summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-05-12 14:43:32 +0000
committerharti <harti@FreeBSD.org>2005-05-12 14:43:32 +0000
commitdfdc1e0f672d6108333eb0feb0440d6386fa092b (patch)
tree333a37dae1e63e44336b219fdceb7cb3b67946f7 /usr.bin/make
parent00f50de80b1cf3480968e312fb7c6a2de7e02434 (diff)
downloadFreeBSD-src-dfdc1e0f672d6108333eb0feb0440d6386fa092b.zip
FreeBSD-src-dfdc1e0f672d6108333eb0feb0440d6386fa092b.tar.gz
Cleanup main(). Move catching SIGCHLD into job.c. Move unsetenv("ENV")
into job.c. Move retrieving of environment nearer to the place where it is actually used and invert the preprocessor conditionals to use positive logic. Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.236)
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/job.c32
-rw-r--r--usr.bin/make/job.h2
-rw-r--r--usr.bin/make/main.c82
3 files changed, 63 insertions, 53 deletions
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index 3e6c482..8b83d33 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -522,6 +522,38 @@ static const char *sh_meta = "#=|^(){};&<>*?[]:$`\\\n";
static GNode *curTarg = NULL;
static GNode *ENDNode;
+static void
+catch_child(int sig __unused)
+{
+}
+
+/**
+ */
+void
+Proc_Init()
+{
+ /*
+ * Catch SIGCHLD so that we get kicked out of select() when we
+ * need to look at a child. This is only known to matter for the
+ * -j case (perhaps without -P).
+ *
+ * XXX this is intentionally misplaced.
+ */
+ struct sigaction sa;
+
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
+ sa.sa_handler = catch_child;
+ sigaction(SIGCHLD, &sa, NULL);
+
+#if DEFSHELL == 2
+ /*
+ * Turn off ENV to make ksh happier.
+ */
+ unsetenv("ENV");
+#endif
+}
+
/**
* Replace the current process.
*/
diff --git a/usr.bin/make/job.h b/usr.bin/make/job.h
index fab68d8..0c85c01 100644
--- a/usr.bin/make/job.h
+++ b/usr.bin/make/job.h
@@ -70,6 +70,8 @@ int Job_Finish(void);
void Job_Wait(void);
void Job_AbortAll(void);
+void Proc_Init(void);
+
struct Buffer *Cmd_Exec(const char *, const char **);
void Compat_Run(struct Lst *);
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index cb04589..741c2f3 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -73,7 +73,6 @@ __FBSDID("$FreeBSD$");
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
-#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -617,16 +616,13 @@ chdir_verify_path(const char *path, char *obpath)
return (NULL);
}
-static void
-catch_child(int sig __unused)
-{
-}
-
-/*
- * 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.
+/**
+ * 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.
+ *
+ * Side Effects:
+ * Creates or modifies enviornment variable MKLVL_ENVVAR via setenv().
*/
static void
check_make_level(void)
@@ -669,55 +665,31 @@ check_make_level(void)
int
main(int argc, char **argv)
{
+ const char *machine;
+ const char *machine_arch;
+ const char *machine_cpu;
Boolean outOfDate = TRUE; /* FALSE if all targets up to date */
char *p, *p1, *pathp;
char *path;
char mdpath[MAXPATHLEN];
char obpath[MAXPATHLEN];
char cdpath[MAXPATHLEN];
- const char *machine = getenv("MACHINE");
- const char *machine_arch = getenv("MACHINE_ARCH");
- const char *machine_cpu = getenv("MACHINE_CPU");
char *cp = NULL, *start;
- /* avoid faults on read-only strings */
- static char syspath[] = PATH_DEFSYSPATH;
-
- {
- /*
- * Catch SIGCHLD so that we get kicked out of select() when we
- * need to look at a child. This is only known to matter for the
- * -j case (perhaps without -P).
- *
- * XXX this is intentionally misplaced.
- */
- struct sigaction sa;
-
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
- sa.sa_handler = catch_child;
- sigaction(SIGCHLD, &sa, NULL);
- }
-
check_make_level();
-#if DEFSHELL == 2
- /*
- * Turn off ENV to make ksh happier.
- */
- unsetenv("ENV");
-#endif
-
#ifdef RLIMIT_NOFILE
/*
* get rid of resource limit on file descriptors
*/
{
struct rlimit rl;
- if (getrlimit(RLIMIT_NOFILE, &rl) != -1 &&
- rl.rlim_cur != rl.rlim_max) {
- rl.rlim_cur = rl.rlim_max;
- setrlimit(RLIMIT_NOFILE, &rl);
+ if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
+ err(2, "getrlimit");
+ }
+ rl.rlim_cur = rl.rlim_max;
+ if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
+ err(2, "setrlimit");
}
}
#endif
@@ -750,23 +722,23 @@ main(int argc, char **argv)
* Note that while MACHINE is decided at run-time,
* MACHINE_ARCH is always known at compile time.
*/
- if (!machine) {
-#ifndef MACHINE
+ if ((machine = getenv("MACHINE")) == NULL) {
+#ifdef MACHINE
+ machine = MACHINE;
+#else
static struct utsname utsname;
if (uname(&utsname) == -1)
err(2, "uname");
machine = utsname.machine;
-#else
- machine = MACHINE;
#endif
}
- if (!machine_arch) {
-#ifndef MACHINE_ARCH
- machine_arch = "unknown";
-#else
+ if ((machine_arch = getenv("MACHINE_ARCH")) == NULL) {
+#ifdef MACHINE_ARCH
machine_arch = MACHINE_ARCH;
+#else
+ machine_arch = "unknown";
#endif
}
@@ -774,7 +746,7 @@ main(int argc, char **argv)
* Set machine_cpu to the minumum supported CPU revision based
* on the target architecture, if not already set.
*/
- if (!machine_cpu) {
+ if ((machine_cpu = getenv("MACHINE_CPU")) == NULL) {
if (!strcmp(machine_arch, "i386"))
machine_cpu = "i386";
else if (!strcmp(machine_arch, "alpha"))
@@ -805,6 +777,8 @@ main(int argc, char **argv)
* for the reading of inclusion paths and variable settings on the
* command line
*/
+ Proc_Init();
+
Dir_Init(); /* Initialize directory structures so -I flags
* can be processed correctly */
Var_Init(environ); /* As well as the lists of variables for
@@ -939,6 +913,8 @@ main(int argc, char **argv)
* as dir1:...:dirn) to the system include path.
*/
if (TAILQ_EMPTY(&sysIncPath)) {
+ char syspath[] = PATH_DEFSYSPATH;
+
for (start = syspath; *start != '\0'; start = cp) {
for (cp = start; *cp != '\0' && *cp != ':'; cp++)
continue;
OpenPOWER on IntegriCloud