From 35e4bd3e9f6e870665ce7198c96a04e9e9389a52 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 13 Mar 2017 12:11:52 -0600 Subject: [PATCH] Replace pipe_nonblock() with pipe2() --- src/exec.c | 29 ----------------------------- src/exec_monitor.c | 2 +- src/signal.c | 3 ++- src/sudo.h | 1 - 4 files changed, 3 insertions(+), 32 deletions(-) diff --git a/src/exec.c b/src/exec.c index 3bc023158..577a56ac5 100644 --- a/src/exec.c +++ b/src/exec.c @@ -256,35 +256,6 @@ sudo_execute(struct command_details *details, struct command_status *cstat) debug_return_int(cstat->type == CMD_ERRNO ? -1 : 0); } -/* - * Open a pipe and make both ends non-blocking. - * Returns 0 on success and -1 on error. - */ -int -pipe_nonblock(int fds[2]) -{ - int flags, ret; - debug_decl(pipe_nonblock, SUDO_DEBUG_EXEC) - - ret = pipe(fds); - if (ret != -1) { - flags = fcntl(fds[0], F_GETFL, 0); - if (flags != -1 && !ISSET(flags, O_NONBLOCK)) - ret = fcntl(fds[0], F_SETFL, flags | O_NONBLOCK); - if (ret != -1) { - flags = fcntl(fds[1], F_GETFL, 0); - if (flags != -1 && !ISSET(flags, O_NONBLOCK)) - ret = fcntl(fds[1], F_SETFL, flags | O_NONBLOCK); - } - if (ret == -1) { - close(fds[0]); - close(fds[1]); - } - } - - debug_return_int(ret); -} - /* * Kill command with increasing urgency. */ diff --git a/src/exec_monitor.c b/src/exec_monitor.c index 5650c562c..ace1073a2 100644 --- a/src/exec_monitor.c +++ b/src/exec_monitor.c @@ -492,7 +492,7 @@ exec_monitor(struct command_details *details, bool foreground, int backchannel) * We use a pipe to atomically handle signal notification within * the event loop. */ - if (pipe_nonblock(signal_pipe) != 0) + if (pipe2(signal_pipe, O_NONBLOCK) != 0) sudo_fatal(U_("unable to create pipe")); /* Reset SIGWINCH and SIGALRM. */ diff --git a/src/signal.c b/src/signal.c index 69cdaa9b9..53c402998 100644 --- a/src/signal.c +++ b/src/signal.c @@ -27,6 +27,7 @@ #endif /* HAVE_STRINGS_H */ #include #include +#include #include #include "sudo.h" @@ -125,7 +126,7 @@ init_signals(void) * We use a pipe to atomically handle signal notification within * the select() loop without races (we may not have pselect()). */ - if (pipe_nonblock(signal_pipe) != 0) + if (pipe2(signal_pipe, O_NONBLOCK) != 0) sudo_fatal(U_("unable to create pipe")); memset(&sa, 0, sizeof(sa)); diff --git a/src/sudo.h b/src/sudo.h index 43175b680..cac16762d 100644 --- a/src/sudo.h +++ b/src/sudo.h @@ -195,7 +195,6 @@ char *tgetpass(const char *prompt, int timeout, int flags, struct sudo_conv_callback *callback); /* exec.c */ -int pipe_nonblock(int fds[2]); int sudo_execute(struct command_details *details, struct command_status *cstat); /* parse_args.c */ -- 2.40.0