From 61e824172c90540130ec29ab0a80bd80ea454c66 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Thu, 22 Jul 2010 14:19:45 +0300 Subject: [PATCH] parser: get_next_pid: Do not store state internally 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 --- parse.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/parse.c b/parse.c index d5962c8..c2dc22d 100644 --- 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); -- 2.45.0