diff --git a/src/system/libroot/posix/unistd/system.cpp b/src/system/libroot/posix/unistd/system.cpp index a7102ead63..69bad3edc3 100644 --- a/src/system/libroot/posix/unistd/system.cpp +++ b/src/system/libroot/posix/unistd/system.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -28,6 +29,20 @@ system(const char *command) if (thread < 0) RETURN_AND_SET_ERRNO_TEST_CANCEL(thread); + // block SIGCHLD ... + sigset_t mask, oldMask; + sigemptyset(&mask); + sigaddset(&mask, SIGCHLD); + sigprocmask(SIG_BLOCK, &mask, &oldMask); + + // and ignore SIGINT and SIGQUIT while waiting for completion + struct sigaction intSave, quitSave, sa; + memset(&sa, 0, sizeof(sa)); + sigemptyset(&sa.sa_mask); + sa.sa_handler = SIG_IGN; + sigaction(SIGINT, &sa, &intSave); + sigaction(SIGQUIT, &sa, &quitSave); + resume_thread(thread); int exitStatus; @@ -37,6 +52,11 @@ system(const char *command) // waitpid() was interrupted by a signal, retry... } + // unblock and reset signal handlers + sigprocmask(SIG_SETMASK, &oldMask, NULL); + sigaction(SIGINT, &intSave, NULL); + sigaction(SIGQUIT, &quitSave, NULL); + if (result < 0) return -1;