On Solaris 11.4 the openpty(3) prototype lives in termios.h.

This commit is contained in:
Todd C. Miller
2020-06-01 12:59:29 -06:00
parent 51dc8ad83c
commit ad70fb4f1e
2 changed files with 23 additions and 16 deletions

View File

@@ -110,7 +110,7 @@ static void del_io_events(bool nonblocking);
static void sync_ttysize(struct exec_closure_pty *ec); static void sync_ttysize(struct exec_closure_pty *ec);
static int safe_close(int fd); static int safe_close(int fd);
static void ev_free_by_fd(struct sudo_event_base *evbase, int fd); static void ev_free_by_fd(struct sudo_event_base *evbase, int fd);
static void check_foreground(struct exec_closure_pty *ec); static pid_t check_foreground(struct exec_closure_pty *ec);
static void add_io_events(struct sudo_event_base *evbase); static void add_io_events(struct sudo_event_base *evbase);
static void schedule_signal(struct exec_closure_pty *ec, int signo); static void schedule_signal(struct exec_closure_pty *ec, int signo);
@@ -487,22 +487,25 @@ log_winchange(unsigned int rows, unsigned int cols)
/* /*
* Check whether we are running in the foregroup. * Check whether we are running in the foregroup.
* Updates the foreground global and does lazy init of the * Updates the foreground global and updates the window size.
* the pty slave as needed. * Returns 0 if there is no tty, the foreground process group ID
* on success, or -1 on failure (tty revoked).
*/ */
static void static pid_t
check_foreground(struct exec_closure_pty *ec) check_foreground(struct exec_closure_pty *ec)
{ {
int ret = 0;
debug_decl(check_foreground, SUDO_DEBUG_EXEC); debug_decl(check_foreground, SUDO_DEBUG_EXEC);
if (io_fds[SFD_USERTTY] != -1) { if (io_fds[SFD_USERTTY] != -1) {
foreground = tcgetpgrp(io_fds[SFD_USERTTY]) == ec->ppgrp; if ((ret = tcgetpgrp(io_fds[SFD_USERTTY])) != -1) {
foreground = ret == ec->ppgrp;
/* Also check for window size changes. */ /* Also check for window size changes. */
sync_ttysize(ec); sync_ttysize(ec);
}
} }
debug_return_int(ret);
debug_return;
} }
/* /*
@@ -568,6 +571,7 @@ suspend_sudo(struct exec_closure_pty *ec, int signo)
log_suspend(SIGCONT); log_suspend(SIGCONT);
/* Check foreground/background status on resume. */ /* Check foreground/background status on resume. */
/* XXX - handle missing tty */
check_foreground(ec); check_foreground(ec);
/* /*

View File

@@ -36,13 +36,16 @@
#include <fcntl.h> #include <fcntl.h>
#include <grp.h> #include <grp.h>
#if defined(HAVE_LIBUTIL_H) #if defined(HAVE_OPENPTY)
# include <libutil.h> # if defined(HAVE_LIBUTIL_H)
#elif defined(HAVE_UTIL_H) # include <libutil.h> /* *BSD */
# include <util.h> # elif defined(HAVE_UTIL_H)
#endif # include <util.h> /* macOS */
#ifdef HAVE_PTY_H # elif defined(HAVE_PTY_H)
# include <pty.h> # include <pty.h> /* Linux */
# else
# include <termios.h> /* Solaris */
# endif
#endif #endif
#include "sudo.h" #include "sudo.h"