From: Todd C. Miller Date: Mon, 23 Jul 2018 17:37:26 +0000 (-0600) Subject: Work around a bug on AIX where closing the pty slave causes the X-Git-Tag: SUDO_1_8_24^2~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc1e0e71684a8d3b25d1645e02c4aa56076a8fcd;p=sudo 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). --- 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; }