]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
command: fork-bomb: Further improve return code when killed
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 16:43:40 +0000 (16:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 16:43:40 +0000 (16:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/stub/command.c

index 3f07dbd02163aa9c8b1200c8ee455d432fabb11e..0c0fd306852a1130ad960344a94f3db24781421d 100644 (file)
@@ -134,7 +134,6 @@ static int fork_bomb(int argc, char* argv[]) {
        // Catch any errors
        if (pid < 0) {
                fprintf(stderr, "Could not fork(): %m\n");
-               exit(EXIT_FAILURE);
 
        // Parent
        } else if (pid) {
@@ -143,14 +142,24 @@ static int fork_bomb(int argc, char* argv[]) {
                // Wait until the child process went away
                waitpid(pid, &status, 0);
 
+               if (WIFSIGNALED(status)) {
+                       fprintf(stderr, "Child %d was terminated by signal %d\n",
+                               pid, WTERMSIG(status));
+
+                       return 128 + WTERMSIG(status);
+               }
+
                // Pass on the exit code
-               return WEXITSTATUS(status);
+               if (WIFEXITED(status))
+                       return WEXITSTATUS(status);
 
        // Child
        } else {
                // Fork again...
                return fork_bomb(0, NULL);
        }
+
+       return EXIT_FAILURE;
 }
 
 static int lines(int argc, char* argv[]) {