summaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
Diffstat (limited to 'job.c')
-rw-r--r--job.c99
1 files changed, 50 insertions, 49 deletions
diff --git a/job.c b/job.c
index 41fb8c34c263..2c04a17a200b 100644
--- a/job.c
+++ b/job.c
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.440 2021/11/28 19:51:06 rillig Exp $ */
+/* $NetBSD: job.c,v 1.451 2022/02/04 23:22:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -155,7 +155,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.440 2021/11/28 19:51:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.451 2022/02/04 23:22:19 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -214,13 +214,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 */
@@ -438,7 +440,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 */
@@ -517,13 +519,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))
Error("*** %s removed", file);
}
@@ -924,7 +926,7 @@ JobWriteCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
run = GNode_ShouldExecute(job->node);
- Var_Subst(ucmd, job->node, VARE_WANTRES, &xcmd);
+ (void)Var_Subst(ucmd, job->node, VARE_WANTRES, &xcmd);
/* TODO: handle errors */
xcmdStart = xcmd;
@@ -938,7 +940,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;
}
@@ -1119,7 +1121,7 @@ JobFinishDoneExitedError(Job *job, WAIT_T *inout_status)
else {
if (deleteOnError)
JobDeleteTarget(job->node);
- PrintOnError(job->node, NULL);
+ PrintOnError(job->node, "\n");
}
}
@@ -1279,9 +1281,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)
@@ -1383,7 +1387,7 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
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;
@@ -1455,9 +1459,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
@@ -1539,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
/*
@@ -1635,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
@@ -1679,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
@@ -1698,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
@@ -1715,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();
}
@@ -1935,7 +1937,7 @@ again:
* we add one of our own free will.
*/
if (*cp != '\0') {
- if (!opts.beSilent)
+ if (!opts.silent)
SwitchOutputTo(job->node);
#ifdef USE_META
if (useMeta) {
@@ -1999,7 +2001,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
@@ -2147,9 +2149,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)
@@ -2203,14 +2204,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;
@@ -2329,8 +2324,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_Run.
+ */
(void)Targ_GetEndNode();
}
@@ -2470,13 +2467,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) {
@@ -2618,7 +2619,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;
@@ -2838,7 +2839,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;
@@ -2970,7 +2971,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;
@@ -3035,4 +3036,4 @@ emul_poll(struct pollfd *fd, int nfd, int timeout)
return npoll;
}
-#endif /* USE_SELECT */
+#endif /* USE_SELECT */