process.c (disable_child_handler_fork_child): simplify
signal(2) is portable for SIG_DFL and SIG_IGN, so we do not need the extra code for sigaction(2). Also, execve will reset all signal handlers to default anyways, so there is little sense in preserving old signal handler besides SIG_IGN. Hopefully this makes the code easier-to-understand and maintain. * process.c (disable_child_handler_fork_child): simplify [ruby-core:75781] [Misc #12439] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
213e7a1c53
commit
80a0c0f808
@ -1,3 +1,8 @@
|
|||||||
|
Sun Jul 3 06:04:09 2016 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
|
* process.c (disable_child_handler_fork_child): simplify
|
||||||
|
[ruby-core:75781] [Misc #12439]
|
||||||
|
|
||||||
Sun Jul 3 05:25:46 2016 Eric Wong <e@80x24.org>
|
Sun Jul 3 05:25:46 2016 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
* tool/asm_parse.rb: add description
|
* tool/asm_parse.rb: add description
|
||||||
|
61
process.c
61
process.c
@ -3497,44 +3497,10 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char
|
|||||||
{
|
{
|
||||||
int sig;
|
int sig;
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef POSIX_SIGNAL
|
|
||||||
struct sigaction act, oact;
|
|
||||||
|
|
||||||
act.sa_handler = SIG_DFL;
|
|
||||||
act.sa_flags = 0;
|
|
||||||
ret = sigemptyset(&act.sa_mask); /* async-signal-safe */
|
|
||||||
if (ret == -1) {
|
|
||||||
ERRMSG("sigemptyset");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
sig_t handler;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (sig = 1; sig < NSIG; sig++) {
|
for (sig = 1; sig < NSIG; sig++) {
|
||||||
int reset = 0;
|
sig_t handler = signal(sig, SIG_DFL);
|
||||||
#ifdef SIGPIPE
|
|
||||||
if (sig == SIGPIPE) {
|
|
||||||
reset = 1;
|
|
||||||
#ifndef POSIX_SIGNAL
|
|
||||||
handler = SIG_DFL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (!reset) {
|
|
||||||
#ifdef POSIX_SIGNAL
|
|
||||||
ret = sigaction(sig, NULL, &oact); /* async-signal-safe */
|
|
||||||
if (ret == -1 && errno == EINVAL) {
|
|
||||||
continue; /* Ignore invalid signal number. */
|
|
||||||
}
|
|
||||||
if (ret == -1) {
|
|
||||||
ERRMSG("sigaction to obtain old action");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
reset = (oact.sa_flags & SA_SIGINFO) ||
|
|
||||||
(oact.sa_handler != SIG_IGN && oact.sa_handler != SIG_DFL);
|
|
||||||
#else
|
|
||||||
handler = signal(sig, SIG_DFL);
|
|
||||||
if (handler == SIG_ERR && errno == EINVAL) {
|
if (handler == SIG_ERR && errno == EINVAL) {
|
||||||
continue; /* Ignore invalid signal number */
|
continue; /* Ignore invalid signal number */
|
||||||
}
|
}
|
||||||
@ -3542,24 +3508,15 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char
|
|||||||
ERRMSG("signal to obtain old action");
|
ERRMSG("signal to obtain old action");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
reset = (handler != SIG_IGN && handler != SIG_DFL);
|
#ifdef SIGPIPE
|
||||||
#endif
|
if (sig == SIGPIPE) {
|
||||||
}
|
continue;
|
||||||
if (reset) {
|
|
||||||
#ifdef POSIX_SIGNAL
|
|
||||||
ret = sigaction(sig, &act, NULL); /* async-signal-safe */
|
|
||||||
if (ret == -1) {
|
|
||||||
ERRMSG("sigaction to set default action");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
handler = signal(sig, handler);
|
|
||||||
if (handler == SIG_ERR) {
|
|
||||||
ERRMSG("signal to set default action");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
/* it will be reset to SIG_DFL at execve time, instead */
|
||||||
|
if (handler == SIG_IGN) {
|
||||||
|
signal(sig, SIG_IGN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sigprocmask(SIG_SETMASK, &old->sigmask, NULL); /* async-signal-safe */
|
ret = sigprocmask(SIG_SETMASK, &old->sigmask, NULL); /* async-signal-safe */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user