From: Michael Tremer Date: Tue, 9 Aug 2022 16:43:40 +0000 (+0000) Subject: command: fork-bomb: Further improve return code when killed X-Git-Tag: 0.9.28~533 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=688f864a126d17e5f4f72bb95feea030b0a6fd75;p=pakfire.git command: fork-bomb: Further improve return code when killed Signed-off-by: Michael Tremer --- diff --git a/tests/stub/command.c b/tests/stub/command.c index 3f07dbd02..0c0fd3068 100644 --- a/tests/stub/command.c +++ b/tests/stub/command.c @@ -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[]) {