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 <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
4b0d8831c2
commit
a8db4bae55
@@ -8,6 +8,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -28,6 +29,20 @@ system(const char *command)
|
|||||||
if (thread < 0)
|
if (thread < 0)
|
||||||
RETURN_AND_SET_ERRNO_TEST_CANCEL(thread);
|
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);
|
resume_thread(thread);
|
||||||
|
|
||||||
int exitStatus;
|
int exitStatus;
|
||||||
@@ -37,6 +52,11 @@ system(const char *command)
|
|||||||
// waitpid() was interrupted by a signal, retry...
|
// 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)
|
if (result < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user