]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-cgroup-util: Check return values
authorMichal Koutný <mkoutny@suse.com>
Wed, 15 Jan 2025 15:36:28 +0000 (16:36 +0100)
committerMichal Koutný <mkoutny@suse.com>
Wed, 12 Mar 2025 09:31:23 +0000 (10:31 +0100)
The test is supposed to check a battery of cgroup helpers on each
process found but it doesn't literally check anything besides presence
of procfs. (One can visually check printed output only. Introduction in
aff38e74bd ("nspawn: suffix the nspawn cgroups with ".nspawn"").)

Make some assumptions about visible processes and turn the test into
testing that systemd helpers can deal with whatever process they find on
the SUT.

Reported by Coverity and
Fixes CID#1587767

src/test/test-cgroup-util.c

index 3f91aa6a72da8ae33adc5356fe3b84f6efd499dc..6b4c9b5aa78d763db744157fd0cb5c518fb57dbf 100644 (file)
@@ -218,14 +218,20 @@ TEST(proc) {
                 if (pidref_is_kernel_thread(&pid) != 0)
                         continue;
 
-                cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path);
-                cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted);
-                cg_pidref_get_owner_uid(&pid, &uid);
-                cg_pidref_get_session(&pid, &session);
-                cg_pidref_get_unit(&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);
+                ASSERT_OK_ZERO(cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path));
+                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));
+
+                /* 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);
+                r = cg_pidref_get_session(&pid, &session);
+                ASSERT_TRUE(r == 0 || r == -ENXIO);
+                r = cg_pid_get_user_unit(pid.pid, &user_unit);
+                ASSERT_TRUE(r == 0 || r == -ENXIO);
+                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,