summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/make/main.c266
1 files changed, 133 insertions, 133 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 6e0ac8c..850b64b 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -48,16 +48,17 @@ static char copyright[] =
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-/*-
- * main.c --
+/*
+ * main.c
* The main file for this entire program. Exit routines etc
* reside here.
*
* Utility functions defined in this file:
- * Main_ParseArgLine Takes a line of arguments, breaks them and
- * treats them as if they were given when first
- * invoked. Used by the parse module to implement
- * the .MFLAGS target.
+ * Main_ParseArgLine
+ * Takes a line of arguments, breaks them and
+ * treats them as if they were given when first
+ * invoked. Used by the parse module to implement
+ * the .MFLAGS target.
*/
#ifndef MACHINE
@@ -103,50 +104,51 @@ __FBSDID("$FreeBSD$");
/* Targets to be made */
Lst create = Lst_Initializer(create);
-time_t now; /* Time at start of make */
-struct GNode *DEFAULT; /* .DEFAULT node */
-Boolean allPrecious; /* .PRECIOUS given on line by itself */
+time_t now; /* Time at start of make */
+struct GNode *DEFAULT; /* .DEFAULT node */
+Boolean allPrecious; /* .PRECIOUS given on line by itself */
-static Boolean noBuiltins; /* -r flag */
+static Boolean noBuiltins; /* -r flag */
/* ordered list of makefiles to read */
static Lst makefiles = Lst_Initializer(makefiles);
-static Boolean expandVars; /* fully expand printed variables */
+static Boolean expandVars; /* fully expand printed variables */
/* list of variables to print */
static Lst variables = Lst_Initializer(variables);
-int maxJobs; /* -j argument */
-static Boolean forceJobs; /* -j argument given */
-Boolean compatMake; /* -B argument */
-Boolean debug; /* -d flag */
-Boolean noExecute; /* -n flag */
-Boolean keepgoing; /* -k flag */
-Boolean queryFlag; /* -q flag */
-Boolean touchFlag; /* -t flag */
-Boolean usePipes; /* !-P flag */
-Boolean ignoreErrors; /* -i flag */
-Boolean beSilent; /* -s flag */
-Boolean beVerbose; /* -v flag */
-Boolean oldVars; /* variable substitution style */
-Boolean checkEnvFirst; /* -e flag */
+int maxJobs; /* -j argument */
+static Boolean forceJobs; /* -j argument given */
+Boolean compatMake; /* -B argument */
+Boolean debug; /* -d flag */
+Boolean noExecute; /* -n flag */
+Boolean keepgoing; /* -k flag */
+Boolean queryFlag; /* -q flag */
+Boolean touchFlag; /* -t flag */
+Boolean usePipes; /* !-P flag */
+Boolean ignoreErrors; /* -i flag */
+Boolean beSilent; /* -s flag */
+Boolean beVerbose; /* -v flag */
+Boolean oldVars; /* variable substitution style */
+Boolean checkEnvFirst; /* -e flag */
/* (-E) vars to override from env */
Lst envFirstVars = Lst_Initializer(envFirstVars);
-Boolean jobsRunning; /* TRUE if the jobs might be running */
+Boolean jobsRunning; /* TRUE if the jobs might be running */
-static void MainParseArgs(int, char **);
-char *chdir_verify_path(const char *, char *);
-static int ReadMakefile(const char *);
-static void usage(void);
+static void MainParseArgs(int, char **);
+char *chdir_verify_path(const char *, char *);
+static int ReadMakefile(const char *);
+static void usage(void);
-static char *curdir; /* startup directory */
-static char *objdir; /* where we chdir'ed to */
+static char *curdir; /* startup directory */
+static char *objdir; /* where we chdir'ed to */
-/*
- * Append a flag with an optional argument to MAKEFLAGS and MFLAGS
+/**
+ * MFLAGS_append
+ * Append a flag with an optional argument to MAKEFLAGS and MFLAGS
*/
static void
MFLAGS_append(const char *flag, char *arg)
@@ -168,16 +170,13 @@ MFLAGS_append(const char *flag, char *arg)
}
}
-/*-
- * MainParseArgs --
+/**
+ * MainParseArgs
* Parse a given argument vector. Called from main() and from
* Main_ParseArgLine() when the .MAKEFLAGS target is used.
*
* XXX: Deal with command line overriding .MAKEFLAGS in makefile
*
- * Results:
- * None
- *
* Side Effects:
* Various global and local flags will be set depending on the flags
* given
@@ -277,7 +276,8 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
debug |= DEBUG_VAR;
break;
default:
- warnx("illegal argument to d option -- %c", *modules);
+ warnx("illegal argument to d option "
+ "-- %c", *modules);
usage();
}
MFLAGS_append("-d", optarg);
@@ -379,8 +379,8 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
}
}
-/*-
- * Main_ParseArgLine --
+/**
+ * Main_ParseArgLine
* Used by the parse module when a .MFLAGS or .MAKEFLAGS target
* is encountered and by main() when reading the .MAKEFLAGS envariable.
* Takes a line of arguments and breaks it into its
@@ -388,9 +388,6 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
* MainParseArgs function.
* The line should have all its leading whitespace removed.
*
- * Results:
- * None
- *
* Side Effects:
* Only those that come from the various arguments.
*/
@@ -450,9 +447,11 @@ check_make_level(void)
int level = (value == NULL) ? 0 : atoi(value);
if (level < 0) {
- errc(2, EAGAIN, "Invalid value for recursion level (%d).", level);
+ 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);
+ errc(2, EAGAIN, "Max recursion level (%d) exceeded.",
+ MKLVL_MAXVAL);
} else {
char new_value[32];
sprintf(new_value, "%d", level + 1);
@@ -461,8 +460,8 @@ check_make_level(void)
#endif /* WANT_ENV_MKLVL */
}
-/*-
- * main --
+/**
+ * main
* The main function, for obvious reasons. Initializes variables
* and a few modules, then parses the arguments give it in the
* environment and on the command line. Reads the system makefile
@@ -492,7 +491,7 @@ main(int argc, char **argv)
const char *machine_cpu = getenv("MACHINE_CPU");
char *cp = NULL, *start;
- /* avoid faults on read-only strings */
+ /* avoid faults on read-only strings */
static char syspath[] = PATH_DEFSYSPATH;
{
@@ -564,13 +563,13 @@ main(int argc, char **argv)
*/
if (!machine) {
#ifndef MACHINE
- static struct utsname utsname;
+ static struct utsname utsname;
- if (uname(&utsname) == -1)
- err(2, "uname");
- machine = utsname.machine;
+ if (uname(&utsname) == -1)
+ err(2, "uname");
+ machine = utsname.machine;
#else
- machine = MACHINE;
+ machine = MACHINE;
#endif
}
@@ -947,8 +946,8 @@ main(int argc, char **argv)
return (0);
}
-/*-
- * ReadMakefile --
+/**
+ * ReadMakefile
* Open and parse the given makefile.
*
* Results:
@@ -1039,8 +1038,8 @@ found:
return (TRUE);
}
-/*-
- * Cmd_Exec --
+/**
+ * Cmd_Exec
* Execute the command in cmd, and return the output of that command
* in a string.
*
@@ -1054,97 +1053,98 @@ found:
Buffer *
Cmd_Exec(char *cmd, const char **error)
{
- int fds[2]; /* Pipe streams */
- int cpid; /* Child PID */
- int pid; /* PID from wait() */
- int status; /* command exit status */
- Buffer *buf; /* buffer to store the result */
- ssize_t rcnt;
-
- *error = NULL;
- buf = Buf_Init(0);
-
- if (shellPath == NULL)
- Shell_Init();
- /*
- * Open a pipe for fetching its output
- */
- if (pipe(fds) == -1) {
- *error = "Couldn't create pipe for \"%s\"";
- return (buf);
- }
-
- /*
- * Fork
- */
- switch (cpid = vfork()) {
- case 0:
+ int fds[2]; /* Pipe streams */
+ int cpid; /* Child PID */
+ int pid; /* PID from wait() */
+ int status; /* command exit status */
+ Buffer *buf; /* buffer to store the result */
+ ssize_t rcnt;
+
+ *error = NULL;
+ buf = Buf_Init(0);
+
+ if (shellPath == NULL)
+ Shell_Init();
/*
- * Close input side of pipe
+ * Open a pipe for fetching its output
*/
- close(fds[0]);
+ if (pipe(fds) == -1) {
+ *error = "Couldn't create pipe for \"%s\"";
+ return (buf);
+ }
/*
- * Duplicate the output stream to the shell's output, then
- * shut the extra thing down. Note we don't fetch the error
- * stream...why not? Why?
+ * Fork
*/
- dup2(fds[1], 1);
- close(fds[1]);
+ switch (cpid = vfork()) {
+ case 0:
+ /*
+ * Close input side of pipe
+ */
+ close(fds[0]);
- {
- char *args[4];
+ /*
+ * Duplicate the output stream to the shell's output, then
+ * shut the extra thing down. Note we don't fetch the error
+ * stream...why not? Why?
+ */
+ dup2(fds[1], 1);
+ close(fds[1]);
- /* Set up arguments for shell */
- args[0] = shellName;
- args[1] = "-c";
- args[2] = cmd;
- args[3] = NULL;
+ {
+ char *args[4];
- execv(shellPath, args);
- _exit(1);
- /*NOTREACHED*/
- }
+ /* Set up arguments for shell */
+ args[0] = shellName;
+ args[1] = "-c";
+ args[2] = cmd;
+ args[3] = NULL;
- case -1:
- *error = "Couldn't exec \"%s\"";
- return (buf);
+ execv(shellPath, args);
+ _exit(1);
+ /*NOTREACHED*/
+ }
- default:
- /*
- * No need for the writing half
- */
- close(fds[1]);
+ case -1:
+ *error = "Couldn't exec \"%s\"";
+ return (buf);
- do {
- char result[BUFSIZ];
- rcnt = read(fds[0], result, sizeof(result));
- if (rcnt != -1)
- Buf_AddBytes(buf, (size_t)rcnt, (Byte *)result);
- } while (rcnt > 0 || (rcnt == -1 && errno == EINTR));
+ default:
+ /*
+ * No need for the writing half
+ */
+ close(fds[1]);
- if (rcnt == -1)
- *error = "Error reading shell's output for \"%s\"";
+ do {
+ char result[BUFSIZ];
- /*
- * Close the input side of the pipe.
- */
- close(fds[0]);
+ rcnt = read(fds[0], result, sizeof(result));
+ if (rcnt != -1)
+ Buf_AddBytes(buf, (size_t)rcnt, (Byte *)result);
+ } while (rcnt > 0 || (rcnt == -1 && errno == EINTR));
- /*
- * Wait for the process to exit.
- */
- while (((pid = wait(&status)) != cpid) && (pid >= 0))
- continue;
+ if (rcnt == -1)
+ *error = "Error reading shell's output for \"%s\"";
+
+ /*
+ * Close the input side of the pipe.
+ */
+ close(fds[0]);
- if (status)
- *error = "\"%s\" returned non-zero status";
+ /*
+ * Wait for the process to exit.
+ */
+ while (((pid = wait(&status)) != cpid) && (pid >= 0))
+ continue;
+
+ if (status)
+ *error = "\"%s\" returned non-zero status";
- Buf_StripNewlines(buf);
+ Buf_StripNewlines(buf);
- break;
- }
- return (buf);
+ break;
+ }
+ return (buf);
}
/*
OpenPOWER on IntegriCloud