]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
main.c: Allow scanning multiple processes by name
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 21 Aug 2010 07:24:07 +0000 (10:24 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 21 Aug 2010 07:24:07 +0000 (10:24 +0300)
Now that we have code in place for scanning multiple pid numbers, we
can also convert all process names to pids. That way, it becomes also
possible to add all process names user has given as an argument.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index 1cf944d9a4d5ed6c5056bc6c62127a472c256b7e..9f9b5c54c7e1cbf90eeb56dc9ab982028718936c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,6 +8,7 @@
 
 #include "parse.h"
 #include "analyze.h"
+#include "pidlib.h"
 
 void print_help_and_die(char *name)
 {
@@ -25,6 +26,21 @@ void print_help_and_die(char *name)
 
 #define OPT_WITH_THREADS       0x101
 
+static void get_all_pids_by_name(struct parse_opts *opts, char *name)
+{
+       struct pidlist *pidlist;
+       DIR *dir = NULL;
+       int pid;
+
+       while ((pid = get_next_pid_by_name(&dir, name))) {
+               pidlist = alloc_pidlist();
+               if (pidlist == NULL)
+                       return;
+               pidlist->pid = pid;
+               list_add_tail(&pidlist->list, &opts->pidlist);
+       }
+}
+
 void read_args(int argc, char *argv[], struct parse_opts *opts)
 {
        int optind = 0, c;
@@ -61,8 +77,8 @@ void read_args(int argc, char *argv[], struct parse_opts *opts)
                        break;
                }
                case 'P':
-                       opts->parse_mask |= PARSE_PROCESS_NAME;
-                       opts->name = optarg;
+                       get_all_pids_by_name(opts, optarg);
+                       opts->parse_mask |= PARSE_PID;
                        break;
                case 'm':
                        opts->parse_mask |= PARSE_MAP_NAME;