Module Name: src
Committed By: rillig
Date: Mon Feb 1 21:04:11 UTC 2021
Modified Files:
src/usr.bin/make: compat.c job.c main.c make.h
Log Message:
make: always use vfork, never fork
Before compat.c 1.217, job.c 1.390 and main.c 1.504 from 2020-12-27, the
exported make variables were exported from each freshly forked child
process. There was no practical difference though between exporting the
variables from the parent process or the child process since these two
processes share the same address space, except that the forked process
is very limited in what it may actually do. This limitation was
violated on a regular basis.
When an exported variable referred to a variable that used the :sh
variable modifier, this led to a fork from within vfork, which is not
allowed. Since 2020-12-27, exporting the variables is done from the
main process, which prevents this situation from ever occurring.
Since that day, there is no need anymore to distinguish between vfork
and fork, which removes any need for the macro.
To generate a diff of this commit:
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/make/compat.c
cvs rdiff -u -r1.410 -r1.411 src/usr.bin/make/job.c
cvs rdiff -u -r1.525 -r1.526 src/usr.bin/make/main.c
cvs rdiff -u -r1.247 -r1.248 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.220 src/usr.bin/make/compat.c:1.221
--- src/usr.bin/make/compat.c:1.220 Tue Jan 19 20:51:46 2021
+++ src/usr.bin/make/compat.c Mon Feb 1 21:04:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.220 2021/01/19 20:51:46 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.221 2021/02/01 21:04:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
#include "pathnames.h"
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.220 2021/01/19 20:51:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.221 2021/02/01 21:04:10 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
@@ -357,7 +357,7 @@ Compat_RunCommand(const char *cmdp, GNod
/*
* Fork and execute the single command. If the fork fails, we abort.
*/
- compatChild = cpid = vFork();
+ compatChild = 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.410 src/usr.bin/make/job.c:1.411
--- src/usr.bin/make/job.c:1.410 Mon Feb 1 18:55:15 2021
+++ src/usr.bin/make/job.c Mon Feb 1 21:04:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.410 2021/02/01 18:55:15 rillig Exp $ */
+/* $NetBSD: job.c,v 1.411 2021/02/01 21:04:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.410 2021/02/01 18:55:15 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.411 2021/02/01 21:04:10 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -1398,7 +1398,7 @@ JobExec(Job *job, char **argv)
Var_ReexportVars();
- 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.525 src/usr.bin/make/main.c:1.526
--- src/usr.bin/make/main.c:1.525 Mon Feb 1 20:01:26 2021
+++ src/usr.bin/make/main.c Mon Feb 1 21:04:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.525 2021/02/01 20:01:26 rillig Exp $ */
+/* $NetBSD: main.c,v 1.526 2021/02/01 21:04:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.525 2021/02/01 20:01:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.526 2021/02/01 21:04:10 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -1795,7 +1795,7 @@ Cmd_Exec(const char *cmd, const char **e
/*
* Fork
*/
- switch (cpid = vFork()) {
+ switch (cpid = vfork()) {
case 0:
(void)close(pipefds[0]); /* Close input side of pipe */
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.247 src/usr.bin/make/make.h:1.248
--- src/usr.bin/make/make.h:1.247 Mon Feb 1 20:51:17 2021
+++ src/usr.bin/make/make.h Mon Feb 1 21:04:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.247 2021/02/01 20:51:17 rillig Exp $ */
+/* $NetBSD: make.h,v 1.248 2021/02/01 21:04:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -532,18 +532,12 @@ extern SearchPath *defSysIncPath;
extern char curdir[];
/* The basename of the program name, suffixed with [n] for sub-makes. */
extern const char *progname;
+extern int makelevel;
/* Name of the .depend makefile */
extern char *makeDependfile;
/* If we replaced environ, this will be non-NULL. */
extern char **savedEnv;
-extern int makelevel;
-
-/*
- * 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"