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.



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:

Index: compat.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/compat.c,v
retrieving revision 1.106
diff -u -u -r1.106 compat.c
--- compat.c	26 Aug 2016 23:28:39 -0000	1.106
+++ compat.c	20 Jul 2017 12:33:21 -0000
@@ -115,6 +115,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
@@ -173,8 +175,15 @@
     }
     if (signo == SIGQUIT)
 	_exit(signo);
-    bmake_signal(signo, SIG_DFL);
-    kill(myPid, signo);
+    compatSigno = signo;
+    if (compatChild > 0) {
+	pid_t child = compatChild;
+	compatChild = 0;
+	KILLPG(child, signo);	/* pass it on - we die later */
+    } else {
+	bmake_signal(signo, SIG_DFL);
+	kill(myPid, signo);
+    }
 }
 
 /*-
@@ -367,7 +376,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");
     }
@@ -481,6 +490,13 @@
     }
     free(cmdStart);
 
+    if (compatSigno) {
+	int signo = compatSigno;
+	compatSigno = 0;
+	bmake_signal(signo, SIG_DFL);
+	kill(myPid, signo);
+    }
+    
     return (status);
 }
 
Index: job.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/job.c,v
retrieving revision 1.190
diff -u -u -r1.190 job.c
--- job.c	16 Apr 2017 21:23:43 -0000	1.190
+++ job.c	20 Jul 2017 12:33:22 -0000
@@ -335,11 +335,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);
Index: make.h
===================================================================
RCS file: /cvsroot/src/usr.bin/make/make.h,v
retrieving revision 1.102
diff -u -u -r1.102 make.h
--- make.h	7 Dec 2016 15:00:46 -0000	1.102
+++ make.h	20 Jul 2017 12:33:22 -0000
@@ -525,4 +525,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