use pipe2() with O_CLOEXEC instead of pipe() + fcntl() and FD_CLOEXEC

This commit is contained in:
Todd C. Miller
2017-04-20 15:10:57 -06:00
parent 6e75179528
commit c2176c32a7
2 changed files with 2 additions and 4 deletions

View File

@@ -566,7 +566,7 @@ exec_monitor(struct command_details *details, bool foreground, int backchannel)
mon_pgrp = getpgrp(); /* save a copy of our process group */ mon_pgrp = getpgrp(); /* save a copy of our process group */
/* Start command and wait for it to stop or exit */ /* Start command and wait for it to stop or exit */
if (pipe(errpipe) == -1) if (pipe2(errpipe, O_CLOEXEC) == -1)
sudo_fatal(U_("unable to create pipe")); sudo_fatal(U_("unable to create pipe"));
cmnd_pid = sudo_debug_fork(); cmnd_pid = sudo_debug_fork();
if (cmnd_pid == -1) { if (cmnd_pid == -1) {
@@ -579,7 +579,6 @@ exec_monitor(struct command_details *details, bool foreground, int backchannel)
close(signal_pipe[0]); close(signal_pipe[0]);
close(signal_pipe[1]); close(signal_pipe[1]);
close(errpipe[0]); close(errpipe[0]);
(void)fcntl(errpipe[1], F_SETFD, FD_CLOEXEC);
restore_signals(); restore_signals();
/* setup tty and exec command */ /* setup tty and exec command */

View File

@@ -157,7 +157,7 @@ exec_nopty(struct command_details *details, struct command_status *cstat)
/* /*
* We use a pipe to get errno if execve(2) fails in the child. * We use a pipe to get errno if execve(2) fails in the child.
*/ */
if (pipe(errpipe) == -1) if (pipe2(errpipe, O_CLOEXEC) == -1)
sudo_fatal(U_("unable to create pipe")); sudo_fatal(U_("unable to create pipe"));
/* /*
@@ -244,7 +244,6 @@ exec_nopty(struct command_details *details, struct command_status *cstat)
close(errpipe[0]); close(errpipe[0]);
close(signal_pipe[0]); close(signal_pipe[0]);
close(signal_pipe[1]); close(signal_pipe[1]);
(void)fcntl(errpipe[1], F_SETFD, FD_CLOEXEC);
exec_cmnd(details, errpipe[1]); exec_cmnd(details, errpipe[1]);
while (write(errpipe[1], &errno, sizeof(int)) == -1) { while (write(errpipe[1], &errno, sizeof(int)) == -1) {
if (errno != EINTR) if (errno != EINTR)