]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
tests: jail: Add test that launches a process into a cgroup
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 12:33:29 +0000 (12:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 12:33:29 +0000 (12:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/jail.c

index 757cd9e890453195639b855047e8de1fefb178b8..3866b8b30bbbad81aec87a0f410cc5100eb970fd 100644 (file)
@@ -18,6 +18,7 @@
 #                                                                             #
 #############################################################################*/
 
+#include <pakfire/cgroup.h>
 #include <pakfire/jail.h>
 
 #include "../testsuite.h"
@@ -98,10 +99,41 @@ FAIL:
        return EXIT_FAILURE;
 }
 
+static int test_launch_into_cgroup(const struct test* t) {
+       struct pakfire_cgroup* cgroup = NULL;
+       struct pakfire_jail* jail = NULL;
+       int r = EXIT_FAILURE;
+
+       // Create a new cgroup
+       ASSERT_SUCCESS(pakfire_cgroup_open(&cgroup, t->pakfire, "pakfire-test", 0));
+
+       // Create a new jail
+       ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, 0));
+
+       // Connect jail to the cgroup
+       ASSERT_SUCCESS(pakfire_jail_set_cgroup(jail, cgroup));
+
+       // Run command
+       ASSERT(pakfire_jail_exec(jail, cmd, NULL) == 0);
+
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (cgroup) {
+               pakfire_cgroup_destroy(cgroup);
+               pakfire_cgroup_unref(cgroup);
+       }
+       if (jail)
+               pakfire_jail_unref(jail);
+
+       return r;
+}
+
 int main(int argc, char** argv) {
        testsuite_add_test(test_create);
        testsuite_add_test(test_env);
        testsuite_add_test(test_exec);
+       testsuite_add_test(test_launch_into_cgroup);
 
        return testsuite_run();
 }