]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
parser: get_next_pid: Do not store state internally
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Thu, 22 Jul 2010 11:19:45 +0000 (14:19 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Thu, 22 Jul 2010 11:19:45 +0000 (14:19 +0300)
Storing the directory state internally may conflict in case there are
multiple users to the get_next_pid function. The directory state is
now taken as an argument and caller will store it.

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

diff --git a/parse.c b/parse.c
index d5962c86cd91944182e1ca70681a3cc9fe4b6915..c2dc22d978de8ce6ff8f1f57d9bd7e782ecdbbb3 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -341,13 +341,12 @@ static int get_next_tid(int pid, DIR **dir)
        return parse_pid(dir);
 }
 
-static int get_next_pid(void)
+static int get_next_pid(DIR **dir)
 {
-       static DIR *dir = NULL;
        int error;
 
-       if (!dir) {
-               dir = opendir("/proc");
+       if (!*dir) {
+               *dir = opendir("/proc");
                if (!dir) {
                        error = errno;
                        printf("Failed to open /proc directory: %s\n",
@@ -356,7 +355,7 @@ static int get_next_pid(void)
                }
        }
 
-       return parse_pid(&dir);
+       return parse_pid(dir);
 }
 
 static void read_pageframe_with_threads(int pid,
@@ -386,13 +385,14 @@ static void read_pageframe_with_threads(int pid,
 void scan_all_pids(struct pageframe *pf, struct process **process_list,
                struct parse_opts *opts)
 {
+       DIR *dir = NULL;
        int pid;
 
        if (opts->parse_mask & PARSE_PID)
                read_pageframe_with_threads(opts->pid, pf, process_list, opts);
 
        while(1) {
-               pid = get_next_pid();
+               pid = get_next_pid(&dir);
                if (pid <= 0)
                        break;
                read_pageframe_with_threads(pid, pf, process_list, opts);