diff options
Diffstat (limited to 'contrib/bmake/job.c')
-rw-r--r-- | contrib/bmake/job.c | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/contrib/bmake/job.c b/contrib/bmake/job.c index 52600124d2a5..a80347acc5cc 100644 --- a/contrib/bmake/job.c +++ b/contrib/bmake/job.c @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.197 2020/02/06 01:13:19 sjg Exp $ */ +/* $NetBSD: job.c,v 1.201 2020/07/03 08:13:23 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.197 2020/02/06 01:13:19 sjg Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.201 2020/07/03 08:13:23 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.197 2020/02/06 01:13:19 sjg Exp $"); +__RCSID("$NetBSD: job.c,v 1.201 2020/07/03 08:13:23 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -290,7 +290,7 @@ static Shell shells[] = { "", }, /* - * KSH description. + * KSH description. */ { "ksh", @@ -463,7 +463,7 @@ JobCreatePipe(Job *job, int minfd) job->jobPipe[i] = fd; } } - + /* Set close-on-exec flag for both */ if (fcntl(job->jobPipe[0], F_SETFD, FD_CLOEXEC) == -1) Punt("Cannot set close-on-exec: %s", strerror(errno)); @@ -473,7 +473,7 @@ JobCreatePipe(Job *job, int minfd) /* * We mark the input side of the pipe non-blocking; we poll(2) the * pipe when we're waiting for a job token, but we might lose the - * race for the token when a new one becomes available, so the read + * race for the token when a new one becomes available, so the read * from the pipe should not block. */ flags = fcntl(job->jobPipe[0], F_GETFL, 0); @@ -796,7 +796,7 @@ JobPrintCommand(void *cmdp, void *jobp) /* * If the shell doesn't have error control the alternate echo'ing will - * be done (to avoid showing additional error checking code) + * be done (to avoid showing additional error checking code) * and this will need the characters '$ ` \ "' escaped */ @@ -804,10 +804,10 @@ JobPrintCommand(void *cmdp, void *jobp) /* Worst that could happen is every char needs escaping. */ escCmd = bmake_malloc((strlen(cmd) * 2) + 1); for (i = 0, j= 0; cmd[i] != '\0'; i++, j++) { - if (cmd[i] == '$' || cmd[i] == '`' || cmd[i] == '\\' || + if (cmd[i] == '$' || cmd[i] == '`' || cmd[i] == '\\' || cmd[i] == '"') escCmd[j++] = '\\'; - escCmd[j] = cmd[i]; + escCmd[j] = cmd[i]; } escCmd[j] = 0; } @@ -880,13 +880,13 @@ JobPrintCommand(void *cmdp, void *jobp) } } else { - /* + /* * If errors are being checked and the shell doesn't have error control * but does supply an errOut template, then setup commands to run * through it. */ - if (!commandShell->hasErrCtl && commandShell->errOut && + if (!commandShell->hasErrCtl && commandShell->errOut && (*commandShell->errOut != '\0')) { if (!(job->flags & JOB_SILENT) && !shutUp) { if (commandShell->hasEchoCtl) { @@ -910,7 +910,7 @@ JobPrintCommand(void *cmdp, void *jobp) DBPRINTF("set -%s\n", "x"); job->flags |= JOB_TRACED; } - + DBPRINTF(cmdTemplate, cmd); free(cmdStart); free(escCmd); @@ -951,7 +951,7 @@ JobSaveCommand(void *cmd, void *gn) { cmd = Var_Subst(NULL, (char *)cmd, (GNode *)gn, VARF_WANTRES); (void)Lst_AtEnd(postCommands->commands, cmd); - return(0); + return 0; } @@ -1074,10 +1074,11 @@ JobFinish (Job *job, WAIT_T status) meta_job_error(job, job->node, job->flags, WEXITSTATUS(status)); } #endif - (void)printf("*** [%s] Error code %d%s\n", - job->node->name, - WEXITSTATUS(status), - (job->flags & JOB_IGNERR) ? " (ignored)" : ""); + if (!dieQuietly(job->node, -1)) + (void)printf("*** [%s] Error code %d%s\n", + job->node->name, + WEXITSTATUS(status), + (job->flags & JOB_IGNERR) ? " (ignored)" : ""); if (job->flags & JOB_IGNERR) { WAIT_STATUS(status) = 0; } else { @@ -1117,7 +1118,7 @@ JobFinish (Job *job, WAIT_T status) } } #endif - + return_job_token = FALSE; Trace_Log(JOBEND, job); @@ -1289,7 +1290,7 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) * .DEFAULT itself. */ Make_HandleUse(DEFAULT, gn); - Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn, 0); + Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn); free(p1); } else if (Dir_MTime(gn, 0) == 0 && (gn->type & OP_SPECIAL) == 0) { /* @@ -1435,7 +1436,7 @@ JobExec(Job *job, char **argv) _exit(1); } } - + /* * Set up the child's output to be routed through the pipe * we've created for it. @@ -1784,7 +1785,7 @@ JobStart(GNode *gn, int flags) JobCreatePipe(job, 3); JobExec(job, argv); - return(JOB_RUNNING); + return JOB_RUNNING; } static char * @@ -2276,11 +2277,11 @@ Shell_GetNewline(void) void Job_SetPrefix(void) { - + if (targPrefix) { free(targPrefix); } else if (!Var_Exists(MAKE_JOB_PREFIX, VAR_GLOBAL)) { - Var_Set(MAKE_JOB_PREFIX, "---", VAR_GLOBAL, 0); + Var_Set(MAKE_JOB_PREFIX, "---", VAR_GLOBAL); } targPrefix = Var_Subst(NULL, "${" MAKE_JOB_PREFIX "}", @@ -2432,7 +2433,7 @@ JobMatchShell(const char *name) for (sh = shells; sh->name != NULL; sh++) { if (strcmp(name, sh->name) == 0) - return (sh); + return sh; } return NULL; } @@ -2548,7 +2549,7 @@ Job_ParseShell(char *line) Parse_Error(PARSE_FATAL, "Unknown keyword \"%s\"", *argv); free(words); - return(FAILURE); + return FAILURE; } fullSpec = TRUE; } @@ -2564,13 +2565,13 @@ Job_ParseShell(char *line) if (newShell.name == NULL) { Parse_Error(PARSE_FATAL, "Neither path nor name specified"); free(words); - return(FAILURE); + return FAILURE; } else { if ((sh = JobMatchShell(newShell.name)) == NULL) { Parse_Error(PARSE_WARNING, "%s: No matching shell", newShell.name); free(words); - return(FAILURE); + return FAILURE; } commandShell = sh; shellName = newShell.name; @@ -2606,7 +2607,7 @@ Job_ParseShell(char *line) Parse_Error(PARSE_WARNING, "%s: No matching shell", shellName); free(words); - return(FAILURE); + return FAILURE; } commandShell = sh; } else { @@ -2723,7 +2724,7 @@ Job_Finish(void) JobRun(postCommands); } } - return(errors); + return errors; } /*- @@ -2968,7 +2969,7 @@ Job_ServerStart(int max_tokens, int jp_0, int jp_1) { int i; char jobarg[64]; - + if (jp_0 >= 0 && jp_1 >= 0) { /* Pipe passed in from parent */ tokenWaitJob.inPipe = jp_0; @@ -2984,12 +2985,12 @@ Job_ServerStart(int max_tokens, int jp_0, int jp_1) tokenWaitJob.inPipe, tokenWaitJob.outPipe); Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL); - Var_Append(MAKEFLAGS, jobarg, VAR_GLOBAL); + Var_Append(MAKEFLAGS, jobarg, VAR_GLOBAL); /* * Preload the job pipe with one token per job, save the one * "extra" token for the primary job. - * + * * XXX should clip maxJobs against PIPE_BUF -- if max_tokens is * larger than the write buffer size of the pipe, we will * deadlock here. @@ -3068,6 +3069,8 @@ Job_TokenWithdraw(void) /* And put the stopper back */ while (write(tokenWaitJob.outPipe, &tok, 1) == -1 && errno == EAGAIN) continue; + if (dieQuietly(NULL, 1)) + exit(2); Fatal("A failure has been detected in another branch of the parallel make"); } @@ -3104,7 +3107,7 @@ Job_RunTarget(const char *target, const char *fname) { return FALSE; if (fname) - Var_Set(ALLSRC, fname, gn, 0); + Var_Set(ALLSRC, fname, gn); JobRun(gn); if (gn->made == ERROR) { @@ -3139,9 +3142,9 @@ emul_poll(struct pollfd *fd, int nfd, int timeout) if (fd[i].fd > maxfd) maxfd = fd[i].fd; } - + if (maxfd >= FD_SETSIZE) { - Punt("Ran out of fd_set slots; " + Punt("Ran out of fd_set slots; " "recompile with a larger FD_SETSIZE."); } |