]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
tests: jail: Send signals to ourselves
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Dec 2022 11:17:32 +0000 (11:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Dec 2022 11:17:32 +0000 (11:17 +0000)
This should not cause the parent process to die.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/jail.c

index 784e89ef18d1402d63a2c9a4de52e5e411d4eab3..cd71f29b547b5d647c901492c59b0b63a83e8b93 100644 (file)
@@ -383,6 +383,42 @@ FAIL:
        return r;
 }
 
+static int test_send_one_signal(const struct test* t,
+               struct pakfire_jail* jail, const char* signal) {
+       const char* argv[] = {
+               "/command", "send-signal", signal, NULL,
+       };
+
+       // Perform the command
+       return pakfire_jail_exec(jail, argv, NULL, NULL, NULL);
+}
+
+static int test_send_signal(const struct test* t) {
+       struct pakfire_jail* jail = NULL;
+       int r = EXIT_FAILURE;
+
+       // Create a new jail
+       ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, 0));
+
+       // Sending SIGTERM to ourselves
+       ASSERT(test_send_one_signal(t, jail, "15") == 0);
+
+       // Sending SIGKILL to ourselves
+       ASSERT(test_send_one_signal(t, jail, "9") == 0);
+
+       // Sending SIGSTOP to ourselves (this should be ignored by the jail)
+       ASSERT(test_send_one_signal(t, jail, "23") == 0);
+
+       // Success
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (jail)
+               pakfire_jail_unref(jail);
+
+       return r;
+}
+
 int main(int argc, const char* argv[]) {
        testsuite_add_test(test_create);
        testsuite_add_test(test_exit_code);
@@ -396,6 +432,7 @@ int main(int argc, const char* argv[]) {
        testsuite_add_test(test_file_ownership);
        testsuite_add_test(test_bind);
        testsuite_add_test(test_communicate);
+       testsuite_add_test(test_send_signal);
 
        return testsuite_run(argc, argv);
 }