From 92d4bb5814245a5d2ae8211dd8b0a570d42f08d3 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 24 Mar 2023 15:26:37 -0600 Subject: Make iobufs private to exec_iolog.c. --- src/exec_iolog.c | 9 ++++----- src/exec_nopty.c | 6 +++--- src/exec_pty.c | 10 +++++----- src/sudo_exec.h | 3 +-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/exec_iolog.c b/src/exec_iolog.c index 6b8225982..143dc70fe 100644 --- a/src/exec_iolog.c +++ b/src/exec_iolog.c @@ -36,10 +36,10 @@ #include "sudo_plugin.h" #include "sudo_plugin_int.h" -struct io_buffer_list iobufs = SLIST_HEAD_INITIALIZER(&iobufs); - int io_fds[6] = { -1, -1, -1, -1, -1, -1 }; +static struct io_buffer_list iobufs = SLIST_HEAD_INITIALIZER(&iobufs); + static sigset_t ttyblock; /* @@ -103,8 +103,7 @@ void io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int, struct io_buffer *), void (*read_cb)(int fd, int what, void *v), - void (*write_cb)(int fd, int what, void *v), - struct exec_closure *ec, struct io_buffer_list *head) + void (*write_cb)(int fd, int what, void *v), struct exec_closure *ec) { int n; struct io_buffer *iob; @@ -132,7 +131,7 @@ io_buf_new(int rfd, int wfd, iob->buf[0] = '\0'; if (iob->revent == NULL || iob->wevent == NULL) sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); - SLIST_INSERT_HEAD(head, iob, entries); + SLIST_INSERT_HEAD(&iobufs, iob, entries); debug_return; } diff --git a/src/exec_nopty.c b/src/exec_nopty.c index efb92b7a7..e4e077b7b 100644 --- a/src/exec_nopty.c +++ b/src/exec_nopty.c @@ -502,7 +502,7 @@ interpose_pipes(struct exec_closure *ec, int io_pipe[3][2]) if (pipe2(io_pipe[STDIN_FILENO], O_CLOEXEC) != 0) sudo_fatal("%s", U_("unable to create pipe")); io_buf_new(STDIN_FILENO, io_pipe[STDIN_FILENO][1], - log_stdin, read_callback, write_callback, ec, &iobufs); + log_stdin, read_callback, write_callback, ec); } } if (interpose[STDOUT_FILENO]) { @@ -512,7 +512,7 @@ interpose_pipes(struct exec_closure *ec, int io_pipe[3][2]) if (pipe2(io_pipe[STDOUT_FILENO], O_CLOEXEC) != 0) sudo_fatal("%s", U_("unable to create pipe")); io_buf_new(io_pipe[STDOUT_FILENO][0], STDOUT_FILENO, - log_stdout, read_callback, write_callback, ec, &iobufs); + log_stdout, read_callback, write_callback, ec); } } if (interpose[STDERR_FILENO]) { @@ -522,7 +522,7 @@ interpose_pipes(struct exec_closure *ec, int io_pipe[3][2]) if (pipe2(io_pipe[STDERR_FILENO], O_CLOEXEC) != 0) sudo_fatal("%s", U_("unable to create pipe")); io_buf_new(io_pipe[STDERR_FILENO][0], STDERR_FILENO, - log_stderr, read_callback, write_callback, ec, &iobufs); + log_stderr, read_callback, write_callback, ec); } } if (want_winch) { diff --git a/src/exec_pty.c b/src/exec_pty.c index b9059e4f2..1000c8b82 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -1160,12 +1160,12 @@ exec_pty(struct command_details *details, struct command_status *cstat) /* Read from /dev/tty, write to pty leader */ if (!ISSET(details->flags, CD_BACKGROUND)) { io_buf_new(io_fds[SFD_USERTTY], io_fds[SFD_LEADER], - log_ttyin, read_callback, write_callback, &ec, &iobufs); + log_ttyin, read_callback, write_callback, &ec); } /* Read from pty leader, write to /dev/tty */ io_buf_new(io_fds[SFD_LEADER], io_fds[SFD_USERTTY], - log_ttyout, read_callback, write_callback, &ec, &iobufs); + log_ttyout, read_callback, write_callback, &ec); /* Are we the foreground process? */ ec.foreground = tcgetpgrp(io_fds[SFD_USERTTY]) == ppgrp; @@ -1194,7 +1194,7 @@ exec_pty(struct command_details *details, struct command_status *cstat) if (pipe2(io_pipe[STDIN_FILENO], O_CLOEXEC) != 0) sudo_fatal("%s", U_("unable to create pipe")); io_buf_new(STDIN_FILENO, io_pipe[STDIN_FILENO][1], - log_stdin, read_callback, write_callback, &ec, &iobufs); + log_stdin, read_callback, write_callback, &ec); io_fds[SFD_STDIN] = io_pipe[STDIN_FILENO][0]; } @@ -1225,7 +1225,7 @@ exec_pty(struct command_details *details, struct command_status *cstat) if (pipe2(io_pipe[STDOUT_FILENO], O_CLOEXEC) != 0) sudo_fatal("%s", U_("unable to create pipe")); io_buf_new(io_pipe[STDOUT_FILENO][0], STDOUT_FILENO, - log_stdout, read_callback, write_callback, &ec, &iobufs); + log_stdout, read_callback, write_callback, &ec); io_fds[SFD_STDOUT] = io_pipe[STDOUT_FILENO][1]; } } @@ -1245,7 +1245,7 @@ exec_pty(struct command_details *details, struct command_status *cstat) if (pipe2(io_pipe[STDERR_FILENO], O_CLOEXEC) != 0) sudo_fatal("%s", U_("unable to create pipe")); io_buf_new(io_pipe[STDERR_FILENO][0], STDERR_FILENO, - log_stderr, read_callback, write_callback, &ec, &iobufs); + log_stderr, read_callback, write_callback, &ec); io_fds[SFD_STDERR] = io_pipe[STDERR_FILENO][1]; } } diff --git a/src/sudo_exec.h b/src/sudo_exec.h index 542c1b143..8bf3c2aad 100644 --- a/src/sudo_exec.h +++ b/src/sudo_exec.h @@ -195,14 +195,13 @@ bool log_stdout(const char *buf, unsigned int n, struct io_buffer *iob); bool log_stderr(const char *buf, unsigned int n, struct io_buffer *iob); void log_suspend(void *v, int signo); void log_winchange(struct exec_closure *ec, unsigned int rows, unsigned int cols); -void io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int, struct io_buffer *), void (*read_cb)(int fd, int what, void *v), void (*write_cb)(int fd, int what, void *v), struct exec_closure *ec, struct io_buffer_list *head); +void io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int, struct io_buffer *), void (*read_cb)(int fd, int what, void *v), void (*write_cb)(int fd, int what, void *v), struct exec_closure *ec); int safe_close(int fd); void ev_free_by_fd(struct sudo_event_base *evbase, int fd); void free_io_bufs(void); void add_io_events(struct exec_closure *ec); void del_io_events(bool nonblocking); void init_ttyblock(void); -extern struct io_buffer_list iobufs; /* exec_nopty.c */ void exec_nopty(struct command_details *details, struct command_status *cstat); -- cgit v1.2.1