From a8db4bae558a7d01128e79c7dc75b0b982b9a392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 24 May 2022 18:50:04 +0200 Subject: [PATCH] libroot: system() should ignore SIGINT, SIGQUIT while waiting https://pubs.opengroup.org/onlinepubs/9699919799/functions/system.html Change-Id: Ic9919e403fb4e6ee4406b0c33789fe8b00b22d1f Reviewed-on: https://review.haiku-os.org/c/haiku/+/5341 Reviewed-by: waddlesplash Tested-by: Commit checker robot --- src/system/libroot/posix/unistd/system.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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;