Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make: always use vfork, never fork



details:   https://anonhg.NetBSD.org/src/rev/0c110f025823
branches:  trunk
changeset: 950843:0c110f025823
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 01 21:04:10 2021 +0000

description:
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.

diffstat:

 usr.bin/make/compat.c |   6 +++---
 usr.bin/make/job.c    |   6 +++---
 usr.bin/make/main.c   |   6 +++---
 usr.bin/make/make.h   |  10 ++--------
 4 files changed, 11 insertions(+), 17 deletions(-)

diffs (110 lines):

diff -r 73995e961ee1 -r 0c110f025823 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Mon Feb 01 20:51:17 2021 +0000
+++ b/usr.bin/make/compat.c     Mon Feb 01 21:04:10 2021 +0000
@@ -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 @@
        /*
         * 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");
        }
diff -r 73995e961ee1 -r 0c110f025823 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Mon Feb 01 20:51:17 2021 +0000
+++ b/usr.bin/make/job.c        Mon Feb 01 21:04:10 2021 +0000
@@ -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 @@
 
        Var_ReexportVars();
 
-       cpid = vFork();
+       cpid = vfork();
        if (cpid == -1)
                Punt("Cannot vfork: %s", strerror(errno));
 
diff -r 73995e961ee1 -r 0c110f025823 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Mon Feb 01 20:51:17 2021 +0000
+++ b/usr.bin/make/main.c       Mon Feb 01 21:04:10 2021 +0000
@@ -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 @@
        /*
         * Fork
         */
-       switch (cpid = vFork()) {
+       switch (cpid = vfork()) {
        case 0:
                (void)close(pipefds[0]); /* Close input side of pipe */
 
diff -r 73995e961ee1 -r 0c110f025823 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Mon Feb 01 20:51:17 2021 +0000
+++ b/usr.bin/make/make.h       Mon Feb 01 21:04:10 2021 +0000
@@ -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 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"



Home | Main Index | Thread Index | Old Index