summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2002-10-03 04:32:47 +0000
committerjmallett <jmallett@FreeBSD.org>2002-10-03 04:32:47 +0000
commitcea0ea5b91ba3c35928089c6b4b279f60ab99c94 (patch)
tree699248aab8226c738e764858c07dd30ddab43f23 /usr.bin
parent2eba9107fd1321295aebc7fea9f4546656156488 (diff)
downloadFreeBSD-src-cea0ea5b91ba3c35928089c6b4b279f60ab99c94.zip
FreeBSD-src-cea0ea5b91ba3c35928089c6b4b279f60ab99c94.tar.gz
In lieu of a good way to prevent every possible looping in make(1), stop
there from being more than 500 processes forked by make(1), to prevent a forkbomb from happening, in a dumb and mechanical way. PR: alane Submitted by: bin/42772 MFC after: 2 weeks
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/make/main.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 846c8ca..3002ef0 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -102,6 +102,8 @@ __FBSDID("$FreeBSD$");
#include "job.h"
#include "pathnames.h"
+#define WANT_ENV_MKLVL 1
+
#ifndef DEFMAXLOCAL
#define DEFMAXLOCAL DEFMAXJOBS
#endif /* DEFMAXLOCAL */
@@ -454,6 +456,12 @@ main(argc, argv)
Boolean outOfDate = TRUE; /* FALSE if all targets up to date */
struct stat sa;
char *p, *p1, *path, *pathp;
+#ifdef WANT_ENV_MKLVL
+#define MKLVL_MAXVAL 500
+#define MKLVL_ENVVAR "__MKLVL__"
+ int iMkLvl = 0;
+ char *szMkLvl = getenv(MKLVL_ENVVAR);
+#endif /* WANT_ENV_MKLVL */
char mdpath[MAXPATHLEN];
char obpath[MAXPATHLEN];
char cdpath[MAXPATHLEN];
@@ -465,6 +473,19 @@ main(argc, argv)
/* avoid faults on read-only strings */
static char syspath[] = _PATH_DEFSYSPATH;
+#ifdef WANT_ENV_MKLVL
+ if ((iMkLvl = szMkLvl ? atoi(szMkLvl) : 0) < 0) {
+ iMkLvl = 0;
+ }
+ if (iMkLvl++ > MKLVL_MAXVAL) {
+ errc(2, EAGAIN,
+ "Max recursion level (%d) exceeded.", MKLVL_MAXVAL);
+ }
+ bzero(szMkLvl = emalloc(32), 32);
+ sprintf(szMkLvl, "%d", iMkLvl);
+ setenv(MKLVL_ENVVAR, szMkLvl, 1);
+#endif /* WANT_ENV_MKLVL */
+
#if DEFSHELL == 2
/*
* Turn off ENV to make ksh happier.
OpenPOWER on IntegriCloud