]> git.ipfire.org Git - pakfire.git/commitdiff
cgroups: Bring back convenience function to create a child group
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 14 Dec 2024 13:39:42 +0000 (13:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 14 Dec 2024 13:39:42 +0000 (13:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/cgroup.c
tests/libpakfire/cgroup.c

index dbf769f4540f3f05e2e33a6c2283feff0b81eb35..2581426bc6122e5735f9c272805857324ec0c637 100644 (file)
@@ -498,6 +498,11 @@ static int pakfire_cgroup_killall(struct pakfire_cgroup* cgroup) {
        return pakfire_cgroup_write(cgroup, "cgroup.kill", "1");
 }
 
+int pakfire_cgroup_child(struct pakfire_cgroup** child,
+               struct pakfire_cgroup* cgroup, const char* path, int flags) {
+       return pakfire_cgroup_open(child, cgroup->ctx, cgroup, path, flags);
+}
+
 /*
        Immediately destroys this cgroup
 */
index 549f899901a94e43c0539361117dfd26686fc56d..0970560b2c731634fa378079796b3aac9ddf921d 100644 (file)
@@ -45,6 +45,33 @@ FAIL:
        return r;
 }
 
+static int test_child(const struct test* t) {
+       struct pakfire_cgroup* cgroup = NULL;
+       struct pakfire_cgroup* child = NULL;
+       int r = EXIT_FAILURE;
+
+       // Open a new cgroup
+       ASSERT_SUCCESS(pakfire_cgroup_create(&cgroup, t->ctx, NULL, "pakfire-test", 0));
+
+       // Create a child
+       ASSERT_SUCCESS(pakfire_cgroup_child(&child, cgroup, "child-group", 0));
+
+       // Destroy the cgroups again
+       ASSERT_SUCCESS(pakfire_cgroup_destroy(child));
+       ASSERT_SUCCESS(pakfire_cgroup_destroy(cgroup));
+
+       // Success
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (child)
+               pakfire_cgroup_unref(child);
+       if (cgroup)
+               pakfire_cgroup_unref(cgroup);
+
+       return r;
+}
+
 static int test_stats(const struct test* t) {
        struct pakfire_cgroup* cgroup = NULL;
        struct pakfire_jail* jail = NULL;
@@ -95,6 +122,7 @@ FAIL:
 
 int main(int argc, const char* argv[]) {
        testsuite_add_test(test_create_and_destroy, 0);
+       testsuite_add_test(test_child, 0);
        testsuite_add_test(test_stats, TEST_WANTS_PAKFIRE);
 
        return testsuite_run(argc, argv);