Display an error message if unable to restore terminal settings.

This commit is contained in:
Todd C. Miller
2023-02-02 20:10:03 -07:00
parent 1758c49d3e
commit 15b4cde692
2 changed files with 14 additions and 7 deletions

View File

@@ -73,8 +73,10 @@ pty_cleanup(void)
{ {
debug_decl(cleanup, SUDO_DEBUG_EXEC); debug_decl(cleanup, SUDO_DEBUG_EXEC);
if (ttymode != TERM_COOKED) if (ttymode != TERM_COOKED) {
sudo_term_restore(io_fds[SFD_USERTTY], false); if (!sudo_term_restore(io_fds[SFD_USERTTY], false))
sudo_warnx("%s", U_("unable to restore terminal settings"));
}
if (utmp_user != NULL) if (utmp_user != NULL)
utmp_logout(ptyname, 0); utmp_logout(ptyname, 0);
@@ -206,8 +208,10 @@ suspend_sudo_pty(struct exec_closure *ec, int signo)
del_io_events(true); del_io_events(true);
/* Restore original tty mode before suspending. */ /* Restore original tty mode before suspending. */
if (ttymode != TERM_COOKED) if (ttymode != TERM_COOKED) {
sudo_term_restore(io_fds[SFD_USERTTY], false); if (!sudo_term_restore(io_fds[SFD_USERTTY], false))
sudo_warnx("%s", U_("unable to restore terminal settings"));
}
/* Log the suspend event. */ /* Log the suspend event. */
log_suspend(ec, signo); log_suspend(ec, signo);
@@ -502,8 +506,10 @@ pty_finish(struct exec_closure *ec, struct command_status *cstat)
if (ttymode != TERM_COOKED) { if (ttymode != TERM_COOKED) {
/* Only restore the terminal if sudo is the foreground process. */ /* Only restore the terminal if sudo is the foreground process. */
const pid_t tcpgrp = tcgetpgrp(io_fds[SFD_USERTTY]); const pid_t tcpgrp = tcgetpgrp(io_fds[SFD_USERTTY]);
if (tcpgrp == ec->ppgrp) if (tcpgrp == ec->ppgrp) {
sudo_term_restore(io_fds[SFD_USERTTY], false); if (!sudo_term_restore(io_fds[SFD_USERTTY], false))
sudo_warnx("%s", U_("unable to restore terminal settings"));
}
} }
/* Update utmp */ /* Update utmp */

View File

@@ -247,7 +247,8 @@ restore:
/* Restore old tty settings. */ /* Restore old tty settings. */
if (!ISSET(flags, TGP_ECHO)) { if (!ISSET(flags, TGP_ECHO)) {
/* Restore old tty settings if possible. */ /* Restore old tty settings if possible. */
(void) sudo_term_restore(input, true); if (!sudo_term_restore(input, true))
sudo_warnx("%s", U_("unable to restore terminal settings"));
} }
if (ttyfd != -1) if (ttyfd != -1)
(void) close(ttyfd); (void) close(ttyfd);