diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-04-01 16:46:01 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-05 13:59:23 +0200 |
commit | 510c7a953ea5e12d8f2e4ab243dec546eb0325a1 (patch) | |
tree | abffefccc87ddd8f361ffee10c53403731efd0f8 /src/test/test-process-util.c | |
parent | 99009ed0f490b89fa14ca323a9ffb9b963980822 (diff) | |
download | systemd-510c7a953ea5e12d8f2e4ab243dec546eb0325a1.tar.gz |
test-process-util: add test that prints all cmdlines
Diffstat (limited to 'src/test/test-process-util.c')
-rw-r--r-- | src/test/test-process-util.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index f79df46d29..ca21eadaba 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -15,6 +15,8 @@ #include "alloc-util.h" #include "architecture.h" #include "errno-util.h" +#include "errno-list.h" +#include "dirent-util.h" #include "fd-util.h" #include "log.h" #include "macro.h" @@ -90,6 +92,52 @@ static void test_get_process_comm(pid_t pid) { log_info("PID"PID_FMT" $PATH: '%s'", pid, strna(i)); } +static void test_get_process_cmdline_one(pid_t pid) { + _cleanup_free_ char *c = NULL, *d = NULL, *e = NULL, *f = NULL, *g = NULL, *h = NULL; + int r; + + r = get_process_cmdline(pid, SIZE_MAX, 0, &c); + log_info("PID "PID_FMT": %s", pid, r >= 0 ? c : errno_to_name(r)); + + r = get_process_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_COMM_FALLBACK, &d); + log_info(" %s", r >= 0 ? d : errno_to_name(r)); + + r = get_process_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE, &e); + log_info(" %s", r >= 0 ? e : errno_to_name(r)); + + r = get_process_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE | PROCESS_CMDLINE_COMM_FALLBACK, &f); + log_info(" %s", r >= 0 ? f : errno_to_name(r)); + + r = get_process_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX, &g); + log_info(" %s", r >= 0 ? g : errno_to_name(r)); + + r = get_process_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX | PROCESS_CMDLINE_COMM_FALLBACK, &h); + log_info(" %s", r >= 0 ? h : errno_to_name(r)); +} + +static void test_get_process_cmdline(void) { + _cleanup_closedir_ DIR *d = NULL; + struct dirent *de; + + log_info("/* %s */", __func__); + + assert_se(d = opendir("/proc")); + + FOREACH_DIRENT(de, d, return) { + pid_t pid; + + dirent_ensure_type(d, de); + + if (de->d_type != DT_DIR) + continue; + + if (parse_pid(de->d_name, &pid) < 0) + continue; + + test_get_process_cmdline_one(pid); + } +} + static void test_get_process_comm_escape_one(const char *input, const char *output) { _cleanup_free_ char *n = NULL; @@ -808,6 +856,7 @@ int main(int argc, char *argv[]) { } test_get_process_comm_escape(); + test_get_process_cmdline(); test_pid_is_unwaited(); test_pid_is_alive(); test_personality(); |