# HG changeset patch # User wenzelm # Date 1455400361 -3600 # Node ID f41884b9c4f1900cad638a1cd4c55e28b2ee5c74 # Parent 9e95a4afb8c3fec2f636dd618bcf62ffd07ccd45 actually wait for forked process and return its status -- this is not meant to be a daemon; diff -r 9e95a4afb8c3 -r f41884b9c4f1 Admin/bash_process/bash_process.c --- a/Admin/bash_process/bash_process.c Sat Feb 13 21:22:02 2016 +0100 +++ b/Admin/bash_process/bash_process.c Sat Feb 13 22:52:41 2016 +0100 @@ -7,9 +7,9 @@ #include #include #include +#include #include - static void fail(const char *msg) { fprintf(stderr, "%s\n", msg); @@ -34,8 +34,24 @@ if (setsid() == -1) { pid_t pid = fork(); + int status; + if (pid == -1) fail("Cannot set session id (failed to fork)"); - else if (pid != 0) exit(0); + else if (pid != 0) { + if (waitpid(pid, &status, 0) == -1) { + fail("Cannot join forked process"); + } + + if (WIFEXITED(status)) { + exit(WEXITSTATUS(status)); + } + else if (WIFSIGNALED(status)) { + exit(128 + WTERMSIG(status)); + } + else { + fail("Unknown status of forked process"); + } + } else if (setsid() == -1) fail("Cannot set session id (after fork)"); }