summary refs log tree commit diff
path: root/Src/signals.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2016-09-16 09:34:17 +0100
committerPeter Stephenson <pws@zsh.org>2016-09-16 17:23:12 +0100
commit327f3dd3adfc8fdd6c356722d093a340b81190a7 (patch)
tree013049092ef15b18d3dc4c308a3fc9ab7c7b765a /Src/signals.c
parent01ae64c0d74c17e36bfe6f52394a59754b8e8c92 (diff)
downloadzsh-327f3dd3adfc8fdd6c356722d093a340b81190a7.tar.gz
zsh-327f3dd3adfc8fdd6c356722d093a340b81190a7.tar.xz
zsh-327f3dd3adfc8fdd6c356722d093a340b81190a7.zip
39359: Fix remaining race with orphaned subjob.
When shell is forked to run right hand side of pipieline it should
use its own PID as process group if the left hand side of the
pipeline has already exited.
Diffstat (limited to 'Src/signals.c')
-rw-r--r--Src/signals.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Src/signals.c b/Src/signals.c
index 2eefc07de..30dde713f 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -723,7 +723,7 @@ killjb(Job jn, int sig)
 {
     Process pn;
     int err = 0;
- 
+
     if (jobbing) {
         if (jn->stat & STAT_SUPERJOB) {
             if (sig == SIGCONT) {
@@ -731,11 +731,21 @@ killjb(Job jn, int sig)
                     if (killpg(pn->pid, sig) == -1)
 			if (kill(pn->pid, sig) == -1 && errno != ESRCH)
 			    err = -1;
- 
+
+		/*
+		 * Note this does not kill the last process,
+		 * which is assumed to be the one controlling the
+		 * subjob, i.e. the forked zsh that was originally
+		 * list_pipe_pid...
+		 */
                 for (pn = jn->procs; pn->next; pn = pn->next)
                     if (kill(pn->pid, sig) == -1 && errno != ESRCH)
 			err = -1;
 
+		/*
+		 * ...we only continue that once the external processes
+		 * currently associated with the subjob are finished.
+		 */
 		if (!jobtab[jn->other].procs && pn)
 		    if (kill(pn->pid, sig) == -1 && errno != ESRCH)
 			err = -1;
@@ -744,7 +754,7 @@ killjb(Job jn, int sig)
             }
             if (killpg(jobtab[jn->other].gleader, sig) == -1 && errno != ESRCH)
 		err = -1;
-		
+
 	    if (killpg(jn->gleader, sig) == -1 && errno != ESRCH)
 		err = -1;