.compare = compare_pageframe,
};
+static int read_cmdline(int pid, int tid, char *cmdline, size_t len)
+{
+ FILE *file;
+ char path[512];
+ int ret;
+
+ snprintf(path, sizeof(path), "/proc/%d/task/%d/cmdline", pid, tid);
+ file = fopen(path, "rb");
+
+ if (!file)
+ return -1;
+
+ ret = fread(cmdline, 1, len, file);
+ if (ret > 0)
+ cmdline[ret - 1] = 0;
+ fclose(file);
+
+ return ret > 0 ? 0 : -1;
+}
+
static int check_parse_opts(struct parse_opts *opts, struct pageframe *pf,
struct maps *map)
{
struct process *process;
FILE *file;
char path[512];
- int ret;
process = malloc(sizeof(*process));
memset(process, 0, sizeof(*process));
parse_pageframe(file, pageframe, maps, opts);
fclose(file);
- snprintf(path, sizeof(path), "/proc/%d/task/%d/cmdline", pid, tid);
- file = fopen(path, "rb");
-
- if (!file)
+ if (read_cmdline(pid, tid, process->name, sizeof(process->name)))
return;
- ret = fread(process->name, 1, sizeof(process->name), file);
- if (ret > 0)
- process->name[ret - 1] = 0;
- fclose(file);
-
if (maps == NULL)
return;