]> granicus.if.org Git - sudo/commitdiff
Use parent process group id instead of parent process id when checking
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 8 Mar 2010 19:27:30 +0000 (14:27 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 8 Mar 2010 19:27:30 +0000 (14:27 -0500)
foreground status and suspending parent.  Fixes an issue when running
commands under /usr/bin/time and others.

--HG--
branch : 1.7

script.c

index 91c92ad8c957bc6f5fd199c4dd9ae9fc98554751..c495131a5970cd8d40137d6b325c4c5751fe66cb 100644 (file)
--- a/script.c
+++ b/script.c
@@ -108,7 +108,7 @@ static sig_atomic_t tty_initialized = 0;
 
 static sigset_t ttyblock;
 
-static pid_t parent, child;
+static pid_t ppgrp, child;
 static int child_status;
 static int foreground;
 
@@ -356,7 +356,7 @@ log_output(buf, n, then, now, ofile, tfile)
 static void
 check_foreground()
 {
-    foreground = tcgetpgrp(script_fds[SFD_USERTTY]) == parent;
+    foreground = tcgetpgrp(script_fds[SFD_USERTTY]) == ppgrp;
     if (foreground && !tty_initialized) {
        if (term_copy(script_fds[SFD_USERTTY], script_fds[SFD_SLAVE], ttyout)) {
            tty_initialized = 1;
@@ -419,7 +419,7 @@ suspend_parent(signo, output, then, now, ofile, tfile)
 #ifdef SCRIPT_DEBUG
        warningx("kill parent %d", signo);
 #endif
-       kill(parent, signo);
+       killpg(ppgrp, signo);
 
        /* Check foreground/background status on resume. */
        check_foreground();
@@ -496,8 +496,8 @@ script_execv(path, argv)
 #endif
 
     /* Are we the foreground process? */
-    parent = getpid(); /* so child can pass signals back to us */
-    foreground = tcgetpgrp(script_fds[SFD_USERTTY]) == parent;
+    ppgrp = getpgrp(); /* so child can pass signals back to us */
+    foreground = tcgetpgrp(script_fds[SFD_USERTTY]) == ppgrp;
 
     /* So we can block tty-generated signals */
     sigemptyset(&ttyblock);