test: port tests over to new /proc/ enumeration API

This commit is contained in:
Lennart Poettering
2023-10-18 14:49:40 +02:00
parent eefb7d22ce
commit 957f84e950
2 changed files with 26 additions and 27 deletions
+19 -21
View File
@@ -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))
r = proc_dir_read_pidref(d, &pid);
assert_se(r >= 0);
if (r == 0)
break;
if (pidref_is_kernel_thread(&pid) != 0)
continue;
r = parse_pid(de->d_name, &pid);
if (r < 0)
continue;
if (pid_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,
+7 -6
View File
@@ -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);
}