Pids are now stored in a linked list in the parse_opts structure.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
switch (c) {
case 'p':
- opts->pid = atoi(optarg);
+ {
+ struct pidlist *pid = alloc_pidlist();
+
+ if (pid == NULL) {
+ perror("malloc");
+ return;
+ }
+ pid->pid = atoi(optarg);
opts->parse_mask |= PARSE_PID;
+ list_add_tail(&pid->list, &opts->pidlist);
break;
+ }
case 'P':
opts->parse_mask |= PARSE_PROCESS_NAME;
opts->name = optarg;
"Results may be inaccurate\n");
}
- memset(&opts, 0, sizeof(opts));
+ init_parse_opts(&opts);
read_args(argc, argv, &opts);
#define PARSE_DUMP 0x8
#define PARSE_NOADD_TREE 0x10
+struct pidlist {
+ struct list_head list;
+
+ int pid;
+};
+
struct parse_opts {
+ struct list_head pidlist;
+
int parse_mask;
- int pid;
char *name;
int with_threads;
};
+static inline void init_parse_opts(struct parse_opts *p)
+{
+ memset(p, 0, sizeof(*p));
+ INIT_LIST_HEAD(&p->pidlist);
+}
+
+static inline struct pidlist *alloc_pidlist(void)
+{
+ struct pidlist *p = malloc(sizeof(*p));
+
+ if (p == NULL)
+ return p;
+
+ memset(p, 0, sizeof(*p));
+ INIT_LIST_HEAD(&p->list);
+
+ return p;
+}
+
#define is_parse_option(parse_opts, flag) \
(!!((parse_opts)->parse_mask & (flag)))
static int should_scan_process(struct parse_opts *opts, struct process *process)
{
+ struct pidlist *pid;
int match = 0;
char *name;
}
if (is_parse_option(opts, PARSE_PID)) {
- if (opts->pid == process->pid)
- match = 1;
+ list_for_each_entry(pid, &opts->pidlist, list) {
+ if (pid->pid == process->pid) {
+ match = 1;
+ break;
+ }
+ }
}
if (is_parse_option(opts, PARSE_MAP_NAME))
int scan_all_pids(struct pageframe *pf, struct process *process_list,
struct parse_opts *opts)
{
+ struct pidlist *pidlist;
DIR *dir = NULL;
int pid;
int count = 0;
dir = NULL;
}
- if (is_parse_option(opts, PARSE_PID))
- count = read_pageframe_with_threads(opts->pid, pf, process_list,
- opts);
+ if (is_parse_option(opts, PARSE_PID)) {
+ list_for_each_entry(pidlist, &opts->pidlist, list) {
+ count += read_pageframe_with_threads(pidlist->pid, pf,
+ process_list, opts);
+ }
+ }
if ((count == 0) && !(is_parse_option(opts, PARSE_MAP_NAME))) {
printf("Failed to find any matching processes "