tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: make: compat should let child die first on Interrupt.



Christos Zoulas <christos%zoulas.com@localhost> wrote:

> On Jul 19,  8:06pm, sjg%juniper.net@localhost (Simon J Gerraty) wrote:
> -- Subject: make: compat should let child die first on Interrupt.
> 
> Sure, perhaps safer to:

Below is my current patch - reverted the death in CompatInterrupt
if there may be a child running.

diff -r 829af08a482b bmake/compat.c
--- a/bmake/compat.c	Sat Jul 15 11:26:05 2017 -0700
+++ b/bmake/compat.c	Thu Jul 20 10:45:13 2017 -0700
@@ -118,6 +118,8 @@
 static GNode	    *curTarg = NULL;
 static GNode	    *ENDNode;
 static void CompatInterrupt(int);
+static pid_t compatChild;
+static int compatSigno;
 
 /*
  * CompatDeleteTarget -- delete a failed, interrupted, or otherwise
@@ -176,8 +178,17 @@
     }
     if (signo == SIGQUIT)
 	_exit(signo);
-    bmake_signal(signo, SIG_DFL);
-    kill(myPid, signo);
+    /*
+     * If there is a child running, pass the signal on
+     * we will self-terminate after it has exited.
+     */
+    compatSigno = signo;
+    if (compatChild > 0) {
+	KILLPG(compatChild, signo);
+    } else {
+	bmake_signal(signo, SIG_DFL);
+	kill(myPid, signo);
+    }
 }
 
 /*-
@@ -370,7 +381,7 @@
     /*
      * Fork and execute the single command. If the fork fails, we abort.
      */
-    cpid = vFork();
+    compatChild = cpid = vFork();
     if (cpid < 0) {
 	Fatal("Could not fork");
     }
@@ -483,7 +494,12 @@
 	}
     }
     free(cmdStart);
-
+    compatChild = 0;
+    if (compatSigno) {
+	bmake_signal(compatSigno, SIG_DFL);
+	kill(myPid, compatSigno);
+    }
+    
     return (status);
 }
 
diff -r 829af08a482b bmake/job.c
--- a/bmake/job.c	Sat Jul 15 11:26:05 2017 -0700
+++ b/bmake/job.c	Thu Jul 20 10:45:13 2017 -0700
@@ -359,11 +359,6 @@
 	    (void)fprintf(fp, TARG_FMT, targPrefix, gn->name)
 
 static sigset_t caught_signals;	/* Set of signals we handle */
-#if defined(SYSV)
-#define KILLPG(pid, sig)	kill(-(pid), (sig))
-#else
-#define KILLPG(pid, sig)	killpg((pid), (sig))
-#endif
 
 static void JobChildSig(int);
 static void JobContinueSig(int);
diff -r 829af08a482b bmake/make.h
--- a/bmake/make.h	Sat Jul 15 11:26:05 2017 -0700
+++ b/bmake/make.h	Thu Jul 20 10:45:13 2017 -0700
@@ -546,4 +546,10 @@
 #define PATH_MAX	MAXPATHLEN
 #endif
 
+#if defined(SYSV)
+#define KILLPG(pid, sig)	kill(-(pid), (sig))
+#else
+#define KILLPG(pid, sig)	killpg((pid), (sig))
+#endif
+
 #endif /* _MAKE_H_ */


Home | Main Index | Thread Index | Old Index