Module Name: src Committed By: sjg Date: Fri Apr 23 00:18:50 UTC 2010
Modified Files: src/usr.bin/make: compat.c job.c main.c make.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 src/usr.bin/make/compat.c cvs rdiff -u -r1.148 -r1.149 src/usr.bin/make/job.c cvs rdiff -u -r1.182 -r1.183 src/usr.bin/make/main.c cvs rdiff -u -r1.81 -r1.82 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.77 src/usr.bin/make/compat.c:1.78 --- src/usr.bin/make/compat.c:1.77 Wed Apr 7 00:11:27 2010 +++ src/usr.bin/make/compat.c Fri Apr 23 00:18:50 2010 @@ -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"); } Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.148 src/usr.bin/make/job.c:1.149 --- src/usr.bin/make/job.c:1.148 Thu Apr 22 19:11:17 2010 +++ src/usr.bin/make/job.c Fri Apr 23 00:18:50 2010 @@ -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)); Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.182 src/usr.bin/make/main.c:1.183 --- src/usr.bin/make/main.c:1.182 Thu Apr 22 22:39:13 2010 +++ src/usr.bin/make/main.c Fri Apr 23 00:18:50 2010 @@ -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 Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.81 src/usr.bin/make/make.h:1.82 --- src/usr.bin/make/make.h:1.81 Thu Apr 22 19:11:17 2010 +++ src/usr.bin/make/make.h Fri Apr 23 00:18:50 2010 @@ -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 */