From dc1e0e71684a8d3b25d1645e02c4aa56076a8fcd Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 23 Jul 2018 11:37:26 -0600 Subject: [PATCH] Work around a bug on AIX where closing the pty slave causes the main sudo process to lose its controlling tty (which was *not* the pty slave). --- src/exec_pty.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/exec_pty.c b/src/exec_pty.c index 7adb0a389..814b0e497 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -754,9 +754,16 @@ pty_close(struct command_status *cstat) int n; debug_decl(pty_close, SUDO_DEBUG_EXEC); - /* Close the pty slave first so reads from the master don't block. */ - if (io_fds[SFD_SLAVE] != -1) +#ifndef _AIX + /* + * Close the pty slave first so reads from the master don't block. + * On AIX as it will cause us to lose *our* controlling tty too! + */ + if (io_fds[SFD_SLAVE] != -1) { close(io_fds[SFD_SLAVE]); + io_fds[SFD_SLAVE] = -1; + } +#endif /* Flush any remaining output (the plugin already got it). */ if (io_fds[SFD_USERTTY] != -1) { @@ -786,9 +793,13 @@ pty_close(struct command_status *cstat) if (utmp_user != NULL) utmp_logout(slavename, cstat->type == CMD_WSTATUS ? cstat->val : 0); +#ifndef _AIX /* Close pty master. */ - if (io_fds[SFD_MASTER] != -1) + if (io_fds[SFD_MASTER] != -1) { close(io_fds[SFD_MASTER]); + io_fds[SFD_MASTER] = -1; + } +#endif debug_return; } -- 2.40.0