]> granicus.if.org Git - sudo/commitdiff
Don't try to restore the terminal if we are not the foreground
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 23 May 2012 18:17:41 +0000 (14:17 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 23 May 2012 18:17:41 +0000 (14:17 -0400)
process.  Otherwise, we may be stopped by SIGTTOU when we try to
update the terminal settings when cleaning up.

--HG--
branch : 1.7

exec_pty.c
sudo.c
sudo.h

index ef39f80e986a145ee93695915a7d748eb3f64729..b0bc8f0bbdda9c041fc6eaffa350f6d355f31b22 100644 (file)
@@ -525,9 +525,12 @@ pty_close(cstat)
     flush_output();
 
     if (io_fds[SFD_USERTTY] != -1) {
-       do {
-           n = term_restore(io_fds[SFD_USERTTY], 0);
-       } while (!n && errno == EINTR);
+       check_foreground();
+       if (foreground) {
+           do {
+               n = term_restore(io_fds[SFD_USERTTY], 0);
+           } while (!n && errno == EINTR);
+       }
     }
 
     /* If child was signalled, write the reason to stdout like the shell. */
@@ -1080,3 +1083,14 @@ safe_close(fd)
     }
     return close(fd);
 }
+
+void
+cleanup_pty(gotsignal)
+    int gotsignal;
+{
+    if (io_fds[SFD_USERTTY] != -1) {
+       check_foreground();
+       if (foreground)
+           term_restore(io_fds[SFD_USERTTY], 0);
+    }
+}
diff --git a/sudo.c b/sudo.c
index ad90d392609334a1cdbe734d96ad7a49a8c1b04a..584f4ff279cfebd776522bbde94a8c39b4521b80 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -1331,7 +1331,9 @@ cleanup(gotsignal)
        io_log_close();
 #endif
     }
-    term_restore(STDIN_FILENO, 0);
+#ifdef _PATH_SUDO_IO_LOGDIR
+    cleanup_pty(gotsignal);
+#endif
 #ifdef HAVE_SELINUX
     selinux_restore_tty();
 #endif
diff --git a/sudo.h b/sudo.h
index b106162d45d6b64d86b5d66a4df6cbd523cbce22..32471f2e36f5f099a9a38a4b5573b5b9845047ff 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -239,6 +239,9 @@ int sudo_execve __P((const char *path, char *argv[], char *envp[], uid_t uid,
 void save_signals __P((void));
 void restore_signals __P((void));
 
+/* exec_pty.c */
+void cleanup_pty __P((int gotsignal));
+
 /* fileops.c */
 char *sudo_parseln     __P((FILE *));
 int lock_file          __P((int, int));