aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/job.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/job.c')
-rw-r--r--contrib/bmake/job.c320
1 files changed, 144 insertions, 176 deletions
diff --git a/contrib/bmake/job.c b/contrib/bmake/job.c
index e4b77477e816..4cce19e89f87 100644
--- a/contrib/bmake/job.c
+++ b/contrib/bmake/job.c
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.435 2021/06/16 09:47:51 rillig Exp $ */
+/* $NetBSD: job.c,v 1.467 2024/03/10 02:53:37 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,12 +70,11 @@
*/
/*
- * job.c --
- * handle the creation etc. of our child processes.
+ * Create child processes and collect their output.
*
* Interface:
* Job_Init Called to initialize this module. In addition,
- * the .BEGIN target is made including all of its
+ * the .BEGIN target is made, including all of its
* dependencies before this function returns.
* Hence, the makefiles must have been parsed
* before this function is called.
@@ -155,7 +154,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.435 2021/06/16 09:47:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.467 2024/03/10 02:53:37 sjg Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -214,13 +213,15 @@ typedef struct Shell {
const char *errOff; /* command to turn off error checking */
const char *echoTmpl; /* template to echo a command */
- const char *runIgnTmpl; /* template to run a command
- * without error checking */
- const char *runChkTmpl; /* template to run a command
- * with error checking */
+ const char *runIgnTmpl; /* template to run a command without error
+ * checking */
+ const char *runChkTmpl; /* template to run a command with error
+ * checking */
- /* string literal that results in a newline character when it appears
- * outside of any 'quote' or "quote" characters */
+ /*
+ * A string literal that results in a newline character when it
+ * occurs outside of any 'quote' or "quote" characters.
+ */
const char *newline;
char commentChar; /* character used by shell for comment lines */
@@ -272,9 +273,7 @@ static bool Always_pass_job_queue = true;
#define MAKE_JOB_ERROR_TOKEN "${MAKE_JOB_ERROR_TOKEN:U}"
static bool Job_error_token = true;
-/*
- * error handling variables
- */
+/* error handling variables */
static int job_errors = 0; /* number of errors reported */
static enum { /* Why is the make aborting? */
ABORT_NONE,
@@ -284,9 +283,7 @@ static enum { /* Why is the make aborting? */
} aborting = ABORT_NONE;
#define JOB_TOKENS "+EI+" /* Token to requeue for each abort state */
-/*
- * this tracks the number of tokens currently "out" to build jobs.
- */
+/* Tracks the number of tokens currently "out" to build jobs. */
int jobTokensRunning = 0;
typedef enum JobStartResult {
@@ -315,15 +312,15 @@ typedef enum JobStartResult {
#define DEFSHELL_INDEX_SH 1
#define DEFSHELL_INDEX_KSH 2
#define DEFSHELL_INDEX_CSH 3
-#else /* !DEFSHELL_CUSTOM */
+#else
#define DEFSHELL_INDEX_SH 0
#define DEFSHELL_INDEX_KSH 1
#define DEFSHELL_INDEX_CSH 2
-#endif /* !DEFSHELL_CUSTOM */
+#endif
#ifndef DEFSHELL_INDEX
#define DEFSHELL_INDEX 0 /* DEFSHELL_INDEX_CUSTOM or DEFSHELL_INDEX_SH */
-#endif /* !DEFSHELL_INDEX */
+#endif
static Shell shells[] = {
#ifdef DEFSHELL_CUSTOM
@@ -439,7 +436,7 @@ static char *shell_freeIt = NULL; /* Allocated memory for custom .SHELL */
static Job *job_table; /* The structures that describe them */
static Job *job_table_end; /* job_table + maxJobs */
-static unsigned int wantToken; /* we want a token */
+static unsigned int wantToken;
static bool lurking_children = false;
static bool make_suspended = false; /* Whether we've seen a SIGTSTP (etc) */
@@ -454,7 +451,7 @@ static void watchfd(Job *);
static void clearfd(Job *);
static bool readyfd(Job *);
-static char *targPrefix = NULL; /* To identify a job change in the output. */
+static char *targPrefix = NULL; /* To identify a job change in the output. */
static Job tokenWaitJob; /* token wait pseudo-job */
static Job childExitJob; /* child exit pseudo-job */
@@ -533,13 +530,13 @@ JobDeleteTarget(GNode *gn)
return;
if (gn->type & OP_PHONY)
return;
- if (Targ_Precious(gn))
+ if (GNode_IsPrecious(gn))
return;
if (opts.noExecute)
return;
file = GNode_Path(gn);
- if (eunlink(file) != -1)
+ if (unlink_file(file) == 0)
Error("*** %s removed", file);
}
@@ -574,7 +571,7 @@ JobCreatePipe(Job *job, int minfd)
Punt("Cannot create pipe: %s", strerror(errno));
for (i = 0; i < 2; i++) {
- /* Avoid using low numbered fds */
+ /* Avoid using low-numbered fds */
fd = fcntl(pipe_fds[i], F_DUPFD, minfd);
if (fd != -1) {
close(pipe_fds[i]);
@@ -585,7 +582,6 @@ JobCreatePipe(Job *job, int minfd)
job->inPipe = pipe_fds[0];
job->outPipe = pipe_fds[1];
- /* Set close-on-exec flag for both */
if (fcntl(job->inPipe, F_SETFD, FD_CLOEXEC) == -1)
Punt("Cannot set close-on-exec: %s", strerror(errno));
if (fcntl(job->outPipe, F_SETFD, FD_CLOEXEC) == -1)
@@ -708,10 +704,10 @@ JobPassSig_suspend(int signo)
/*
* We've been continued.
*
- * A whole host of signals continue to happen!
+ * A whole host of signals is going to happen!
* SIGCHLD for any processes that actually suspended themselves.
- * SIGCHLD for any processes that exited while we were alseep.
- * The SIGCONT that actually caused us to wakeup.
+ * SIGCHLD for any processes that exited while we were asleep.
+ * The SIGCONT that actually caused us to wake up.
*
* Since we defer passing the SIGCONT on to our children until
* the main processing loop, we can be sure that all the SIGCHLD
@@ -759,7 +755,8 @@ ParseCommandFlags(char **pp, CommandFlags *out_cmdFlags)
out_cmdFlags->ignerr = true;
else if (*p == '+')
out_cmdFlags->always = true;
- else
+ else if (!ch_isspace(*p))
+ /* Ignore whitespace for compatibility with GNU make */
break;
p++;
}
@@ -794,8 +791,8 @@ ShellWriter_WriteFmt(ShellWriter *wr, const char *fmt, const char *arg)
DEBUG1(JOB, fmt, arg);
(void)fprintf(wr->f, fmt, arg);
- /* XXX: Is flushing needed in any case, or only if f == stdout? */
- (void)fflush(wr->f);
+ if (wr->f == stdout)
+ (void)fflush(wr->f);
}
static void
@@ -862,7 +859,7 @@ static void
JobWriteSpecialsEchoCtl(Job *job, ShellWriter *wr, CommandFlags *inout_cmdFlags,
const char *escCmd, const char **inout_cmdTemplate)
{
- /* XXX: Why is the job modified at this point? */
+ /* XXX: Why is the whole job modified at this point? */
job->ignerr = true;
if (job->echo && inout_cmdFlags->echo) {
@@ -874,9 +871,6 @@ JobWriteSpecialsEchoCtl(Job *job, ShellWriter *wr, CommandFlags *inout_cmdFlags,
* for toggling the error checking.
*/
inout_cmdFlags->echo = false;
- } else {
- if (inout_cmdFlags->echo)
- ShellWriter_EchoCmd(wr, escCmd);
}
*inout_cmdTemplate = shell->runIgnTmpl;
@@ -892,13 +886,9 @@ static void
JobWriteSpecials(Job *job, ShellWriter *wr, const char *escCmd, bool run,
CommandFlags *inout_cmdFlags, const char **inout_cmdTemplate)
{
- if (!run) {
- /*
- * If there is no command to run, there is no need to switch
- * error checking off and on again for nothing.
- */
+ if (!run)
inout_cmdFlags->ignerr = false;
- } else if (shell->hasErrCtl)
+ else if (shell->hasErrCtl)
ShellWriter_ErrOff(wr, job->echo && inout_cmdFlags->echo);
else if (shell->runIgnTmpl != NULL && shell->runIgnTmpl[0] != '\0') {
JobWriteSpecialsEchoCtl(job, wr, inout_cmdFlags, escCmd,
@@ -940,7 +930,7 @@ JobWriteCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
run = GNode_ShouldExecute(job->node);
- Var_Subst(ucmd, job->node, VARE_WANTRES, &xcmd);
+ xcmd = Var_Subst(ucmd, job->node, VARE_WANTRES);
/* TODO: handle errors */
xcmdStart = xcmd;
@@ -954,7 +944,7 @@ JobWriteCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
* We're not actually executing anything...
* but this one needs to be - use compat mode just for it.
*/
- Compat_RunCommand(ucmd, job->node, ln);
+ (void)Compat_RunCommand(ucmd, job->node, ln);
free(xcmdStart);
return;
}
@@ -967,12 +957,10 @@ JobWriteCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
escCmd = shell->hasErrCtl ? NULL : EscapeShellDblQuot(xcmd);
if (!cmdFlags.echo) {
- if (job->echo && run && shell->hasEchoCtl) {
+ if (job->echo && run && shell->hasEchoCtl)
ShellWriter_EchoOff(wr);
- } else {
- if (shell->hasErrCtl)
- cmdFlags.echo = true;
- }
+ else if (shell->hasErrCtl)
+ cmdFlags.echo = true;
}
if (cmdFlags.ignerr) {
@@ -1069,7 +1057,7 @@ JobSaveCommands(Job *job)
* variables such as .TARGET, .IMPSRC. It is not intended to
* expand the other variables as well; see deptgt-end.mk.
*/
- (void)Var_Subst(cmd, job->node, VARE_WANTRES, &expanded_cmd);
+ expanded_cmd = Var_Subst(cmd, job->node, VARE_WANTRES);
/* TODO: handle errors */
Lst_Append(&Targ_GetEndNode()->commands, expanded_cmd);
}
@@ -1097,10 +1085,19 @@ DebugFailedJob(const Job *job)
if (!DEBUG(ERROR))
return;
- debug_printf("\n*** Failed target: %s\n*** Failed commands:\n",
- job->node->name);
- for (ln = job->node->commands.first; ln != NULL; ln = ln->next)
- debug_printf("\t%s\n", (const char *)ln->datum);
+ debug_printf("\n");
+ debug_printf("*** Failed target: %s\n", job->node->name);
+ debug_printf("*** Failed commands:\n");
+ for (ln = job->node->commands.first; ln != NULL; ln = ln->next) {
+ const char *cmd = ln->datum;
+ debug_printf("\t%s\n", cmd);
+
+ if (strchr(cmd, '$') != NULL) {
+ char *xcmd = Var_Subst(cmd, job->node, VARE_WANTRES);
+ debug_printf("\t=> %s\n", xcmd);
+ free(xcmd);
+ }
+ }
}
static void
@@ -1125,7 +1122,7 @@ JobFinishDoneExitedError(Job *job, WAIT_T *inout_status)
else {
if (deleteOnError)
JobDeleteTarget(job->node);
- PrintOnError(job->node, NULL);
+ PrintOnError(job->node, "\n");
}
}
@@ -1192,7 +1189,9 @@ JobFinish (Job *job, WAIT_T status)
JobClosePipes(job);
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
- (void)fclose(job->cmdFILE);
+ if (fclose(job->cmdFILE) != 0)
+ Punt("Cannot write shell script for '%s': %s",
+ job->node->name, strerror(errno));
job->cmdFILE = NULL;
}
done = true;
@@ -1283,9 +1282,11 @@ TouchRegular(GNode *gn)
return; /* XXX: What about propagating the error? */
}
- /* Last resort: update the file's time stamps in the traditional way.
+ /*
+ * Last resort: update the file's time stamps in the traditional way.
* XXX: This doesn't work for empty files, which are sometimes used
- * as marker files. */
+ * as marker files.
+ */
if (read(fd, &c, 1) == 1) {
(void)lseek(fd, 0, SEEK_SET);
while (write(fd, &c, 1) == -1 && errno == EAGAIN)
@@ -1384,10 +1385,10 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
* this node's parents so they never get examined.
*/
- if (gn->flags & FROM_DEPEND) {
+ if (gn->flags.fromDepend) {
if (!Job_RunTarget(".STALE", gn->fname))
fprintf(stdout,
- "%s: %s, %d: ignoring stale %s for %s\n",
+ "%s: %s, %u: ignoring stale %s for %s\n",
progname, gn->fname, gn->lineno, makeDependfile,
gn->name);
return true;
@@ -1407,7 +1408,7 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
return false;
}
- abortProc("%s: don't know how to make %s. Stop", progname, gn->name);
+ abortProc("don't know how to make %s. Stop", gn->name);
return false;
}
@@ -1434,7 +1435,7 @@ JobExec(Job *job, char **argv)
}
/*
- * Some jobs produce no output and it's disconcerting to have
+ * Some jobs produce no output, and it's disconcerting to have
* no feedback of their running (since they produce no output, the
* banner with their name in it never appears). This is an attempt to
* provide that feedback, even if nothing follows it.
@@ -1448,7 +1449,7 @@ JobExec(Job *job, char **argv)
/* Pre-emptively mark job running, pid still zero though */
job->status = JOB_ST_RUNNING;
- Var_ReexportVars();
+ Var_ReexportVars(job->node);
cpid = vfork();
if (cpid == -1)
@@ -1459,9 +1460,8 @@ JobExec(Job *job, char **argv)
sigset_t tmask;
#ifdef USE_META
- if (useMeta) {
+ if (useMeta)
meta_job_child(job);
- }
#endif
/*
* Reset all signal handlers; this is necessary because we
@@ -1488,9 +1488,7 @@ JobExec(Job *job, char **argv)
if (Always_pass_job_queue ||
(job->node->type & (OP_MAKE | OP_SUBMAKE))) {
- /*
- * Pass job token pipe to submakes.
- */
+ /* Pass job token pipe to submakes. */
if (fcntl(tokenWaitJob.inPipe, F_SETFD, 0) == -1)
execDie("clear close-on-exec",
"tokenWaitJob.inPipe");
@@ -1544,9 +1542,8 @@ JobExec(Job *job, char **argv)
Trace_Log(JOBSTART, job);
#ifdef USE_META
- if (useMeta) {
+ if (useMeta)
meta_job_parent(job, cpid);
- }
#endif
/*
@@ -1558,7 +1555,9 @@ JobExec(Job *job, char **argv)
watchfd(job);
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
- (void)fclose(job->cmdFILE);
+ if (fclose(job->cmdFILE) != 0)
+ Punt("Cannot write shell script for '%s': %s",
+ job->node->name, strerror(errno));
job->cmdFILE = NULL;
}
@@ -1638,7 +1637,7 @@ JobWriteShellCommands(Job *job, GNode *gn, bool *out_run)
#ifdef USE_META
if (useMeta) {
meta_job_start(job, gn);
- if (gn->type & OP_SILENT) /* might have changed */
+ if (gn->type & OP_SILENT) /* might have changed */
job->echo = false;
}
#endif
@@ -1682,7 +1681,7 @@ JobStart(GNode *gn, bool special)
job->special = special || gn->type & OP_SPECIAL;
job->ignerr = opts.ignoreErrors || gn->type & OP_IGNORE;
- job->echo = !(opts.beSilent || gn->type & OP_SILENT);
+ job->echo = !(opts.silent || gn->type & OP_SILENT);
/*
* Check the commands now so any attributes from .DEFAULT have a
@@ -1701,11 +1700,11 @@ JobStart(GNode *gn, bool special)
* also dead...
*/
if (!cmdsOK) {
- PrintOnError(gn, NULL); /* provide some clue */
+ PrintOnError(gn, "\n"); /* provide some clue */
DieHorribly();
}
} else if (((gn->type & OP_MAKE) && !opts.noRecursiveExecute) ||
- (!opts.noExecute && !opts.touchFlag)) {
+ (!opts.noExecute && !opts.touch)) {
/*
* The above condition looks very similar to
* GNode_ShouldExecute but is subtly different. It prevents
@@ -1718,7 +1717,7 @@ JobStart(GNode *gn, bool special)
* also dead...
*/
if (!cmdsOK) {
- PrintOnError(gn, NULL); /* provide some clue */
+ PrintOnError(gn, "\n"); /* provide some clue */
DieHorribly();
}
@@ -1785,12 +1784,12 @@ JobStart(GNode *gn, bool special)
* itself.
*/
static char *
-PrintFilteredOutput(char *cp, char *endp) /* XXX: should all be const */
+PrintFilteredOutput(char *p, char *endp) /* XXX: should all be const */
{
- char *ecp; /* XXX: should be const */
+ char *ep; /* XXX: should be const */
if (shell->noPrint == NULL || shell->noPrint[0] == '\0')
- return cp;
+ return p;
/*
* XXX: What happens if shell->noPrint occurs on the boundary of
@@ -1798,9 +1797,9 @@ PrintFilteredOutput(char *cp, char *endp) /* XXX: should all be const */
* be a proper stream filter instead of doing string matching on
* selected chunks of the output.
*/
- while ((ecp = strstr(cp, shell->noPrint)) != NULL) {
- if (ecp != cp) {
- *ecp = '\0'; /* XXX: avoid writing to the buffer */
+ while ((ep = strstr(p, shell->noPrint)) != NULL) {
+ if (ep != p) {
+ *ep = '\0'; /* XXX: avoid writing to the buffer */
/*
* The only way there wouldn't be a newline after
* this line is if it were the last in the buffer.
@@ -1808,16 +1807,16 @@ PrintFilteredOutput(char *cp, char *endp) /* XXX: should all be const */
* there must be a newline, so we don't print one.
*/
/* XXX: What about null bytes in the output? */
- (void)fprintf(stdout, "%s", cp);
+ (void)fprintf(stdout, "%s", p);
(void)fflush(stdout);
}
- cp = ecp + shell->noPrintLen;
- if (cp == endp)
+ p = ep + shell->noPrintLen;
+ if (p == endp)
break;
- cp++; /* skip over the (XXX: assumed) newline */
- pp_skip_whitespace(&cp);
+ p++; /* skip over the (XXX: assumed) newline */
+ pp_skip_whitespace(&p);
}
- return cp;
+ return p;
}
/*
@@ -1855,46 +1854,36 @@ again:
if (nRead < 0) {
if (errno == EAGAIN)
return;
- if (DEBUG(JOB)) {
+ if (DEBUG(JOB))
perror("CollectOutput(piperead)");
- }
nr = 0;
- } else {
+ } else
nr = (size_t)nRead;
- }
+
+ if (nr == 0)
+ finish = false; /* stop looping */
/*
* If we hit the end-of-file (the job is dead), we must flush its
* remaining output, so pretend we read a newline if there's any
* output remaining in the buffer.
- * Also clear the 'finish' flag so we stop looping.
*/
if (nr == 0 && job->curPos != 0) {
job->outBuf[job->curPos] = '\n';
nr = 1;
- finish = false;
- } else if (nr == 0) {
- finish = false;
}
- /*
- * Look for the last newline in the bytes we just got. If there is
- * one, break out of the loop with 'i' as its index and gotNL set
- * true.
- */
max = job->curPos + nr;
+ for (i = job->curPos; i < max; i++)
+ if (job->outBuf[i] == '\0')
+ job->outBuf[i] = ' ';
+
+ /* Look for the last newline in the bytes we just got. */
for (i = job->curPos + nr - 1;
i >= job->curPos && i != (size_t)-1; i--) {
if (job->outBuf[i] == '\n') {
gotNL = true;
break;
- } else if (job->outBuf[i] == '\0') {
- /*
- * FIXME: The null characters are only replaced with
- * space _after_ the last '\n'. Everywhere else they
- * hide the rest of the command output.
- */
- job->outBuf[i] = ' ';
}
}
@@ -1922,7 +1911,7 @@ again:
*/
job->outBuf[i] = '\0';
if (i >= job->curPos) {
- char *cp;
+ char *p;
/*
* FIXME: SwitchOutputTo should be here, according to
@@ -1930,23 +1919,23 @@ again:
* do anything in the default shell, this bug has gone
* unnoticed until now.
*/
- cp = PrintFilteredOutput(job->outBuf, &job->outBuf[i]);
+ p = PrintFilteredOutput(job->outBuf, &job->outBuf[i]);
/*
* There's still more in the output buffer. This time,
* though, we know there's no newline at the end, so
* we add one of our own free will.
*/
- if (*cp != '\0') {
- if (!opts.beSilent)
+ if (*p != '\0') {
+ if (!opts.silent)
SwitchOutputTo(job->node);
#ifdef USE_META
if (useMeta) {
- meta_job_output(job, cp,
+ meta_job_output(job, p,
gotNL ? "\n" : "");
}
#endif
- (void)fprintf(stdout, "%s%s", cp,
+ (void)fprintf(stdout, "%s%s", p,
gotNL ? "\n" : "");
(void)fflush(stdout);
}
@@ -2002,7 +1991,7 @@ JobRun(GNode *targ)
Compat_Make(targ, targ);
/* XXX: Replace with GNode_IsError(gn) */
if (targ->made == ERROR) {
- PrintOnError(targ, "\n\nStop.");
+ PrintOnError(targ, "\n\nStop.\n");
exit(1);
}
#endif
@@ -2087,6 +2076,8 @@ JobReapChild(pid_t pid, WAIT_T status, bool isJobs)
job->status = JOB_ST_FINISHED;
job->exit_status = WAIT_STATUS(status);
+ if (WIFEXITED(status))
+ job->node->exit_status = WEXITSTATUS(status);
JobFinish(job, status);
}
@@ -2128,7 +2119,7 @@ Job_CatchOutput(void)
JobRestartJobs();
} else if (count == 0)
Punt("unexpected eof on token pipe");
- else
+ else if (errno != EAGAIN)
Punt("token pipe read: %s", strerror(errno));
nready--;
}
@@ -2150,9 +2141,8 @@ Job_CatchOutput(void)
* than job->inPollfd.
*/
if (useMeta && job->inPollfd != &fds[i]) {
- if (meta_job_event(job) <= 0) {
- fds[i].events = 0; /* never mind */
- }
+ if (meta_job_event(job) <= 0)
+ fds[i].events = 0; /* never mind */
}
#endif
if (--nready == 0)
@@ -2182,8 +2172,11 @@ InitShellNameAndPath(void)
return;
}
#endif
-
+#ifdef DEFSHELL_PATH
+ shellPath = DEFSHELL_PATH;
+#else
shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName);
+#endif
}
void
@@ -2203,14 +2196,8 @@ Shell_Init(void)
free(shellErrFlag);
shellErrFlag = NULL;
}
- if (shellErrFlag == NULL) {
- size_t n = strlen(shell->errFlag) + 2;
-
- shellErrFlag = bmake_malloc(n);
- if (shellErrFlag != NULL)
- snprintf(shellErrFlag, n, "-%s",
- shell->errFlag);
- }
+ if (shellErrFlag == NULL)
+ shellErrFlag = str_concat2("-", shell->errFlag);
} else if (shellErrFlag != NULL) {
free(shellErrFlag);
shellErrFlag = NULL;
@@ -2230,14 +2217,13 @@ Shell_GetNewline(void)
void
Job_SetPrefix(void)
{
- if (targPrefix != NULL) {
+ if (targPrefix != NULL)
free(targPrefix);
- } else if (!Var_Exists(SCOPE_GLOBAL, MAKE_JOB_PREFIX)) {
- Global_Set(MAKE_JOB_PREFIX, "---");
- }
+ else if (!Var_Exists(SCOPE_GLOBAL, ".MAKE.JOB.PREFIX"))
+ Global_Set(".MAKE.JOB.PREFIX", "---");
- (void)Var_Subst("${" MAKE_JOB_PREFIX "}",
- SCOPE_GLOBAL, VARE_WANTRES, &targPrefix);
+ targPrefix = Var_Subst("${.MAKE.JOB.PREFIX}",
+ SCOPE_GLOBAL, VARE_WANTRES);
/* TODO: handle errors */
}
@@ -2307,9 +2293,7 @@ Job_Init(void)
watchfd(&childExitJob);
sigemptyset(&caught_signals);
- /*
- * Install a SIGCHLD handler.
- */
+ /* Install a SIGCHLD handler. */
(void)bmake_signal(SIGCHLD, JobChildSig);
sigaddset(&caught_signals, SIGCHLD);
@@ -2335,8 +2319,10 @@ Job_Init(void)
AddSig(SIGCONT, JobContinueSig);
(void)Job_RunTarget(".BEGIN", NULL);
- /* Create the .END node now, even though no code in the unit tests
- * depends on it. See also Targ_GetEndNode in Compat_Run. */
+ /*
+ * Create the .END node now, even though no code in the unit tests
+ * depends on it. See also Targ_GetEndNode in Compat_MakeAll.
+ */
(void)Targ_GetEndNode();
}
@@ -2438,9 +2424,7 @@ Job_ParseShell(char *line)
memset(&newShell, 0, sizeof newShell);
- /*
- * Parse the specification by keyword
- */
+ /* Parse the specification by keyword. */
wordsList = Str_Words(line, true);
words = wordsList.words;
argc = wordsList.len;
@@ -2476,13 +2460,17 @@ Job_ParseShell(char *line)
} else if (strncmp(arg, "newline=", 8) == 0) {
newShell.newline = arg + 8;
} else if (strncmp(arg, "check=", 6) == 0) {
- /* Before 2020-12-10, these two variables
- * had been a single variable. */
+ /*
+ * Before 2020-12-10, these two variables had
+ * been a single variable.
+ */
newShell.errOn = arg + 6;
newShell.echoTmpl = arg + 6;
} else if (strncmp(arg, "ignore=", 7) == 0) {
- /* Before 2020-12-10, these two variables
- * had been a single variable. */
+ /*
+ * Before 2020-12-10, these two variables had
+ * been a single variable.
+ */
newShell.errOff = arg + 7;
newShell.runIgnTmpl = arg + 7;
} else if (strncmp(arg, "errout=", 7) == 0) {
@@ -2531,25 +2519,9 @@ Job_ParseShell(char *line)
}
}
} else {
- /*
- * The user provided a path. If s/he gave nothing else
- * (fullSpec is false), try and find a matching shell in the
- * ones we know of. Else we just take the specification at
- * its word and copy it to a new location. In either case,
- * we need to record the path the user gave for the shell.
- */
shellPath = path;
- path = strrchr(path, '/');
- if (path == NULL) {
- path = UNCONST(shellPath);
- } else {
- path++;
- }
- if (newShell.name != NULL) {
- shellName = newShell.name;
- } else {
- shellName = path;
- }
+ shellName = newShell.name != NULL ? newShell.name
+ : str_basename(path);
if (!fullSpec) {
if ((sh = FindShellByName(shellName)) == NULL) {
Parse_Error(PARSE_WARNING,
@@ -2624,7 +2596,7 @@ JobInterrupt(bool runINTERRUPT, int signo)
JobSigUnlock(&mask);
- if (runINTERRUPT && !opts.touchFlag) {
+ if (runINTERRUPT && !opts.touch) {
interrupt = Targ_FindNode(".INTERRUPT");
if (interrupt != NULL) {
opts.ignoreErrors = false;
@@ -2646,11 +2618,10 @@ Job_Finish(void)
GNode *endNode = Targ_GetEndNode();
if (!Lst_IsEmpty(&endNode->commands) ||
!Lst_IsEmpty(&endNode->children)) {
- if (job_errors != 0) {
+ if (job_errors != 0)
Error("Errors reported so .END ignored");
- } else {
+ else
JobRun(endNode);
- }
}
return job_errors;
}
@@ -2790,9 +2761,7 @@ clearfd(Job *job)
fdsLen--;
}
#endif
- /*
- * Move last job in table into hole made by dead job.
- */
+ /* Move last job in table into hole made by dead job. */
if (fdsLen != i) {
fds[i] = fds[fdsLen];
jobByFdIndex[i] = jobByFdIndex[fdsLen];
@@ -2850,7 +2819,7 @@ Job_TempFile(const char *pattern, char *tfile, size_t tfile_sz)
JobSigLock(&mask);
fd = mkTempFile(pattern, tfile, tfile_sz);
if (tfile != NULL && !DEBUG(SCRIPT))
- unlink(tfile);
+ unlink(tfile);
JobSigUnlock(&mask);
return fd;
@@ -2929,9 +2898,8 @@ Job_TokenWithdraw(void)
if (count == 0)
Fatal("eof on job pipe!");
if (count < 0 && jobTokensRunning != 0) {
- if (errno != EAGAIN) {
+ if (errno != EAGAIN)
Fatal("job pipe read: %s", strerror(errno));
- }
DEBUG1(JOB, "(%d) blocked for token\n", getpid());
wantToken = 1;
return false;
@@ -2982,7 +2950,7 @@ Job_RunTarget(const char *target, const char *fname)
JobRun(gn);
/* XXX: Replace with GNode_IsError(gn) */
if (gn->made == ERROR) {
- PrintOnError(gn, "\n\nStop.");
+ PrintOnError(gn, "\n\nStop.\n");
exit(1);
}
return true;
@@ -3047,4 +3015,4 @@ emul_poll(struct pollfd *fd, int nfd, int timeout)
return npoll;
}
-#endif /* USE_SELECT */
+#endif /* USE_SELECT */