-#ifdef _POSIX_VDISABLE
- if (echo || status != _POSIX_VDISABLE) {
-#else
- if (echo) {
-#endif
- if (echo) {
- (void)write(output, "\n", 1);
- term.c_lflag |= ECHO;
- }
-#ifdef VSTATUS
- if (status != _POSIX_VDISABLE)
- term.c_cc[VSTATUS] = status;
-#endif
- (void)tcsetattr(input, _T_FLUSH, &term);
- }
- (void)sigprocmask(SIG_SETMASK, &oset, NULL);
+ save_errno = errno;
+ if (!(term.c_lflag & ECHO))
+ (void)write(output, "\n", 1);
+
+ /* Restore old terminal settings and signals. */
+ if (memcmp(&term, &oterm, sizeof(term)) != 0)
+ (void)tcsetattr(input, _T_FLUSH, &oterm);
+ (void)sigaction(SIGINT, &saveint, NULL);
+ (void)sigaction(SIGHUP, &savehup, NULL);
+ (void)sigaction(SIGQUIT, &savequit, NULL);
+ (void)sigaction(SIGTERM, &saveterm, NULL);
+ (void)sigaction(SIGTSTP, &savetstp, NULL);
+ (void)sigaction(SIGTTIN, &savettin, NULL);
+ (void)sigaction(SIGTTOU, &savettou, NULL);