]> git.itanic.dy.fi Git - scan-pagemap/blobdiff - parse.c
parser: Remove unaccessible pids from the pidlist
[scan-pagemap] / parse.c
diff --git a/parse.c b/parse.c
index a7b73cd2ab10e99b9b4155e83ea694dd4e278e7e..827264b8fb315e5a5a631a72759b517be9895f8c 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -245,6 +245,7 @@ static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
 {
        struct maps *maps;
        struct process *process;
+       struct pidlist *pidl, *n;
        FILE *file;
        char path[512];
 
@@ -296,6 +297,17 @@ static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
 free:
        free(process);
 
+       /*
+        * Remove the pid from the list. It is no longer an
+        * interesting pid, since we can't access its data
+        */
+       list_for_each_entry_safe(pidl, n, &opts->pidlist, list) {
+               if (pidl->pid == pid) {
+                       list_del(&pidl->list);
+                       break;
+               }
+       }
+
        return 0;
 }
 
@@ -330,13 +342,13 @@ static int read_pageframe_with_threads(int pid,
 int scan_all_pids(struct pageframe *pf, struct process *process_list,
                struct parse_opts *opts)
 {
-       struct pidlist *pidlist;
+       struct pidlist *pidlist, *n;
        DIR *dir = NULL;
        int pid;
        int count = 0;
 
        if (is_parse_option(opts, PARSE_PID)) {
-               list_for_each_entry(pidlist, &opts->pidlist, list) {
+               list_for_each_entry_safe(pidlist, n, &opts->pidlist, list) {
                        count += read_pageframe_with_threads(pidlist->pid, pf,
                                                        process_list, opts);
                }