Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make On darwin at least, vfork() fails in child of v...



details:   https://anonhg.NetBSD.org/src/rev/d3a41db97145
branches:  trunk
changeset: 754183:d3a41db97145
user:      sjg <sjg%NetBSD.org@localhost>
date:      Fri Apr 23 00:18:50 2010 +0000

description:
On darwin at least, vfork() fails in child of vfork().
It probably shouldn't work anyway, so avoid this.
We use the macro vFork() - a function seems to cause problems
and is unnecessary overhead.

diffstat:

 usr.bin/make/compat.c |   8 ++++----
 usr.bin/make/job.c    |   8 ++++----
 usr.bin/make/main.c   |  13 ++++++++-----
 usr.bin/make/make.h   |   9 ++++++++-
 4 files changed, 24 insertions(+), 14 deletions(-)

diffs (155 lines):

diff -r ad4c2b0f89ed -r d3a41db97145 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Thu Apr 22 22:39:13 2010 +0000
+++ b/usr.bin/make/compat.c     Fri Apr 23 00:18:50 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.77 2010/04/07 00:11:27 sjg Exp $  */
+/*     $NetBSD: compat.c,v 1.78 2010/04/23 00:18:50 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.77 2010/04/07 00:11:27 sjg Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.78 2010/04/23 00:18:50 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.77 2010/04/07 00:11:27 sjg Exp $");
+__RCSID("$NetBSD: compat.c,v 1.78 2010/04/23 00:18:50 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -355,7 +355,7 @@
     /*
      * Fork and execute the single command. If the fork fails, we abort.
      */
-    cpid = vfork();
+    cpid = vFork();
     if (cpid < 0) {
        Fatal("Could not fork");
     }
diff -r ad4c2b0f89ed -r d3a41db97145 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Thu Apr 22 22:39:13 2010 +0000
+++ b/usr.bin/make/job.c        Fri Apr 23 00:18:50 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.148 2010/04/22 19:11:17 sjg Exp $    */
+/*     $NetBSD: job.c,v 1.149 2010/04/23 00:18:50 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.148 2010/04/22 19:11:17 sjg Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.149 2010/04/23 00:18:50 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.148 2010/04/22 19:11:17 sjg Exp $");
+__RCSID("$NetBSD: job.c,v 1.149 2010/04/23 00:18:50 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1299,7 +1299,7 @@
     /* Pre-emptively mark job running, pid still zero though */
     job->job_state = JOB_ST_RUNNING;
 
-    cpid = vfork();
+    cpid = vFork();
     if (cpid == -1)
        Punt("Cannot vfork: %s", strerror(errno));
 
diff -r ad4c2b0f89ed -r d3a41db97145 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Thu Apr 22 22:39:13 2010 +0000
+++ b/usr.bin/make/main.c       Fri Apr 23 00:18:50 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.182 2010/04/22 22:39:13 dholland Exp $      */
+/*     $NetBSD: main.c,v 1.183 2010/04/23 00:18:50 sjg Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.182 2010/04/22 22:39:13 dholland Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.183 2010/04/23 00:18:50 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.182 2010/04/22 22:39:13 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.183 2010/04/23 00:18:50 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -185,6 +185,7 @@
 static char objdir[MAXPATHLEN + 1];    /* where we chdir'ed to */
 char *progname;                                /* the program name */
 char *makeDependfile;
+pid_t myPid;
 
 Boolean forceJobs = FALSE;
 
@@ -842,6 +843,8 @@
 #endif
        }
 
+       myPid = getpid();               /* remember this for vFork() */
+
        /*
         * Just in case MAKEOBJDIR wants us to do something tricky.
         */
@@ -923,7 +926,7 @@
                ep = "0";
            }
            Var_Set(MAKE_LEVEL, ep, VAR_GLOBAL, 0);
-           snprintf(tmp, sizeof(tmp), "%u", getpid());
+           snprintf(tmp, sizeof(tmp), "%u", myPid);
            Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
            snprintf(tmp, sizeof(tmp), "%u", getppid());
            Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0);
@@ -1581,7 +1584,7 @@
     /*
      * Fork
      */
-    switch (cpid = vfork()) {
+    switch (cpid = vFork()) {
     case 0:
        /*
         * Close input side of pipe
diff -r ad4c2b0f89ed -r d3a41db97145 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Thu Apr 22 22:39:13 2010 +0000
+++ b/usr.bin/make/make.h       Fri Apr 23 00:18:50 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.81 2010/04/22 19:11:17 sjg Exp $    */
+/*     $NetBSD: make.h,v 1.82 2010/04/23 00:18:50 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -395,6 +395,13 @@
 extern char    *progname;      /* The program name */
 extern char    *makeDependfile; /* .depend */
 
+/*
+ * We cannot vfork() in a child of vfork().
+ * Most systems do not enforce this but some do.
+ */
+#define vFork() ((getpid() == myPid) ? vfork() : fork())
+extern pid_t   myPid;
+
 #define        MAKEFLAGS       ".MAKEFLAGS"
 #define        MAKEOVERRIDES   ".MAKEOVERRIDES"
 #define        MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX" /* prefix for job target output */



Home | Main Index | Thread Index | Old Index