Module Name:    src
Committed By:   sjg
Date:           Thu Jul 20 19:29:54 UTC 2017

Modified Files:
        src/usr.bin/make: compat.c job.c make.h

Log Message:
Make compat.c handle SIGINT etc more like job.c

If there is a running child, pass the signal on, and
wait for it to exit before we self-terminate.

Reviewed by: christos


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/make/compat.c
cvs rdiff -u -r1.190 -r1.191 src/usr.bin/make/job.c
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/make/make.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/compat.c
diff -u src/usr.bin/make/compat.c:1.106 src/usr.bin/make/compat.c:1.107
--- src/usr.bin/make/compat.c:1.106	Fri Aug 26 23:28:39 2016
+++ src/usr.bin/make/compat.c	Thu Jul 20 19:29:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.106 2016/08/26 23:28:39 dholland Exp $	*/
+/*	$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.106 2016/08/26 23:28:39 dholland Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.106 2016/08/26 23:28:39 dholland Exp $");
+__RCSID("$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -115,6 +115,8 @@ __RCSID("$NetBSD: compat.c,v 1.106 2016/
 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,17 @@ CompatInterrupt(int signo)
     }
     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 exist after it has exited.
+     */
+    compatSigno = signo;
+    if (compatChild > 0) {
+	KILLPG(compatChild, signo);
+    } else {
+	bmake_signal(signo, SIG_DFL);
+	kill(myPid, signo);
+    }
 }
 
 /*-
@@ -367,7 +378,7 @@ again:
     /*
      * Fork and execute the single command. If the fork fails, we abort.
      */
-    cpid = vFork();
+    compatChild = cpid = vFork();
     if (cpid < 0) {
 	Fatal("Could not fork");
     }
@@ -480,7 +491,12 @@ again:
 	}
     }
     free(cmdStart);
-
+    compatChild = 0;
+    if (compatSigno) {
+	bmake_signal(compatSigno, SIG_DFL);
+	kill(myPid, compatSigno);
+    }
+    
     return (status);
 }
 

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.190 src/usr.bin/make/job.c:1.191
--- src/usr.bin/make/job.c:1.190	Sun Apr 16 21:23:43 2017
+++ src/usr.bin/make/job.c	Thu Jul 20 19:29:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.190 2017/04/16 21:23:43 riastradh Exp $	*/
+/*	$NetBSD: job.c,v 1.191 2017/07/20 19:29:54 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.190 2017/04/16 21:23:43 riastradh Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.191 2017/07/20 19:29:54 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.190 2017/04/16 21:23:43 riastradh Exp $");
+__RCSID("$NetBSD: job.c,v 1.191 2017/07/20 19:29:54 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -335,11 +335,6 @@ static Job childExitJob;	/* child exit p
 	    (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: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.102 src/usr.bin/make/make.h:1.103
--- src/usr.bin/make/make.h:1.102	Wed Dec  7 15:00:46 2016
+++ src/usr.bin/make/make.h	Thu Jul 20 19:29:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.102 2016/12/07 15:00:46 christos Exp $	*/
+/*	$NetBSD: make.h,v 1.103 2017/07/20 19:29:54 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -525,4 +525,10 @@ int cached_stat(const char *, void *);
 #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_ */

Reply via email to