From 7d06308236d18622bdbc6429f3dfa5216f3f7dd7 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 8 Mar 2010 14:27:30 -0500 Subject: [PATCH] Use parent process group id instead of parent process id when checking foreground status and suspending parent. Fixes an issue when running commands under /usr/bin/time and others. --HG-- branch : 1.7 --- script.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/script.c b/script.c index 91c92ad8c..c495131a5 100644 --- 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); -- 2.49.0