tech-toolchain archive

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

make: compat should let child die first on Interrupt.



Analysis of a FreeBSD ports PR, shows that compat.c should handle
signals more like job.c, as in pass the signal to the child, and
self terminate after the child has died.

This is important for the ports case, because a the child needs to
restore tty state on exit.

Patch below does the job, but perhaps variable names could be improved.

diff -r 829af08a482b bmake/compat.c
--- a/bmake/compat.c	Sat Jul 15 11:26:05 2017 -0700
+++ b/bmake/compat.c	Wed Jul 19 19:58:01 2017 -0700
@@ -118,6 +118,8 @@
 static GNode	    *curTarg = NULL;
 static GNode	    *ENDNode;
 static void CompatInterrupt(int);
+static pid_t compatChild;
+static int signaled;
 
 /*
  * CompatDeleteTarget -- delete a failed, interrupted, or otherwise
@@ -176,8 +178,13 @@
     }
     if (signo == SIGQUIT)
 	_exit(signo);
-    bmake_signal(signo, SIG_DFL);
-    kill(myPid, signo);
+    signaled = signo;
+    if (compatChild > 0) {
+	KILLPG(compatChild, signo);	/* pass it on - we die later */
+    } else {
+	bmake_signal(signo, SIG_DFL);
+	kill(myPid, signo);
+    }
 }
 
 /*-
@@ -370,7 +377,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");
     }
@@ -484,6 +491,11 @@
     }
     free(cmdStart);
 
+    if (signaled) {
+	bmake_signal(signaled, SIG_DFL);
+	kill(myPid, signaled);
+    }
+    
     return (status);
 }
 
diff -r 829af08a482b bmake/job.c
--- a/bmake/job.c	Sat Jul 15 11:26:05 2017 -0700
+++ b/bmake/job.c	Wed Jul 19 19:58:01 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	Wed Jul 19 19:58:01 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