Compare commits
2 Commits
fe9827bbeb
...
66365e15a7
Author | SHA1 | Date | |
---|---|---|---|
66365e15a7 | |||
4a5947e10e |
@ -8,6 +8,8 @@
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
|
||||
#define SIG_ERR (__simple_sighandler_t)(-3)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
@ -19,6 +21,9 @@ extern "C"
|
||||
int sigaction(int signo, const struct sigaction* act, struct sigaction* oldact);
|
||||
#pragma GCC pop_options
|
||||
|
||||
/* Change the current thread's signal disposition for a specific signal. */
|
||||
__simple_sighandler_t signal(int signo, __simple_sighandler_t handler);
|
||||
|
||||
/* Send a signal to a specific process. */
|
||||
int kill(pid_t pid, int signo);
|
||||
|
||||
|
@ -13,6 +13,18 @@ extern "C"
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
__simple_sighandler_t signal(int signo, __simple_sighandler_t handler)
|
||||
{
|
||||
struct sigaction act, oldact;
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
|
||||
if (sigaction(signo, &act, &oldact) < 0) return SIG_ERR;
|
||||
|
||||
return oldact.sa_handler;
|
||||
}
|
||||
|
||||
int kill(pid_t pid, int signo)
|
||||
{
|
||||
long rc = syscall(SYS_kill, pid, signo);
|
||||
|
@ -191,9 +191,6 @@ extern "C"
|
||||
return S_ISREG(st.st_mode);
|
||||
}
|
||||
|
||||
// FIXME: During the execution of system(), SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored, in
|
||||
// the process that calls system().
|
||||
|
||||
pid_t child = fork();
|
||||
if (child == 0)
|
||||
{
|
||||
@ -203,9 +200,21 @@ extern "C"
|
||||
|
||||
if (child < 0) return -1;
|
||||
|
||||
sigset_t set, oldset;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
||||
|
||||
auto old_int = signal(SIGINT, SIG_IGN);
|
||||
auto old_quit = signal(SIGQUIT, SIG_IGN);
|
||||
|
||||
int status;
|
||||
waitpid(child, &status, 0);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &oldset, nullptr);
|
||||
signal(SIGINT, old_int);
|
||||
signal(SIGQUIT, old_quit);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user