#ifdef TEST_PROGRAM_PROCFS
-static int test_tasks(int argc, char *argv[])
+static int test_tasks(int argc, char *argv[], const char *prefix)
{
DIR *sub = NULL;
struct path_cxt *pc;
pid = strtol(argv[1], (char **) NULL, 10);
printf("PID=%d, TIDs:", pid);
- pc = ul_new_procfs_path(pid, NULL);
+ pc = ul_new_procfs_path(pid, prefix);
if (!pc)
err(EXIT_FAILURE, "alloc procfs handler failed");
return EXIT_SUCCESS;
}
-static int test_fds(int argc, char *argv[])
+static int test_fds(int argc, char *argv[], const char *prefix)
{
DIR *sub = NULL;
struct path_cxt *pc;
pid = strtol(argv[1], (char **) NULL, 10);
printf("PID=%d, FDs:", pid);
- pc = ul_new_procfs_path(pid, NULL);
+ pc = ul_new_procfs_path(pid, prefix);
if (!pc)
err(EXIT_FAILURE, "alloc procfs handler failed");
return EXIT_SUCCESS;
}
-static int test_one_process(int argc, char *argv[])
+static int test_one_process(int argc, char *argv[], const char *prefix)
{
pid_t pid;
struct path_cxt *pc;
return EXIT_FAILURE;
pid = strtol(argv[1], (char **) NULL, 10);
- pc = ul_new_procfs_path(pid, NULL);
+ pc = ul_new_procfs_path(pid, prefix);
if (!pc)
err(EXIT_FAILURE, "cannot alloc procfs handler");
return is ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static int test_process_stat_nth(int argc, char *argv[])
+static int test_process_stat_nth(int argc, char *argv[], const char *prefix)
{
pid_t pid;
struct path_cxt *pc;
pid = strtol(argv[1], (char **) NULL, 10);
n = strtol(argv[2], (char **) NULL, 10);
- pc = ul_new_procfs_path(pid, NULL);
+ pc = ul_new_procfs_path(pid, prefix);
if (!pc)
err(EXIT_FAILURE, "cannot alloc procfs handler");
int main(int argc, char *argv[])
{
+ const char *prefix = NULL;
+
+ if (argc > 2 && strcmp(argv[1], "--prefix") == 0) {
+ prefix = argv[2];
+ argc -= 2;
+ argv += 2;
+ }
+
if (argc < 2) {
- fprintf(stderr, "usage: %1$s --tasks <pid>\n"
- " %1$s --fds <pid>\n"
+ fprintf(stderr, "usage: %1$s [--prefix <prefix>] --tasks <pid>\n"
+ " %1$s [--prefix <prefix>] --fds <pid>\n"
" %1$s --is-procfs [<dir>]\n"
" %1$s --processes [--name <name>] [--uid <uid>]\n"
- " %1$s --one <pid>\n"
- " %1$s --stat-nth <pid> <n>\n",
+ " %1$s [--prefix <prefix>] --one <pid>\n"
+ " %1$s [--prefix <prefix>] --stat-nth <pid> <n>\n",
program_invocation_short_name);
return EXIT_FAILURE;
}
if (strcmp(argv[1], "--tasks") == 0)
- return test_tasks(argc - 1, argv + 1);
+ return test_tasks(argc - 1, argv + 1, prefix);
if (strcmp(argv[1], "--fds") == 0)
- return test_fds(argc - 1, argv + 1);
+ return test_fds(argc - 1, argv + 1, prefix);
if (strcmp(argv[1], "--processes") == 0)
return test_processes(argc - 1, argv + 1);
if (strcmp(argv[1], "--is-procfs") == 0)
return test_isprocfs(argc - 1, argv + 1);
if (strcmp(argv[1], "--one") == 0)
- return test_one_process(argc - 1, argv + 1);
+ return test_one_process(argc - 1, argv + 1, prefix);
if (strcmp(argv[1], "--stat-nth") == 0)
- return test_process_stat_nth(argc - 1, argv + 1);
+ return test_process_stat_nth(argc - 1, argv + 1, prefix);
return EXIT_FAILURE;
}