Skip to content

Commit

Permalink
Block SIGCHLD during system() call (per POSIX)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont authored and Father Chrysostomos committed Dec 31, 2011
1 parent c56bc16 commit b1cf9e9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pp_sys.c
Expand Up @@ -4116,9 +4116,17 @@ PP(pp_system)
Pid_t childpid;
int pp[2];
I32 did_pipes = 0;
#if (defined(HAS_SIGPROCMASK) && !defined(PERL_MICRO))
sigset_t newset, oldset;
#endif

if (PerlProc_pipe(pp) >= 0)
did_pipes = 1;
#if (defined(HAS_SIGPROCMASK) && !defined(PERL_MICRO))
sigemptyset(&newset);
sigaddset(&newset, SIGCHLD);
sigprocmask(SIG_BLOCK, &newset, &oldset);
#endif
while ((childpid = PerlProc_fork()) == -1) {
if (errno != EAGAIN) {
value = -1;
Expand All @@ -4128,6 +4136,9 @@ PP(pp_system)
PerlLIO_close(pp[0]);
PerlLIO_close(pp[1]);
}
#if (defined(HAS_SIGPROCMASK) && !defined(PERL_MICRO))
sigprocmask(SIG_SETMASK, &oldset, NULL);
#endif
RETURN;
}
sleep(5);
Expand All @@ -4146,6 +4157,9 @@ PP(pp_system)
result = wait4pid(childpid, &status, 0);
} while (result == -1 && errno == EINTR);
#ifndef PERL_MICRO
#ifdef HAS_SIGPROCMASK
sigprocmask(SIG_SETMASK, &oldset, NULL);
#endif
(void)rsignal_restore(SIGINT, &ihand);
(void)rsignal_restore(SIGQUIT, &qhand);
#endif
Expand Down Expand Up @@ -4176,6 +4190,9 @@ PP(pp_system)
XPUSHi(STATUS_CURRENT);
RETURN;
}
#if (defined(HAS_SIGPROCMASK) && !defined(PERL_MICRO))
sigprocmask(SIG_SETMASK, &oldset, NULL);
#endif
if (did_pipes) {
PerlLIO_close(pp[0]);
#if defined(HAS_FCNTL) && defined(F_SETFD)
Expand Down

0 comments on commit b1cf9e9

Please sign in to comment.