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

@@ -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)