From: Timo Kokkonen Date: Sat, 21 Aug 2010 07:24:07 +0000 (+0300) Subject: main.c: Allow scanning multiple processes by name X-Git-Url: http://git.itanic.dy.fi/?p=scan-pagemap;a=commitdiff_plain;h=079a74b05e89f918b3a4348be6163f6ebe0b26b4 main.c: Allow scanning multiple processes by name 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 --- diff --git a/main.c b/main.c index 1cf944d..9f9b5c5 100644 --- 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;