Replace pipe_nonblock() with pipe2()
This commit is contained in:
29
src/exec.c
29
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);
|
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.
|
* Kill command with increasing urgency.
|
||||||
*/
|
*/
|
||||||
|
@@ -492,7 +492,7 @@ exec_monitor(struct command_details *details, bool foreground, int backchannel)
|
|||||||
* We use a pipe to atomically handle signal notification within
|
* We use a pipe to atomically handle signal notification within
|
||||||
* the event loop.
|
* the event loop.
|
||||||
*/
|
*/
|
||||||
if (pipe_nonblock(signal_pipe) != 0)
|
if (pipe2(signal_pipe, O_NONBLOCK) != 0)
|
||||||
sudo_fatal(U_("unable to create pipe"));
|
sudo_fatal(U_("unable to create pipe"));
|
||||||
|
|
||||||
/* Reset SIGWINCH and SIGALRM. */
|
/* Reset SIGWINCH and SIGALRM. */
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#endif /* HAVE_STRINGS_H */
|
#endif /* HAVE_STRINGS_H */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "sudo.h"
|
#include "sudo.h"
|
||||||
@@ -125,7 +126,7 @@ init_signals(void)
|
|||||||
* We use a pipe to atomically handle signal notification within
|
* We use a pipe to atomically handle signal notification within
|
||||||
* the select() loop without races (we may not have pselect()).
|
* 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"));
|
sudo_fatal(U_("unable to create pipe"));
|
||||||
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
@@ -195,7 +195,6 @@ char *tgetpass(const char *prompt, int timeout, int flags,
|
|||||||
struct sudo_conv_callback *callback);
|
struct sudo_conv_callback *callback);
|
||||||
|
|
||||||
/* exec.c */
|
/* exec.c */
|
||||||
int pipe_nonblock(int fds[2]);
|
|
||||||
int sudo_execute(struct command_details *details, struct command_status *cstat);
|
int sudo_execute(struct command_details *details, struct command_status *cstat);
|
||||||
|
|
||||||
/* parse_args.c */
|
/* parse_args.c */
|
||||||
|
Reference in New Issue
Block a user