]> git.ipfire.org Git - pakfire.git/commitdiff
tests: jail: Send signals to ourselves
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Aug 2022 15:54:18 +0000 (15:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Aug 2022 15:54:18 +0000 (15:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/python/jail.py
tests/stub/command.c

index 8428a0d453636f716a3f604267d4c4714640ebb5..ba1875db9bfc5ff0018dbcd661537913a35fc32a 100755 (executable)
@@ -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"])
index e0980952130152fdc1ef2d2298002e1284261acd..92dece5469675a20ed040d87f8ff60e123aff792 100644 (file)
@@ -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);