summaryrefslogtreecommitdiff
path: root/devel/bmake/files/job.c
diff options
context:
space:
mode:
Diffstat (limited to 'devel/bmake/files/job.c')
-rw-r--r--devel/bmake/files/job.c74
1 files changed, 49 insertions, 25 deletions
diff --git a/devel/bmake/files/job.c b/devel/bmake/files/job.c
index 7932b893f4d..455c87b91ea 100644
--- a/devel/bmake/files/job.c
+++ b/devel/bmake/files/job.c
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.7 2008/11/11 14:37:05 joerg Exp $ */
+/* $NetBSD: job.c,v 1.8 2009/09/18 21:27:25 joerg 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.7 2008/11/11 14:37:05 joerg Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.8 2009/09/18 21:27:25 joerg 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.7 2008/11/11 14:37:05 joerg Exp $");
+__RCSID("$NetBSD: job.c,v 1.8 2009/09/18 21:27:25 joerg Exp $");
#endif
#endif /* not lint */
#endif
@@ -197,7 +197,7 @@ int not_parallel = 0; /* set if .NOT_PARALLEL */
* .END target but we keep it around to avoid having to search for it
* all the time.
*/
-static GNode *postCommands = NILGNODE;
+static GNode *postCommands = NULL;
/* node containing commands to execute when
* everything else is done */
static int numCommands; /* The number of commands actually printed
@@ -355,11 +355,13 @@ static sigset_t caught_signals; /* Set of signals we handle */
#define KILLPG(pid, sig) killpg((pid), (sig))
#endif
+static char *tmpdir; /* directory name, always ending with "/" */
+
static void JobChildSig(int);
static void JobContinueSig(int);
static Job *JobFindPid(int, int);
-static int JobPrintCommand(ClientData, ClientData);
-static int JobSaveCommand(ClientData, ClientData);
+static int JobPrintCommand(void *, void *);
+static int JobSaveCommand(void *, void *);
static void JobClose(Job *);
static void JobExec(Job *, char **);
static void JobMakeArgv(Job *, char **);
@@ -674,7 +676,7 @@ JobFindPid(int pid, int status)
*-----------------------------------------------------------------------
*/
static int
-JobPrintCommand(ClientData cmdp, ClientData jobp)
+JobPrintCommand(void *cmdp, void *jobp)
{
Boolean noSpecials; /* true if we shouldn't worry about
* inserting special commands into
@@ -907,7 +909,7 @@ JobPrintCommand(ClientData cmdp, ClientData jobp)
*-----------------------------------------------------------------------
*/
static int
-JobSaveCommand(ClientData cmd, ClientData gn)
+JobSaveCommand(void *cmd, void *gn)
{
cmd = Var_Subst(NULL, (char *)cmd, (GNode *)gn, FALSE);
(void)Lst_AtEnd(postCommands->commands, cmd);
@@ -1072,7 +1074,7 @@ JobFinish (Job *job, WAIT_T status)
* the parents. In addition, any saved commands for the node are placed
* on the .END target.
*/
- if (job->tailCmds != NILLNODE) {
+ if (job->tailCmds != NULL) {
Lst_ForEachFrom(job->node->commands, job->tailCmds,
JobSaveCommand,
job->node);
@@ -1210,7 +1212,7 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
* No commands. Look for .DEFAULT rule from which we might infer
* commands
*/
- if ((DEFAULT != NILGNODE) && !Lst_IsEmpty(DEFAULT->commands) &&
+ if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands) &&
(gn->type & OP_SPECIAL) == 0) {
char *p1;
/*
@@ -1319,6 +1321,7 @@ JobExec(Job *job, char **argv)
if (cpid == 0) {
/* Child */
+ sigset_t tmask;
/*
* Reset all signal handlers; this is necessary because we also
@@ -1327,8 +1330,8 @@ JobExec(Job *job, char **argv)
JobSigReset();
/* Now unblock signals */
- sigemptyset(&mask);
- JobSigUnlock(&mask);
+ sigemptyset(&tmask);
+ JobSigUnlock(&tmask);
/*
* Must duplicate the input stream down to the child's input and
@@ -1519,7 +1522,7 @@ JobStart(GNode *gn, int flags)
flags |= JOB_SPECIAL;
job->node = gn;
- job->tailCmds = NILLNODE;
+ job->tailCmds = NULL;
/*
* Set the initial value of the flags for this job based on the global
@@ -1552,11 +1555,10 @@ JobStart(GNode *gn, int flags)
(!noExecute && !touchFlag)) {
/*
* tfile is the name of a file into which all shell commands are
- * put. It is used over by removing it before the child shell is
- * executed. The XXXXXX in the string are replaced by the pid of
- * the make process in a 6-character field with leading zeroes.
+ * put. It is removed before the child shell is executed, unless
+ * DEBUG(SCRIPT) is set.
*/
- char tfile[sizeof(TMPPAT)];
+ char *tfile;
sigset_t mask;
/*
* We're serious here, but if the commands were bogus, we're
@@ -1567,7 +1569,9 @@ JobStart(GNode *gn, int flags)
}
JobSigLock(&mask);
- (void)strcpy(tfile, TMPPAT);
+ tfile = bmake_malloc(strlen(tmpdir) + sizeof(TMPPAT));
+ strcpy(tfile, tmpdir);
+ strcat(tfile, TMPPAT);
if ((tfd = mkstemp(tfile)) == -1)
Punt("Could not create temporary file %s", strerror(errno));
if (!DEBUG(SCRIPT))
@@ -1598,6 +1602,8 @@ JobStart(GNode *gn, int flags)
if (numCommands == 0) {
noExec = TRUE;
}
+
+ free(tfile);
} else if (NoExecute(gn)) {
/*
* Not executing anything -- just print all the commands to stdout
@@ -1655,7 +1661,7 @@ JobStart(GNode *gn, int flags)
* the commands for the job were no good.
*/
if (cmdsOK && aborting == 0) {
- if (job->tailCmds != NILLNODE) {
+ if (job->tailCmds != NULL) {
Lst_ForEachFrom(job->node->commands, job->tailCmds,
JobSaveCommand,
job->node);
@@ -1897,7 +1903,7 @@ JobRun(GNode *targ)
Lst lst = Lst_Init(FALSE);
Lst_AtEnd(lst, targ);
(void)Make_Run(lst);
- Lst_Destroy(lst, NOFREE);
+ Lst_Destroy(lst, NULL);
JobStart(targ, JOB_SPECIAL);
while (jobTokensRunning) {
Job_CatchOutput();
@@ -2130,6 +2136,8 @@ void
Job_Init(void)
{
GNode *begin; /* node for commands to do at the very start */
+ const char *p;
+ size_t len;
/* Allocate space for all the job info */
job_table = bmake_malloc(maxJobs * sizeof *job_table);
@@ -2140,7 +2148,19 @@ Job_Init(void)
aborting = 0;
errors = 0;
- lastNode = NILGNODE;
+ lastNode = NULL;
+
+ /* set tmpdir, and ensure that it ends with "/" */
+ p = getenv("TMPDIR");
+ if (p == NULL || *p == '\0') {
+ p = _PATH_TMP;
+ }
+ len = strlen(p);
+ tmpdir = bmake_malloc(len + 2);
+ strcpy(tmpdir, p);
+ if (tmpdir[len - 1] != '/') {
+ strcat(tmpdir, "/");
+ }
if (maxJobs == 1) {
/*
@@ -2218,7 +2238,7 @@ Job_Init(void)
begin = Targ_FindNode(".BEGIN", TARG_NOCREATE);
- if (begin != NILGNODE) {
+ if (begin != NULL) {
JobRun(begin);
if (begin->made == ERROR) {
PrintOnError("\n\nStop.");
@@ -2270,7 +2290,7 @@ JobMatchShell(const char *name)
if (strcmp(name, sh->name) == 0)
return (sh);
}
- return (NULL);
+ return NULL;
}
/*-
@@ -2344,6 +2364,10 @@ Job_ParseShell(char *line)
* Parse the specification by keyword
*/
words = brk_string(line, &argc, TRUE, &path);
+ if (words == NULL) {
+ Error("Unterminated quoted string [%s]", line);
+ return FAILURE;
+ }
shellArgv = path;
for (path = NULL, argv = words; argc != 0; argc--, argv++) {
@@ -2519,7 +2543,7 @@ JobInterrupt(int runINTERRUPT, int signo)
if (runINTERRUPT && !touchFlag) {
interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
- if (interrupt != NILGNODE) {
+ if (interrupt != NULL) {
ignoreErrors = FALSE;
JobRun(interrupt);
}
@@ -2544,7 +2568,7 @@ JobInterrupt(int runINTERRUPT, int signo)
int
Job_Finish(void)
{
- if (postCommands != NILGNODE &&
+ if (postCommands != NULL &&
(!Lst_IsEmpty(postCommands->commands) ||
!Lst_IsEmpty(postCommands->children))) {
if (errors) {