From: Todd C. Miller Date: Thu, 20 Apr 2017 21:10:57 +0000 (-0600) Subject: use pipe2() with O_CLOEXEC instead of pipe() + fcntl() and FD_CLOEXEC X-Git-Tag: SUDO_1_8_20^2~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2176c32a723db9dfce96c607459490ca5c5dbaa;p=sudo use pipe2() with O_CLOEXEC instead of pipe() + fcntl() and FD_CLOEXEC --- diff --git a/src/exec_monitor.c b/src/exec_monitor.c index ace1073a2..b006d767f 100644 --- a/src/exec_monitor.c +++ b/src/exec_monitor.c @@ -566,7 +566,7 @@ exec_monitor(struct command_details *details, bool foreground, int backchannel) mon_pgrp = getpgrp(); /* save a copy of our process group */ /* 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")); cmnd_pid = sudo_debug_fork(); 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[1]); close(errpipe[0]); - (void)fcntl(errpipe[1], F_SETFD, FD_CLOEXEC); restore_signals(); /* setup tty and exec command */ diff --git a/src/exec_nopty.c b/src/exec_nopty.c index 3380d1eef..b88d4a57d 100644 --- a/src/exec_nopty.c +++ b/src/exec_nopty.c @@ -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. */ - if (pipe(errpipe) == -1) + if (pipe2(errpipe, O_CLOEXEC) == -1) 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(signal_pipe[0]); close(signal_pipe[1]); - (void)fcntl(errpipe[1], F_SETFD, FD_CLOEXEC); exec_cmnd(details, errpipe[1]); while (write(errpipe[1], &errno, sizeof(int)) == -1) { if (errno != EINTR)