]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-cgroup: cleanup test cgroup
authorLuca Boccassi <luca.boccassi@gmail.com>
Tue, 12 Aug 2025 22:59:15 +0000 (23:59 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Sep 2025 10:10:48 +0000 (12:10 +0200)
One test cgroup gets left behind by the test, as it moves itself
into it. Move itself and back to the original cgroup at the end
and clean up.

This fixes a failure when running the test first as root, and then
as unprivileged (initial cleanup fails as the leftover test cgroup
is owned by root).

(cherry picked from commit 998bb9600e3e3d5f2db93508a69657e197e7f5b7)

src/test/test-cgroup.c

index 39ef07b9b0031612e51ead66284bf2ca496a0142..aa628ac658feaa7a731731ea86c5160ec06a658d 100644 (file)
@@ -60,7 +60,7 @@ TEST(cg_create) {
 
         log_info("Paths for test:\n%s\n%s", test_a, test_b);
 
-        /* Possibly clean up left-overs from aboted previous runs */
+        /* Possibly clean up left-overs from aborted previous runs */
         (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_a, /* delete_root= */ true);
         (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, /* delete_root= */ true);
 
@@ -121,6 +121,9 @@ TEST(cg_create) {
         ASSERT_OK_ZERO(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL));
 
         ASSERT_OK(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, true));
+
+        ASSERT_OK_ZERO(cg_attach(SYSTEMD_CGROUP_CONTROLLER, here, 0));
+        ASSERT_OK(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, true));
 }
 
 TEST(id) {