From: Michael Tremer Date: Thu, 4 Aug 2022 15:54:18 +0000 (+0000) Subject: tests: jail: Send signals to ourselves X-Git-Tag: 0.9.28~584 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e452ed61aa8f677e41dc318078f4e31a000a6ce3;p=pakfire.git tests: jail: Send signals to ourselves Signed-off-by: Michael Tremer --- diff --git a/tests/python/jail.py b/tests/python/jail.py index 8428a0d45..ba1875db9 100755 --- a/tests/python/jail.py +++ b/tests/python/jail.py @@ -123,6 +123,26 @@ class JailTests(unittest.TestCase): """ self.pakfire.execute(["/command", "check-open-file-descriptors"]) + # Signals + + def test_send_signal_DEFAULT(self): + """ + Sends a stupid signal which doesn't do anything + """ + self.pakfire.execute(["/command", "send-signal", "0"]) + + def test_send_signal_KILL(self): + """ + Test the process killing itself + """ + self.pakfire.execute(["/command", "send-signal", "9"]) + + def test_send_signal_TERM(self): + """ + Test the process terminating itself + """ + self.pakfire.execute(["/command", "send-signal", "15"]) + # This is an interactive test which cannot be performed automatically #def test_shell(self): # self.pakfire.execute(["/bin/bash", "-i"]) diff --git a/tests/stub/command.c b/tests/stub/command.c index e09809521..92dece546 100644 --- a/tests/stub/command.c +++ b/tests/stub/command.c @@ -202,6 +202,31 @@ static int print_pid(int argc, char* argv[]) { return 0; } +static int send_signal(int argc, char* argv[]) { + int r; + + if (argc < 1) { + fprintf(stderr, "No signal given\n"); + return EXIT_FAILURE; + } + + // Fetch our own PID + pid_t pid = getpid(); + + // Parse signal from command line + int signum = strtoul(argv[0], NULL, 10); + + printf("Sending signal %d to ourselves (PID %d)\n", signum, pid); + + r = kill(pid, signum); + if (r < 0) { + fprintf(stderr, "Error sending signal: %m\n"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + int main(int argc, char* argv[]) { if (argc < 2) { fprintf(stderr, "No command given\n"); @@ -246,6 +271,10 @@ int main(int argc, char* argv[]) { else if (strcmp(command, "print-pid") == 0) callback = print_pid; + // Send signal + else if (strcmp(command, "send-signal") == 0) + callback = send_signal; + // Exit if no callback has been set if (!callback) { fprintf(stderr, "Unknown command: %s\n", command);