From 15b4cde6921b1fa0fe32aa76a1e861d8bf1fe1a1 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 2 Feb 2023 20:10:03 -0700 Subject: [PATCH] Display an error message if unable to restore terminal settings. --- src/exec_pty.c | 18 ++++++++++++------ src/tgetpass.c | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/exec_pty.c b/src/exec_pty.c index 8e4ff84d9..25eae0780 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -73,8 +73,10 @@ pty_cleanup(void) { debug_decl(cleanup, SUDO_DEBUG_EXEC); - if (ttymode != TERM_COOKED) - sudo_term_restore(io_fds[SFD_USERTTY], false); + if (ttymode != TERM_COOKED) { + if (!sudo_term_restore(io_fds[SFD_USERTTY], false)) + sudo_warnx("%s", U_("unable to restore terminal settings")); + } if (utmp_user != NULL) utmp_logout(ptyname, 0); @@ -206,8 +208,10 @@ suspend_sudo_pty(struct exec_closure *ec, int signo) del_io_events(true); /* Restore original tty mode before suspending. */ - if (ttymode != TERM_COOKED) - sudo_term_restore(io_fds[SFD_USERTTY], false); + if (ttymode != TERM_COOKED) { + if (!sudo_term_restore(io_fds[SFD_USERTTY], false)) + sudo_warnx("%s", U_("unable to restore terminal settings")); + } /* Log the suspend event. */ log_suspend(ec, signo); @@ -502,8 +506,10 @@ pty_finish(struct exec_closure *ec, struct command_status *cstat) if (ttymode != TERM_COOKED) { /* Only restore the terminal if sudo is the foreground process. */ const pid_t tcpgrp = tcgetpgrp(io_fds[SFD_USERTTY]); - if (tcpgrp == ec->ppgrp) - sudo_term_restore(io_fds[SFD_USERTTY], false); + if (tcpgrp == ec->ppgrp) { + if (!sudo_term_restore(io_fds[SFD_USERTTY], false)) + sudo_warnx("%s", U_("unable to restore terminal settings")); + } } /* Update utmp */ diff --git a/src/tgetpass.c b/src/tgetpass.c index e99aecd2c..0e73ed68a 100644 --- a/src/tgetpass.c +++ b/src/tgetpass.c @@ -247,7 +247,8 @@ restore: /* Restore old tty settings. */ if (!ISSET(flags, TGP_ECHO)) { /* 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) (void) close(ttyfd);