From: Timo Kokkonen Date: Sat, 3 Jul 2010 20:10:53 +0000 (+0300) Subject: parser: Add support for parsing through all PIDs X-Git-Url: http://git.itanic.dy.fi/?p=scan-pagemap;a=commitdiff_plain;h=a5c2e985a1b17f90164d57728bc5fe8cac0ec556 parser: Add support for parsing through all PIDs This reads the entire /proc directory and parses all pids it can find there. Signed-off-by: Timo Kokkonen --- diff --git a/parse.c b/parse.c index 55d6402..32660e2 100644 --- a/parse.c +++ b/parse.c @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -218,3 +220,50 @@ err_out: return; } + +static int get_next_pid(void) +{ + static DIR *dir = NULL; + struct dirent *dirent; + int error; + + if (!dir) { + dir = opendir("/proc"); + if (!dir) { + error = errno; + printf("Failed to open /proc directory: %s\n", + strerror(error)); + return -1; + } + } + +restart: + dirent = readdir(dir); + if (!dirent) { + if (errno == 0) { + closedir(dir); + dir = NULL; + return 0; + } + error = errno; + printf("Failed to read directory: %s\n", strerror(error)); + return -1; + } + + printf("%s\n", dirent->d_name); + if (dirent->d_name[0] < '0' || dirent->d_name[0] > '9') + goto restart; + + return atoi(dirent->d_name); +} + +void scan_all_pids(struct pageframe *pf) +{ + int pid; + while(1) { + pid = get_next_pid(); + if (pid <= 0) + break; + read_pageframe(pid, pf); + } +} diff --git a/parse.h b/parse.h index dcbe1f2..b3092d2 100644 --- a/parse.h +++ b/parse.h @@ -4,5 +4,6 @@ #include "pagemap.h" void read_pageframe(int pid, struct pageframe *pageframe); +void scan_all_pids(struct pageframe *pf); #endif