diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-10-17 13:43:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-10-18 14:49:40 +0200 |
commit | 957f84e950b35e61b25d67f26c4798a25f22eed7 (patch) | |
tree | c7e82f62af97706783f064cee5f1c394e6807a84 | |
parent | process-util: add API for enumerating processes in /proc/ and pinning them vi... (diff) | |
download | systemd-957f84e950b35e61b25d67f26c4798a25f22eed7.tar.xz systemd-957f84e950b35e61b25d67f26c4798a25f22eed7.zip |
test: port tests over to new /proc/ enumeration API
-rw-r--r-- | src/test/test-cgroup-util.c | 36 | ||||
-rw-r--r-- | src/test/test-process-util.c | 13 |
2 files changed, 24 insertions, 25 deletions
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index 57facfe632..51f52d9a4e 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -194,35 +194,33 @@ TEST(proc) { _cleanup_closedir_ DIR *d = NULL; int r; - d = opendir("/proc"); - assert_se(d); + assert_se(proc_dir_open(&d) >= 0); - FOREACH_DIRENT(de, d, break) { + for (;;) { _cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *slice = NULL; - pid_t pid; + _cleanup_(pidref_done) PidRef pid = PIDREF_NULL; uid_t uid = UID_INVALID; - if (!IN_SET(de->d_type, DT_DIR, DT_UNKNOWN)) - continue; + r = proc_dir_read_pidref(d, &pid); + assert_se(r >= 0); - r = parse_pid(de->d_name, &pid); - if (r < 0) - continue; + if (r == 0) + break; - if (pid_is_kernel_thread(pid) != 0) + if (pidref_is_kernel_thread(&pid) != 0) continue; - cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &path); - cg_pid_get_path_shifted(pid, NULL, &path_shifted); - cg_pid_get_owner_uid(pid, &uid); - cg_pid_get_session(pid, &session); - cg_pid_get_unit(pid, &unit); - cg_pid_get_user_unit(pid, &user_unit); - cg_pid_get_machine_name(pid, &machine); - cg_pid_get_slice(pid, &slice); + cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid.pid, &path); + cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted); + cg_pid_get_owner_uid(pid.pid, &uid); + cg_pid_get_session(pid.pid, &session); + cg_pid_get_unit(pid.pid, &unit); + cg_pid_get_user_unit(pid.pid, &user_unit); + cg_pid_get_machine_name(pid.pid, &machine); + cg_pid_get_slice(pid.pid, &slice); printf(PID_FMT"\t%s\t%s\t"UID_FMT"\t%s\t%s\t%s\t%s\t%s\n", - pid, + pid.pid, path, path_shifted, uid, diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 2ff9f1fad5..524bcceb97 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -149,17 +149,18 @@ static void test_pid_get_cmdline_one(pid_t pid) { TEST(pid_get_cmdline) { _cleanup_closedir_ DIR *d = NULL; + int r; - assert_se(d = opendir("/proc")); + assert_se(proc_dir_open(&d) >= 0); - FOREACH_DIRENT(de, d, return) { + for (;;) { pid_t pid; - if (de->d_type != DT_DIR) - continue; + r = proc_dir_read(d, &pid); + assert_se(r >= 0); - if (parse_pid(de->d_name, &pid) < 0) - continue; + if (r == 0) /* EOF */ + break; test_pid_get_cmdline_one(pid); } |