DragonFly BSD
DragonFly submit List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

usr.bin/make Cleanup make recursion limiting code


From: Max Okumoto <okumoto@xxxxxxxx>
Date: Thu, 25 Nov 2004 05:18:35 -0800

PatchSet 376
Date: 2004/11/24 22:03:45
Author: jmallett
Log:

Gentle code cleanup for the maximum make(1) level foo. This moves
it to a function, and moves the related defines out of the middle of code body.


Submitted by: Max Okumoto less-than okumoto at ucsd dot edu greater-than

Members:
        main.c:1.98->1.99
---------------------
PatchSet 376
Date: 2004/11/24 22:03:45
Author: jmallett
Log:
Gentle code cleanup for the maximum make(1) level foo.  This moves it to a
function, and moves the related defines out of the middle of code body.

Submitted by:	Max Okumoto less-than okumoto at ucsd dot edu greater-than

Members: 
	main.c:1.98->1.99 

Index: main.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/main.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- main.c	17 Nov 2004 11:32:46 -0000	1.98
+++ main.c	24 Nov 2004 22:03:45 -0000	1.99
@@ -90,6 +90,8 @@
 #include "pathnames.h"
 
 #define WANT_ENV_MKLVL	1
+#define	MKLVL_MAXVAL	500
+#define	MKLVL_ENVVAR	"__MKLVL__"
 
 #define	MAKEFLAGS	".MAKEFLAGS"
 
@@ -404,4 +406,28 @@
+/*
+ * In lieu of a good way to prevent every possible looping in
+ * make(1), stop there from being more than MKLVL_MAXVAL processes forked
+ * by make(1), to prevent a forkbomb from happening, in a dumb and
+ * mechanical way.
+ */
+static void
+check_make_level(void)
+{
+#ifdef WANT_ENV_MKLVL
+	char	*value = getenv(MKLVL_ENVVAR);
+	int	level = (value == NULL) ? 0 : atoi(value);
+
+	if (level < 0) {
+		errc(2, EAGAIN, "Invalid value for recursion level (%d).", level);
+	} else if (level > MKLVL_MAXVAL) {
+		errc(2, EAGAIN, "Max recursion level (%d) exceeded.", MKLVL_MAXVAL);
+	} else {
+		char new_value[32];
+		sprintf(new_value, "%d", level + 1);
+		setenv(MKLVL_ENVVAR, new_value, 1);
+	}
+#endif /* WANT_ENV_MKLVL */
+}
 
 /*-
  * main --
  *	The main function, for obvious reasons. Initializes variables
@@ -428,12 +455,6 @@
 	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];
@@ -461,13 +482,0 @@
-#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 */
-
@@ -461,3 +482,6 @@
 	sigaction(SIGCHLD, &sa, NULL);
 	}
 
+	check_make_level();
+
+


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