From: Yu Watanabe Date: Sat, 15 Mar 2025 01:46:36 +0000 (+0900) Subject: test-cgroup-util: allow ESRCH in cg_pidref_get_path() and friends X-Git-Tag: v258-rc1~1075^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e92d699dde746355bba893b2375b7937a52d9e05;p=thirdparty%2Fsystemd.git test-cgroup-util: allow ESRCH in cg_pidref_get_path() and friends As the process may be already dead. Follow-ups for ca82f0cbe2db096bc7ff81280b5683ea1beae534. --- diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index cdf2ea83d7e..18bc998a39d 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -216,44 +216,57 @@ TEST(proc, .sd_booted = true) { _cleanup_(pidref_done) PidRef pid = PIDREF_NULL; uid_t uid = UID_INVALID; - r = proc_dir_read_pidref(d, &pid); - assert_se(r >= 0); - + ASSERT_OK(r = proc_dir_read_pidref(d, &pid)); if (r == 0) break; if (pidref_is_kernel_thread(&pid) != 0) continue; - ASSERT_OK_ZERO(cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path)); + r = cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path); + if (r == -ESRCH) + continue; + ASSERT_OK(r); + /* Test may run in a container with supervising/monitor processes that don't belong to our * cgroup tree (slices/leaves) */ if (hidden_cgroup(path)) continue; - ASSERT_OK_ZERO(cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted)); - ASSERT_OK_ZERO(cg_pidref_get_unit(&pid, &unit)); - ASSERT_OK_ZERO(cg_pid_get_slice(pid.pid, &slice)); + + r = cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted); + if (r != -ESRCH) + ASSERT_OK(r); + r = cg_pidref_get_unit(&pid, &unit); + if (r != -ESRCH) + ASSERT_OK(r); + r = cg_pid_get_slice(pid.pid, &slice); + if (r != -ESRCH) + ASSERT_OK(r); /* Not all processes belong to a specific user or a machine */ r = cg_pidref_get_owner_uid(&pid, &uid); - ASSERT_TRUE(r == 0 || r == -ENXIO); + if (!IN_SET(r, -ESRCH, -ENXIO)) + ASSERT_OK(r); r = cg_pidref_get_session(&pid, &session); - ASSERT_TRUE(r == 0 || r == -ENXIO); + if (!IN_SET(r, -ESRCH, -ENXIO)) + ASSERT_OK(r); r = cg_pid_get_user_unit(pid.pid, &user_unit); - ASSERT_TRUE(r == 0 || r == -ENXIO); + if (!IN_SET(r, -ESRCH, -ENXIO)) + ASSERT_OK(r); r = cg_pid_get_machine_name(pid.pid, &machine); - ASSERT_TRUE(r == 0 || r == -ENOENT); - - printf(PID_FMT"\t%s\t%s\t"UID_FMT"\t%s\t%s\t%s\t%s\t%s\n", - pid.pid, - path, - path_shifted, - uid, - session, - unit, - user_unit, - machine, - slice); + if (!IN_SET(r, -ESRCH, -ENOENT)) + ASSERT_OK(r); + + log_debug(PID_FMT": %s, %s, "UID_FMT", %s, %s, %s, %s, %s", + pid.pid, + path, + strna(path_shifted), + uid, + strna(session), + strna(unit), + strna(user_unit), + strna(machine), + strna(slice)); } }