Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
return atoi(dirent->d_name);
}
return atoi(dirent->d_name);
}
-static int get_next_tid(int pid, DIR **dir)
+static int opendir_check(DIR **dir, const char *path)
- if (*dir == NULL) {
- char path[64];
-
- snprintf(path, sizeof(path), "/proc/%d/task/", pid);
- *dir = opendir(path);
- if (!*dir) {
+ if (!*dir) {
+ *dir = opendir("/proc");
+ if (!dir) {
- printf("Failed to open %s directory: %s\n",
- path,
+ fprintf(stderr, "Failed to open /proc directory: %s\n",
strerror(error));
return -1;
}
}
strerror(error));
return -1;
}
}
-static int get_next_pid(DIR **dir)
+static int get_next_tid(int pid, DIR **dir)
+ if (*dir == NULL) {
+ char path[64];
- if (!*dir) {
- *dir = opendir("/proc");
- if (!dir) {
- error = errno;
- printf("Failed to open /proc directory: %s\n",
- strerror(error));
+ snprintf(path, sizeof(path), "/proc/%d/task/", pid);
+ if (opendir_check(dir, path))
}
return parse_pid(dir);
}
}
return parse_pid(dir);
}
+static int get_next_pid(DIR **dir)
+{
+ if (opendir_check(dir, "/proc"))
+ return -1;
+
+ return parse_pid(dir);
+}
+
static void read_pageframe_with_threads(int pid,
struct pageframe *pageframe,
struct process **process_list,
static void read_pageframe_with_threads(int pid,
struct pageframe *pageframe,
struct process **process_list,