Skip to content

Commit 8781032

Browse files
deshaw-bawangadmillert
authored andcommitted
[race] : Move the installation of the SIGCHLD handler before fork
1 parent 543e46a commit 8781032

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

src/exec_monitor.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,13 @@ exec_monitor(struct command_details *details, sigset_t *oset,
616616
selinux_audit_role_change();
617617
}
618618
#endif
619+
/*
620+
* Create new event base and register read events for the
621+
* signal pipe, error pipe, and backchannel.
622+
*/
623+
init_exec_events_monitor(&mc, errsock[0]);
624+
/* Restore signal mask now that signal handlers are setup. */
625+
sigprocmask(SIG_SETMASK, oset, NULL);
619626

620627
mc.cmnd_pid = sudo_debug_fork();
621628
switch (mc.cmnd_pid) {
@@ -654,15 +661,6 @@ exec_monitor(struct command_details *details, sigset_t *oset,
654661
cstat.val = mc.cmnd_pid;
655662
send_status(backchannel, &cstat);
656663

657-
/*
658-
* Create new event base and register read events for the
659-
* signal pipe, error pipe, and backchannel.
660-
*/
661-
init_exec_events_monitor(&mc, errsock[0]);
662-
663-
/* Restore signal mask now that signal handlers are setup. */
664-
sigprocmask(SIG_SETMASK, oset, NULL);
665-
666664
/* If any of stdin/stdout/stderr are pipes, close them in parent. */
667665
if (io_fds[SFD_STDIN] != io_fds[SFD_FOLLOWER])
668666
close(io_fds[SFD_STDIN]);

src/exec_nopty.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ exec_nopty(struct command_details *details,
606606
}
607607
#endif
608608

609+
/* Allocate and set signal events and the error pipe event.*/
610+
init_exec_events(&ec, evbase, errpipe[0]);
611+
/* Restore signal mask now that signal handlers are setup. */
612+
sigprocmask(SIG_SETMASK, &oset, NULL);
609613
ec.cmnd_pid = sudo_debug_fork();
610614
switch (ec.cmnd_pid) {
611615
case -1:
@@ -667,9 +671,6 @@ exec_nopty(struct command_details *details,
667671
if (ISSET(details->flags, CD_SET_TIMEOUT))
668672
alarm(details->timeout);
669673

670-
/* Allocate and set signal events and the error pipe event. */
671-
init_exec_events(&ec, evbase, errpipe[0]);
672-
673674
if (ISSET(details->flags, CD_INTERCEPT|CD_LOG_SUBCMDS)) {
674675
int rc = 1;
675676

@@ -692,9 +693,6 @@ exec_nopty(struct command_details *details,
692693
/* Enable any I/O log events. */
693694
add_io_events(&ec);
694695

695-
/* Restore signal mask now that signal handlers are setup. */
696-
sigprocmask(SIG_SETMASK, &oset, NULL);
697-
698696
/*
699697
* Non-pty event loop.
700698
* Wait for command to exit, handles signals and the error pipe.

src/exec_pty.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,10 @@ exec_pty(struct command_details *details,
13351335
debug_return_bool(true);
13361336
}
13371337

1338+
/* Allocate and set signal events and the backchannel event. */
1339+
init_exec_events(ec, evbase, sv[0]);
1340+
/* Restore signal mask now that signal handlers are setup. */
1341+
sigprocmask(SIG_SETMASK, &oset, NULL);
13381342
ec->monitor_pid = sudo_debug_fork();
13391343
switch (ec->monitor_pid) {
13401344
case -1:
@@ -1408,9 +1412,6 @@ exec_pty(struct command_details *details,
14081412
if (ISSET(details->flags, CD_SET_TIMEOUT))
14091413
alarm(details->timeout);
14101414

1411-
/* Allocate and set signal events and the backchannel event. */
1412-
init_exec_events(ec, evbase, sv[0]);
1413-
14141415
/* Create event and closure for intercept mode. */
14151416
if (ISSET(details->flags, CD_INTERCEPT|CD_LOG_SUBCMDS)) {
14161417
ec->intercept = intercept_setup(intercept_sv[0], ec->evbase, details);
@@ -1422,9 +1423,6 @@ exec_pty(struct command_details *details,
14221423
cstat->type = CMD_INVALID;
14231424
cstat->val = 0;
14241425

1425-
/* Restore signal mask now that signal handlers are setup. */
1426-
sigprocmask(SIG_SETMASK, &oset, NULL);
1427-
14281426
/*
14291427
* I/O logging must be in the C locale for floating point numbers
14301428
* to be logged consistently.

0 commit comments

Comments
 (0)