1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2002-04-13 10:57:56 +00:00
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1995-01-23 21:03:17 +00:00
|
|
|
* Copyright (c) 1988, 1989 by Adam de Boor
|
1994-05-27 12:33:43 +00:00
|
|
|
* Copyright (c) 1989 by Berkeley Softworks
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Adam de Boor.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2000-07-09 02:54:54 +00:00
|
|
|
*
|
|
|
|
* @(#)job.c 8.2 (Berkeley) 3/19/94
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-09 02:54:54 +00:00
|
|
|
#include <sys/cdefs.h>
|
2002-04-13 10:17:18 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-04-28 05:08:10 +00:00
|
|
|
#ifndef OLD_JOKE
|
2002-09-17 21:29:06 +00:00
|
|
|
#define OLD_JOKE 0
|
1998-04-28 05:08:10 +00:00
|
|
|
#endif /* OLD_JOKE */
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
* job.c --
|
|
|
|
* handle the creation etc. of our child processes.
|
|
|
|
*
|
|
|
|
* Interface:
|
|
|
|
* Job_Make Start the creation of the given target.
|
|
|
|
*
|
|
|
|
* Job_CatchChildren Check for and handle the termination of any
|
|
|
|
* children. This must be called reasonably
|
|
|
|
* frequently to keep the whole make going at
|
|
|
|
* a decent clip, since job table entries aren't
|
|
|
|
* removed until their process is caught this way.
|
|
|
|
* Its single argument is TRUE if the function
|
|
|
|
* should block waiting for a child to terminate.
|
|
|
|
*
|
|
|
|
* Job_CatchOutput Print any output our children have produced.
|
|
|
|
* Should also be called fairly frequently to
|
|
|
|
* keep the user informed of what's going on.
|
|
|
|
* If no output is waiting, it will block for
|
|
|
|
* a time given by the SEL_* constants, below,
|
|
|
|
* or until output is ready.
|
|
|
|
*
|
|
|
|
* Job_Init Called to intialize this module. in addition,
|
|
|
|
* any commands attached to the .BEGIN target
|
|
|
|
* are executed before this function returns.
|
|
|
|
* Hence, the makefile must have been parsed
|
|
|
|
* before this function is called.
|
|
|
|
*
|
|
|
|
* Job_Full Return TRUE if the job table is filled.
|
|
|
|
*
|
|
|
|
* Job_Empty Return TRUE if the job table is completely
|
|
|
|
* empty.
|
|
|
|
*
|
|
|
|
* Job_ParseShell Given the line following a .SHELL target, parse
|
|
|
|
* the line as a shell specification. Returns
|
|
|
|
* FAILURE if the spec was incorrect.
|
|
|
|
*
|
2002-04-13 12:18:00 +00:00
|
|
|
* Job_Finish Perform any final processing which needs doing.
|
1994-05-27 12:33:43 +00:00
|
|
|
* This includes the execution of any commands
|
|
|
|
* which have been/were attached to the .END
|
|
|
|
* target. It should only be called when the
|
|
|
|
* job table is empty.
|
|
|
|
*
|
|
|
|
* Job_AbortAll Abort all currently running jobs. It doesn't
|
|
|
|
* handle output or do anything for the jobs,
|
|
|
|
* just kills them. It should only be called in
|
|
|
|
* an emergency, as it were.
|
|
|
|
*
|
|
|
|
* Job_CheckCommands Verify that the commands for a target are
|
|
|
|
* ok. Provide them if necessary and possible.
|
|
|
|
*
|
|
|
|
* Job_Touch Update a target without really updating it.
|
|
|
|
*
|
|
|
|
* Job_Wait Wait for all currently-running jobs to finish.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/time.h>
|
2002-12-01 13:38:25 +00:00
|
|
|
#ifdef USE_KQUEUE
|
2002-10-04 20:30:03 +00:00
|
|
|
#include <sys/event.h>
|
2002-12-01 13:38:25 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/wait.h>
|
2002-04-12 13:23:33 +00:00
|
|
|
#include <err.h>
|
1995-01-23 21:03:17 +00:00
|
|
|
#include <errno.h>
|
2002-04-12 13:23:33 +00:00
|
|
|
#include <fcntl.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1995-01-23 21:03:17 +00:00
|
|
|
#include <signal.h>
|
2001-07-26 11:02:39 +00:00
|
|
|
#include <unistd.h>
|
2002-04-12 13:23:33 +00:00
|
|
|
#include <utime.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "make.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "job.h"
|
|
|
|
#include "pathnames.h"
|
2004-11-04 12:57:41 +00:00
|
|
|
|
|
|
|
#define STATIC static
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* error handling variables
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
static int errors = 0; /* number of errors reported */
|
|
|
|
static int aborting = 0; /* why is the make aborting? */
|
2002-09-17 21:29:06 +00:00
|
|
|
#define ABORT_ERROR 1 /* Because of an error */
|
|
|
|
#define ABORT_INTERRUPT 2 /* Because it was interrupted */
|
|
|
|
#define ABORT_WAIT 3 /* Waiting for jobs to finish */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
/*
|
|
|
|
* XXX: Avoid SunOS bug... FILENO() is fp->_file, and file
|
|
|
|
* is a char! So when we go above 127 we turn negative!
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
#define FILENO(a) ((unsigned)fileno(a))
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* post-make command processing. The node postCommands is really just the
|
|
|
|
* .END target but we keep it around to avoid having to search for it
|
|
|
|
* all the time.
|
|
|
|
*/
|
|
|
|
static GNode *postCommands; /* node containing commands to execute when
|
|
|
|
* everything else is done */
|
|
|
|
static int numCommands; /* The number of commands actually printed
|
|
|
|
* for a target. Should this number be
|
|
|
|
* 0, no shell will be executed. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return values from JobStart.
|
|
|
|
*/
|
2002-09-17 21:29:06 +00:00
|
|
|
#define JOB_RUNNING 0 /* Job is running */
|
|
|
|
#define JOB_ERROR 1 /* Error in starting the job */
|
|
|
|
#define JOB_FINISHED 2 /* The job is already finished */
|
|
|
|
#define JOB_STOPPED 3 /* The job is stopped */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-11-19 12:04:12 +00:00
|
|
|
/*
|
|
|
|
* tfile is used to build temp file names to store shell commands to
|
2004-11-30 17:46:29 +00:00
|
|
|
* execute.
|
2000-11-19 12:04:12 +00:00
|
|
|
*/
|
|
|
|
static char tfile[sizeof(TMPPAT)];
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Descriptions for various shells.
|
|
|
|
*/
|
2004-11-30 15:35:51 +00:00
|
|
|
static const DEF_SHELL_STRUCT(CShell, const) shells[] = {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* CSH description. The csh can do echo control by playing
|
|
|
|
* with the setting of the 'echo' shell variable. Sadly,
|
|
|
|
* however, it is unable to do error control nicely.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
"csh",
|
2004-10-23 21:36:55 +00:00
|
|
|
TRUE, "unset verbose", "set verbose", "unset verbose", 13,
|
1994-05-27 12:33:43 +00:00
|
|
|
FALSE, "echo \"%s\"\n", "csh -c \"%s || exit 0\"",
|
|
|
|
"v", "e",
|
|
|
|
},
|
|
|
|
/*
|
|
|
|
* SH description. Echo control is also possible and, under
|
|
|
|
* sun UNIX anyway, one can even control error checking.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
"sh",
|
|
|
|
TRUE, "set -", "set -v", "set -", 5,
|
1996-10-06 02:35:38 +00:00
|
|
|
TRUE, "set -e", "set +e",
|
|
|
|
#ifdef OLDBOURNESHELL
|
1994-05-27 12:33:43 +00:00
|
|
|
FALSE, "echo \"%s\"\n", "sh -c '%s || exit 0'\n",
|
1996-10-06 02:35:38 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
"v", "e",
|
2000-08-16 23:31:43 +00:00
|
|
|
},
|
|
|
|
/*
|
|
|
|
* KSH description. The Korn shell has a superset of
|
|
|
|
* the Bourne shell's functionality.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
"ksh",
|
|
|
|
TRUE, "set -", "set -v", "set -", 5,
|
|
|
|
TRUE, "set -e", "set +e",
|
|
|
|
"v", "e",
|
1994-05-27 12:33:43 +00:00
|
|
|
},
|
|
|
|
};
|
2004-11-25 10:01:26 +00:00
|
|
|
static Shell *commandShell = NULL; /* this is the shell to which we pass
|
|
|
|
* all commands in the Makefile. It is
|
|
|
|
* set by the Job_ParseShell function */
|
|
|
|
char *shellPath = NULL, /* full pathname of executable image */
|
|
|
|
*shellName = NULL; /* last component of shell */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int maxJobs; /* The most children we can run at once */
|
1996-10-06 02:35:38 +00:00
|
|
|
STATIC int nJobs; /* The number of children currently running */
|
|
|
|
STATIC Lst jobs; /* The structures that describe them */
|
|
|
|
STATIC Boolean jobFull; /* Flag to tell when the job table is full. It
|
1994-05-27 12:33:43 +00:00
|
|
|
* is set TRUE when (1) the total number of
|
2004-11-11 12:52:16 +00:00
|
|
|
* running jobs equals the maximum allowed */
|
2002-10-04 20:30:03 +00:00
|
|
|
#ifdef USE_KQUEUE
|
|
|
|
static int kqfd; /* File descriptor obtained by kqueue() */
|
|
|
|
#else
|
1994-05-27 12:33:43 +00:00
|
|
|
static fd_set outputs; /* Set of descriptors of pipes connected to
|
|
|
|
* the output channels of children */
|
|
|
|
#endif
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
STATIC GNode *lastNode; /* The node for which output was most recently
|
1994-05-27 12:33:43 +00:00
|
|
|
* produced. */
|
1996-10-06 02:35:38 +00:00
|
|
|
STATIC char *targFmt; /* Format string to use to head output from a
|
1994-05-27 12:33:43 +00:00
|
|
|
* job when it's not the most-recent job heard
|
|
|
|
* from */
|
1996-10-06 02:35:38 +00:00
|
|
|
|
2004-11-04 12:57:41 +00:00
|
|
|
#define TARG_FMT "--- %s ---\n" /* Default format */
|
|
|
|
#define MESSAGE(fp, gn) \
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(fp, targFmt, gn->name);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
2004-11-05 11:41:36 +00:00
|
|
|
* When JobStart attempts to run a job but isn't allowed to
|
|
|
|
* or when Job_CatchChildren detects a job that has
|
|
|
|
* been stopped somehow, the job is placed on the stoppedJobs queue to be run
|
1995-05-30 06:41:30 +00:00
|
|
|
* when the next job finishes.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
STATIC Lst stoppedJobs; /* Lst of Job structures describing
|
1994-05-27 12:33:43 +00:00
|
|
|
* jobs that were stopped due to concurrency
|
2004-11-05 11:41:36 +00:00
|
|
|
* limits or externally */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-12 08:58:07 +00:00
|
|
|
STATIC int fifoFd; /* Fd of our job fifo */
|
|
|
|
STATIC char fifoName[] = "/tmp/make_fifo_XXXXXXXXX";
|
|
|
|
STATIC int fifoMaster;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-12 07:57:17 +00:00
|
|
|
static sig_atomic_t interrupted;
|
|
|
|
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#if defined(USE_PGRP) && defined(SYSV)
|
1996-10-06 02:35:38 +00:00
|
|
|
# define KILL(pid, sig) killpg(-(pid), (sig))
|
1994-05-27 12:33:43 +00:00
|
|
|
#else
|
|
|
|
# if defined(USE_PGRP)
|
1996-10-06 02:35:38 +00:00
|
|
|
# define KILL(pid, sig) killpg((pid), (sig))
|
1994-05-27 12:33:43 +00:00
|
|
|
# else
|
1996-10-06 02:35:38 +00:00
|
|
|
# define KILL(pid, sig) kill((pid), (sig))
|
1994-05-27 12:33:43 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
/*
|
|
|
|
* Grmpf... There is no way to set bits of the wait structure
|
|
|
|
* anymore with the stupid W*() macros. I liked the union wait
|
|
|
|
* stuff much more. So, we devise our own macros... This is
|
|
|
|
* really ugly, use dramamine sparingly. You have been warned.
|
|
|
|
*/
|
2002-09-17 21:29:06 +00:00
|
|
|
#define W_SETMASKED(st, val, fun) \
|
1996-10-06 02:35:38 +00:00
|
|
|
{ \
|
2004-11-30 17:46:29 +00:00
|
|
|
int sh = (int)~0; \
|
1996-10-06 02:35:38 +00:00
|
|
|
int mask = fun(sh); \
|
|
|
|
\
|
|
|
|
for (sh = 0; ((mask >> sh) & 1) == 0; sh++) \
|
|
|
|
continue; \
|
|
|
|
*(st) = (*(st) & ~mask) | ((val) << sh); \
|
|
|
|
}
|
|
|
|
|
2002-09-17 21:29:06 +00:00
|
|
|
#define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
|
|
|
|
#define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
|
2002-03-22 01:33:25 +00:00
|
|
|
static int JobCondPassSig(void *, void *);
|
|
|
|
static void JobPassSig(int);
|
|
|
|
static int JobCmpPid(void *, void *);
|
|
|
|
static int JobPrintCommand(void *, void *);
|
|
|
|
static int JobSaveCommand(void *, void *);
|
|
|
|
static void JobClose(Job *);
|
|
|
|
static void JobFinish(Job *, int *);
|
|
|
|
static void JobExec(Job *, char **);
|
|
|
|
static void JobMakeArgv(Job *, char **);
|
|
|
|
static void JobRestart(Job *);
|
|
|
|
static int JobStart(GNode *, int, Job *);
|
|
|
|
static char *JobOutput(Job *, char *, char *, int);
|
|
|
|
static void JobDoOutput(Job *, Boolean);
|
2004-11-30 15:35:51 +00:00
|
|
|
static Shell *JobMatchShell(const char *);
|
2002-03-22 01:33:25 +00:00
|
|
|
static void JobInterrupt(int, int);
|
|
|
|
static void JobRestartJobs(void);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-12 07:57:17 +00:00
|
|
|
/*
|
|
|
|
* JobCatchSignal
|
|
|
|
*
|
|
|
|
* Got a signal. Set global variables and hope that someone will
|
|
|
|
* handle it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
JobCatchSig(int signo)
|
|
|
|
{
|
|
|
|
|
|
|
|
interrupted = signo;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobCondPassSig --
|
2004-11-05 11:41:36 +00:00
|
|
|
* Pass a signal to a job if USE_PGRP is defined.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* === 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None, except the job may bite it.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
JobCondPassSig(void *jobp, void *signop)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-12-01 10:29:20 +00:00
|
|
|
Job *job = jobp;
|
2004-11-30 17:46:29 +00:00
|
|
|
int signo = *(int *)signop;
|
2004-11-04 12:57:41 +00:00
|
|
|
|
2004-11-05 11:41:36 +00:00
|
|
|
DEBUGF(JOB, ("JobCondPassSig passing signal %d to child %d.\n",
|
|
|
|
signo, job->pid));
|
1994-05-27 12:33:43 +00:00
|
|
|
KILL(job->pid, signo);
|
2004-11-30 17:46:29 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobPassSig --
|
2004-11-05 11:41:36 +00:00
|
|
|
* Pass a signal on to all local jobs if
|
1994-05-27 12:33:43 +00:00
|
|
|
* USE_PGRP is defined, then die ourselves.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* We die by the same signal.
|
1995-05-30 06:41:30 +00:00
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobPassSig(int signo)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1996-10-06 02:35:38 +00:00
|
|
|
sigset_t nmask, omask;
|
|
|
|
struct sigaction act;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-12 07:57:17 +00:00
|
|
|
sigemptyset(&nmask);
|
|
|
|
sigaddset(&nmask, signo);
|
|
|
|
sigprocmask(SIG_SETMASK, &nmask, &omask);
|
|
|
|
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("JobPassSig(%d) called.\n", signo));
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_ForEach(jobs, JobCondPassSig, &signo);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with proper cleanup based on the signal received. We only run
|
|
|
|
* the .INTERRUPT target if the signal was in fact an interrupt. The other
|
|
|
|
* three termination signals are more of a "get out *now*" command.
|
|
|
|
*/
|
|
|
|
if (signo == SIGINT) {
|
1996-10-06 02:35:38 +00:00
|
|
|
JobInterrupt(TRUE, signo);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else if ((signo == SIGHUP) || (signo == SIGTERM) || (signo == SIGQUIT)) {
|
1996-10-06 02:35:38 +00:00
|
|
|
JobInterrupt(FALSE, signo);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Leave gracefully if SIGQUIT, rather than core dumping.
|
|
|
|
*/
|
|
|
|
if (signo == SIGQUIT) {
|
1998-08-24 10:17:20 +00:00
|
|
|
signo = SIGINT;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Send ourselves the signal now we've given the message to everyone else.
|
|
|
|
* Note we block everything else possible while we're getting the signal.
|
|
|
|
* This ensures that all our jobs get continued when we wake up before
|
|
|
|
* we take any other signal.
|
2004-11-12 07:57:17 +00:00
|
|
|
* XXX this comment seems wrong.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
sigaction(signo, &act, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
DEBUGF(JOB, ("JobPassSig passing signal to self, mask = %x.\n",
|
|
|
|
~0 & ~(1 << (signo - 1))));
|
|
|
|
signal(signo, SIG_DFL);
|
1996-10-06 02:35:38 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
KILL(getpid(), signo);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1995-01-23 21:03:17 +00:00
|
|
|
signo = SIGCONT;
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_ForEach(jobs, JobCondPassSig, &signo);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
1996-10-06 02:35:38 +00:00
|
|
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
|
|
|
act.sa_handler = JobPassSig;
|
|
|
|
sigaction(signo, &act, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobCmpPid --
|
|
|
|
* Compare the pid of the job with the given pid and return 0 if they
|
|
|
|
* are equal. This function is called from Job_CatchChildren via
|
|
|
|
* Lst_Find to find the job descriptor of the finished job.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* 0 if the pid's match
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
JobCmpPid(void *job, void *pid)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-12-01 10:29:20 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
return (*(int *)pid - ((Job *)job)->pid);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobPrintCommand --
|
|
|
|
* Put out another command for the given job. If the command starts
|
|
|
|
* with an @ or a - we process it specially. In the former case,
|
|
|
|
* so long as the -s and -n flags weren't given to make, we stick
|
|
|
|
* a shell-specific echoOff command in the script. In the latter,
|
|
|
|
* we ignore errors for the entire job, unless the shell has error
|
|
|
|
* control.
|
|
|
|
* If the command is just "..." we take all future commands for this
|
|
|
|
* job to be commands to be executed once the entire graph has been
|
|
|
|
* made and return non-zero to signal that the end of the commands
|
|
|
|
* was reached. These commands are later attached to the postCommands
|
2002-04-13 12:18:00 +00:00
|
|
|
* node and executed by Job_Finish when all things are done.
|
1994-05-27 12:33:43 +00:00
|
|
|
* This function is called from JobStart via Lst_ForEach.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Always 0, unless the command was "..."
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* If the command begins with a '-' and the shell has no error control,
|
|
|
|
* the JOB_IGNERR flag is set in the job descriptor.
|
|
|
|
* If the command is "..." and we're not ignoring such things,
|
|
|
|
* tailCmds is set to the successor node of the cmd.
|
|
|
|
* numCommands is incremented if the command is actually printed.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
JobPrintCommand(void *cmdp, void *jobp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
Boolean noSpecials; /* true if we shouldn't worry about
|
|
|
|
* inserting special commands into
|
|
|
|
* the input stream. */
|
|
|
|
Boolean shutUp = FALSE; /* true if we put a no echo command
|
|
|
|
* into the command file */
|
|
|
|
Boolean errOff = FALSE; /* true if we turned error checking
|
|
|
|
* off before printing the command
|
|
|
|
* and need to turn it back on */
|
|
|
|
char *cmdTemplate; /* Template to use when printing the
|
|
|
|
* command */
|
|
|
|
char *cmdStart; /* Start of expanded command */
|
|
|
|
LstNode cmdNode; /* Node for replacing the command */
|
2004-12-01 10:29:20 +00:00
|
|
|
char *cmd = cmdp;
|
|
|
|
Job *job = jobp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
noSpecials = (noExecute && !(job->node->type & OP_MAKE));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (strcmp(cmd, "...") == 0) {
|
1995-05-30 06:41:30 +00:00
|
|
|
job->node->type |= OP_SAVE_CMDS;
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((job->flags & JOB_IGNDOTS) == 0) {
|
2004-12-01 10:29:20 +00:00
|
|
|
job->tailCmds = Lst_Succ(Lst_Member(job->node->commands, cmd));
|
2004-11-30 17:46:29 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2002-09-17 22:31:26 +00:00
|
|
|
#define DBPRINTF(fmt, arg) \
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, (fmt, arg)); \
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(job->cmdFILE, fmt, arg); \
|
|
|
|
fflush(job->cmdFILE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
numCommands += 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For debugging, we replace each command with the result of expanding
|
|
|
|
* the variables in the command.
|
|
|
|
*/
|
2004-12-01 10:29:20 +00:00
|
|
|
cmdNode = Lst_Member(job->node->commands, cmd);
|
1996-10-06 02:35:38 +00:00
|
|
|
cmdStart = cmd = Var_Subst(NULL, cmd, job->node, FALSE);
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_Replace(cmdNode, cmdStart);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
cmdTemplate = "%s\n";
|
|
|
|
|
|
|
|
/*
|
2004-07-29 14:29:23 +00:00
|
|
|
* Check for leading @', -' or +'s to control echoing, error checking,
|
|
|
|
* and execution on -n.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2004-07-29 14:29:23 +00:00
|
|
|
while (*cmd == '@' || *cmd == '-' || *cmd == '+') {
|
|
|
|
switch (*cmd) {
|
|
|
|
|
|
|
|
case '@':
|
2000-05-14 22:24:28 +00:00
|
|
|
shutUp = DEBUG(LOUD) ? FALSE : TRUE;
|
2004-07-29 14:29:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
1994-05-27 12:33:43 +00:00
|
|
|
errOff = TRUE;
|
2004-07-29 14:29:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
if (noSpecials) {
|
|
|
|
/*
|
|
|
|
* We're not actually exececuting anything...
|
|
|
|
* but this one needs to be - use compat mode just for it.
|
|
|
|
*/
|
|
|
|
Compat_RunCommand(cmdp, job->node);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
cmd++;
|
|
|
|
}
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
while (isspace((unsigned char)*cmd))
|
1994-05-27 12:33:43 +00:00
|
|
|
cmd++;
|
|
|
|
|
|
|
|
if (shutUp) {
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!(job->flags & JOB_SILENT) && !noSpecials &&
|
1994-05-27 12:33:43 +00:00
|
|
|
commandShell->hasEchoCtl) {
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
shutUp = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errOff) {
|
1996-10-06 02:35:38 +00:00
|
|
|
if ( !(job->flags & JOB_IGNERR) && !noSpecials) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (commandShell->hasErrCtl) {
|
|
|
|
/*
|
|
|
|
* we don't want the error-control commands showing
|
|
|
|
* up either, so we turn off echoing while executing
|
|
|
|
* them. We could put another field in the shell
|
|
|
|
* structure to tell JobDoOutput to look for this
|
|
|
|
* string too, but why make it any more complex than
|
|
|
|
* it already is?
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!(job->flags & JOB_SILENT) && !shutUp &&
|
1994-05-27 12:33:43 +00:00
|
|
|
commandShell->hasEchoCtl) {
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
|
|
|
DBPRINTF("%s\n", commandShell->ignErr);
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOn);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF("%s\n", commandShell->ignErr);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} else if (commandShell->ignErr &&
|
1996-10-06 02:35:38 +00:00
|
|
|
(*commandShell->ignErr != '\0'))
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The shell has no error control, so we need to be
|
|
|
|
* weird to get it to ignore any errors from the command.
|
|
|
|
* If echoing is turned on, we turn it off and use the
|
|
|
|
* errCheck template to echo the command. Leave echoing
|
|
|
|
* off so the user doesn't see the weirdness we go through
|
|
|
|
* to ignore errors. Set cmdTemplate to use the weirdness
|
|
|
|
* instead of the simple "%s\n" template.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!(job->flags & JOB_SILENT) && !shutUp &&
|
1994-05-27 12:33:43 +00:00
|
|
|
commandShell->hasEchoCtl) {
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
|
|
|
DBPRINTF(commandShell->errCheck, cmd);
|
1994-05-27 12:33:43 +00:00
|
|
|
shutUp = TRUE;
|
|
|
|
}
|
|
|
|
cmdTemplate = commandShell->ignErr;
|
|
|
|
/*
|
|
|
|
* The error ignoration (hee hee) is already taken care
|
|
|
|
* of by the ignErr template, so pretend error checking
|
|
|
|
* is still on.
|
|
|
|
*/
|
|
|
|
errOff = FALSE;
|
|
|
|
} else {
|
|
|
|
errOff = FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errOff = FALSE;
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF(cmdTemplate, cmd);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (errOff) {
|
|
|
|
/*
|
|
|
|
* If echoing is already off, there's no point in issuing the
|
|
|
|
* echoOff command. Otherwise we issue it and pretend it was on
|
|
|
|
* for the whole command...
|
|
|
|
*/
|
2004-12-01 10:29:20 +00:00
|
|
|
if (!shutUp && !(job->flags & JOB_SILENT) && commandShell->hasEchoCtl) {
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
1994-05-27 12:33:43 +00:00
|
|
|
shutUp = TRUE;
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF("%s\n", commandShell->errCheck);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (shutUp) {
|
1996-10-06 02:35:38 +00:00
|
|
|
DBPRINTF("%s\n", commandShell->echoOn);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobSaveCommand --
|
|
|
|
* Save a command to be executed when everything else is done.
|
|
|
|
* Callback function for JobFinish...
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Always returns 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The command is tacked onto the end of postCommands's commands list.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
JobSaveCommand(void *cmd, void *gn)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
cmd = Var_Subst(NULL, cmd, gn, FALSE);
|
2004-11-30 17:46:29 +00:00
|
|
|
Lst_AtEnd(postCommands->commands, cmd);
|
|
|
|
return (0);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobClose --
|
|
|
|
* Called to close both input and output pipes when a job is finished.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Nada
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The file descriptors associated with the job are closed.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobClose(Job *job)
|
1996-10-06 02:35:38 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (usePipes) {
|
2004-11-04 12:57:41 +00:00
|
|
|
#if !defined(USE_KQUEUE)
|
1996-10-06 02:35:38 +00:00
|
|
|
FD_CLR(job->inPipe, &outputs);
|
|
|
|
#endif
|
|
|
|
if (job->outPipe != job->inPipe) {
|
2004-11-30 17:46:29 +00:00
|
|
|
close(job->outPipe);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
JobDoOutput(job, TRUE);
|
2004-11-30 17:46:29 +00:00
|
|
|
close(job->inPipe);
|
1996-10-06 02:35:38 +00:00
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
close(job->outFd);
|
1996-10-06 02:35:38 +00:00
|
|
|
JobDoOutput(job, TRUE);
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobFinish --
|
|
|
|
* Do final processing for the given job including updating
|
|
|
|
* parents and starting new jobs as available/necessary. Note
|
|
|
|
* that we pay no attention to the JOB_IGNERR flag here.
|
|
|
|
* This is because when we're called because of a noexecute flag
|
|
|
|
* or something, jstat.w_status is 0 and when called from
|
|
|
|
* Job_CatchChildren, the status is zeroed if it s/b ignored.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Some nodes may be put on the toBeMade queue.
|
|
|
|
* Final commands for the job are placed on postCommands.
|
|
|
|
*
|
|
|
|
* If we got an error and are aborting (aborting == ABORT_ERROR) and
|
|
|
|
* the job list is now empty, we are done for the day.
|
|
|
|
* If we recognized an error (errors !=0), we set the aborting flag
|
|
|
|
* to ABORT_ERROR so no more jobs will be started.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobFinish(Job *job, int *status)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1996-10-06 02:35:38 +00:00
|
|
|
Boolean done;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if ((WIFEXITED(*status) &&
|
|
|
|
(((WEXITSTATUS(*status) != 0) && !(job->flags & JOB_IGNERR)))) ||
|
|
|
|
(WIFSIGNALED(*status) && (WTERMSIG(*status) != SIGCONT)))
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If it exited non-zero and either we're doing things our
|
|
|
|
* way or we're not ignoring errors, the job is finished.
|
|
|
|
* Similarly, if the shell died because of a signal
|
|
|
|
* the job is also finished. In these
|
|
|
|
* cases, finish out the job's output before printing the exit
|
|
|
|
* status...
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
JobClose(job);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
|
2004-11-30 17:46:29 +00:00
|
|
|
fclose(job->cmdFILE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
done = TRUE;
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (WIFEXITED(*status)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Deal with ignored errors in -B mode. We need to print a message
|
|
|
|
* telling of the ignored error as well as setting status.w_status
|
|
|
|
* to 0 so the next command gets run. To do this, we set done to be
|
1996-10-06 02:35:38 +00:00
|
|
|
* TRUE if in -B mode and the job exited non-zero.
|
|
|
|
*/
|
|
|
|
done = WEXITSTATUS(*status) != 0;
|
|
|
|
/*
|
|
|
|
* Old comment said: "Note we don't
|
1994-05-27 12:33:43 +00:00
|
|
|
* want to close down any of the streams until we know we're at the
|
1996-10-06 02:35:38 +00:00
|
|
|
* end."
|
|
|
|
* But we do. Otherwise when are we going to print the rest of the
|
|
|
|
* stuff?
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
JobClose(job);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No need to close things down or anything.
|
|
|
|
*/
|
|
|
|
done = FALSE;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (done ||
|
1996-10-06 02:35:38 +00:00
|
|
|
WIFSTOPPED(*status) ||
|
|
|
|
(WIFSIGNALED(*status) && (WTERMSIG(*status) == SIGCONT)) ||
|
1994-05-27 12:33:43 +00:00
|
|
|
DEBUG(JOB))
|
|
|
|
{
|
|
|
|
FILE *out;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (compatMake && !usePipes && (job->flags & JOB_IGNERR)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If output is going to a file and this job is ignoring
|
|
|
|
* errors, arrange to have the exit status sent to the
|
|
|
|
* output file as well.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
out = fdopen(job->outFd, "w");
|
2002-04-13 09:10:07 +00:00
|
|
|
if (out == NULL)
|
|
|
|
Punt("Cannot fdopen");
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
out = stdout;
|
|
|
|
}
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (WIFEXITED(*status)) {
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Process %d exited.\n", job->pid));
|
1996-10-06 02:35:38 +00:00
|
|
|
if (WEXITSTATUS(*status) != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (usePipes && job->node != lastNode) {
|
1996-10-06 02:35:38 +00:00
|
|
|
MESSAGE(out, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = job->node;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(out, "*** Error code %d%s\n",
|
1996-10-06 02:35:38 +00:00
|
|
|
WEXITSTATUS(*status),
|
|
|
|
(job->flags & JOB_IGNERR) ? "(ignored)" : "");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (job->flags & JOB_IGNERR) {
|
1996-10-06 02:35:38 +00:00
|
|
|
*status = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} else if (DEBUG(JOB)) {
|
|
|
|
if (usePipes && job->node != lastNode) {
|
1996-10-06 02:35:38 +00:00
|
|
|
MESSAGE(out, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = job->node;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(out, "*** Completed successfully\n");
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
} else if (WIFSTOPPED(*status)) {
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Process %d stopped.\n", job->pid));
|
1994-05-27 12:33:43 +00:00
|
|
|
if (usePipes && job->node != lastNode) {
|
1996-10-06 02:35:38 +00:00
|
|
|
MESSAGE(out, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = job->node;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(out, "*** Stopped -- signal %d\n",
|
2004-11-05 11:41:36 +00:00
|
|
|
WSTOPSIG(*status));
|
1994-05-27 12:33:43 +00:00
|
|
|
job->flags |= JOB_RESUME;
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_AtEnd(stoppedJobs, job);
|
2004-11-30 17:46:29 +00:00
|
|
|
fflush(out);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (WTERMSIG(*status) == SIGCONT) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If the beastie has continued, shift the Job from the stopped
|
|
|
|
* list to the running one (or re-stop it if concurrency is
|
|
|
|
* exceeded) and go and get another child.
|
|
|
|
*/
|
2004-11-05 11:41:36 +00:00
|
|
|
if (job->flags & (JOB_RESUME|JOB_RESTART)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (usePipes && job->node != lastNode) {
|
1996-10-06 02:35:38 +00:00
|
|
|
MESSAGE(out, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = job->node;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(out, "*** Continued\n");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!(job->flags & JOB_CONTINUING)) {
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Warning: process %d was not continuing.\n", job->pid));
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifdef notdef
|
|
|
|
/*
|
|
|
|
* We don't really want to restart a job from scratch just
|
|
|
|
* because it continued, especially not without killing the
|
|
|
|
* continuing process! That's why this is ifdef'ed out.
|
|
|
|
* FD - 9/17/90
|
|
|
|
*/
|
|
|
|
JobRestart(job);
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
job->flags &= ~JOB_CONTINUING;
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_AtEnd(jobs, job);
|
1996-10-06 02:35:38 +00:00
|
|
|
nJobs += 1;
|
2004-11-05 11:41:36 +00:00
|
|
|
DEBUGF(JOB, ("Process %d is continuing locally.\n", job->pid));
|
1996-10-06 02:35:38 +00:00
|
|
|
if (nJobs == maxJobs) {
|
|
|
|
jobFull = TRUE;
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Job queue is full.\n"));
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fflush(out);
|
1996-10-06 02:35:38 +00:00
|
|
|
return;
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
if (usePipes && job->node != lastNode) {
|
1996-10-06 02:35:38 +00:00
|
|
|
MESSAGE(out, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = job->node;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(out, "*** Signal %d\n", WTERMSIG(*status));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
fflush(out);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now handle the -B-mode stuff. If the beast still isn't finished,
|
|
|
|
* try and restart the job on the next command. If JobStart says it's
|
|
|
|
* ok, it's ok. If there's an error, this puppy is done.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (compatMake && (WIFEXITED(*status) &&
|
|
|
|
!Lst_IsAtEnd(job->node->commands))) {
|
|
|
|
switch (JobStart(job->node, job->flags & JOB_IGNDOTS, job)) {
|
|
|
|
case JOB_RUNNING:
|
|
|
|
done = FALSE;
|
|
|
|
break;
|
|
|
|
case JOB_ERROR:
|
|
|
|
done = TRUE;
|
|
|
|
W_SETEXITSTATUS(status, 1);
|
|
|
|
break;
|
|
|
|
case JOB_FINISHED:
|
|
|
|
/*
|
|
|
|
* If we got back a JOB_FINISHED code, JobStart has already
|
|
|
|
* called Make_Update and freed the job descriptor. We set
|
|
|
|
* done to false here to avoid fake cycles and double frees.
|
|
|
|
* JobStart needs to do the update so we can proceed up the
|
|
|
|
* graph when given the -n flag..
|
|
|
|
*/
|
|
|
|
done = FALSE;
|
|
|
|
break;
|
2002-09-28 20:03:26 +00:00
|
|
|
default:
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
done = TRUE;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (done &&
|
|
|
|
(aborting != ABORT_ERROR) &&
|
|
|
|
(aborting != ABORT_INTERRUPT) &&
|
1996-10-06 02:35:38 +00:00
|
|
|
(*status == 0))
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* As long as we aren't aborting and the job didn't return a non-zero
|
|
|
|
* status that we shouldn't ignore, we call Make_Update to update
|
|
|
|
* the parents. In addition, any saved commands for the node are placed
|
|
|
|
* on the .END target.
|
|
|
|
*/
|
2000-12-02 18:58:01 +00:00
|
|
|
if (job->tailCmds != NULL) {
|
1996-10-06 02:35:38 +00:00
|
|
|
Lst_ForEachFrom(job->node->commands, job->tailCmds,
|
2004-12-01 10:29:20 +00:00
|
|
|
JobSaveCommand, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
job->node->made = MADE;
|
1996-10-06 02:35:38 +00:00
|
|
|
Make_Update(job->node);
|
2000-12-02 20:24:42 +00:00
|
|
|
free(job);
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (*status != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
errors += 1;
|
2000-12-02 20:24:42 +00:00
|
|
|
free(job);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
JobRestartJobs();
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set aborting if any error.
|
|
|
|
*/
|
|
|
|
if (errors && !keepgoing && (aborting != ABORT_INTERRUPT)) {
|
|
|
|
/*
|
|
|
|
* If we found any errors in this batch of children and the -k flag
|
|
|
|
* wasn't given, we set the aborting flag so no more jobs get
|
|
|
|
* started.
|
|
|
|
*/
|
|
|
|
aborting = ABORT_ERROR;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2000-11-19 12:04:12 +00:00
|
|
|
if ((aborting == ABORT_ERROR) && Job_Empty())
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If we are aborting and the job table is now empty, we finish.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
Finish(errors);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_Touch --
|
|
|
|
* Touch the given target. Called by JobStart when the -t flag was
|
2002-10-09 03:42:10 +00:00
|
|
|
* given. Prints messages unless told to be silent.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The data modification of the file is changed. In addition, if the
|
|
|
|
* file did not exist, it is created.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_Touch(GNode *gn, Boolean silent)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int streamID; /* ID of stream opened to do the touch */
|
1996-10-06 02:35:38 +00:00
|
|
|
struct utimbuf times; /* Times for utime() call */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
if (gn->type & (OP_JOIN | OP_USE | OP_EXEC | OP_OPTIONAL)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* .JOIN, .USE, .ZEROTIME and .OPTIONAL targets are "virtual" targets
|
|
|
|
* and, as such, shouldn't really be created.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!silent) {
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "touch %s\n", gn->name);
|
|
|
|
fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (noExecute) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gn->type & OP_ARCHV) {
|
1996-10-06 02:35:38 +00:00
|
|
|
Arch_Touch(gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else if (gn->type & OP_LIB) {
|
1996-10-06 02:35:38 +00:00
|
|
|
Arch_TouchLib(gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
char *file = gn->path ? gn->path : gn->name;
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
times.actime = times.modtime = now;
|
|
|
|
if (utime(file, ×) < 0){
|
|
|
|
streamID = open(file, O_RDWR | O_CREAT, 0666);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (streamID >= 0) {
|
|
|
|
char c;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read and write a byte to the file to change the
|
|
|
|
* modification time, then close the file.
|
|
|
|
*/
|
|
|
|
if (read(streamID, &c, 1) == 1) {
|
2004-11-30 17:46:29 +00:00
|
|
|
lseek(streamID, (off_t)0, SEEK_SET);
|
|
|
|
write(streamID, &c, 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
close(streamID);
|
1996-10-06 02:35:38 +00:00
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "*** couldn't touch %s: %s",
|
1996-10-06 02:35:38 +00:00
|
|
|
file, strerror(errno));
|
2004-11-30 17:46:29 +00:00
|
|
|
fflush(stdout);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_CheckCommands --
|
1995-05-30 06:41:30 +00:00
|
|
|
* Make sure the given node has all the commands it needs.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if the commands list is/was ok.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The node will have commands from the .DEFAULT rule added to it
|
|
|
|
* if it needs them.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Boolean
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (OP_NOP(gn->type) && Lst_IsEmpty(gn->commands) &&
|
1994-05-27 12:33:43 +00:00
|
|
|
(gn->type & OP_LIB) == 0) {
|
|
|
|
/*
|
|
|
|
* No commands. Look for .DEFAULT rule from which we might infer
|
1995-05-30 06:41:30 +00:00
|
|
|
* commands
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2000-12-02 18:58:01 +00:00
|
|
|
if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands)) {
|
1995-01-23 21:03:17 +00:00
|
|
|
char *p1;
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Make only looks for a .DEFAULT if the node was never the
|
|
|
|
* target of an operator, so that's what we do too. If
|
|
|
|
* a .DEFAULT was given, we substitute its commands for gn's
|
|
|
|
* commands and set the IMPSRC variable to be the target's name
|
|
|
|
* The DEFAULT node acts like a transformation rule, in that
|
|
|
|
* gn also inherits any attributes or sources attached to
|
|
|
|
* .DEFAULT itself.
|
|
|
|
*/
|
|
|
|
Make_HandleUse(DEFAULT, gn);
|
1996-10-06 02:35:38 +00:00
|
|
|
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn);
|
2002-10-23 23:16:43 +00:00
|
|
|
free(p1);
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (Dir_MTime(gn) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* The node wasn't the target of an operator we have no .DEFAULT
|
|
|
|
* rule to go on and the target doesn't already exist. There's
|
|
|
|
* nothing more we can do for this branch. If the -k flag wasn't
|
|
|
|
* given, we stop in our tracks, otherwise we just don't update
|
1995-05-30 06:41:30 +00:00
|
|
|
* this node's parents so they never get examined.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
static const char msg[] = "make: don't know how to make";
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (gn->type & OP_OPTIONAL) {
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "%s %s(ignored)\n", msg, gn->name);
|
|
|
|
fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else if (keepgoing) {
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "%s %s(continuing)\n", msg, gn->name);
|
|
|
|
fflush(stdout);
|
|
|
|
return (FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
1998-04-28 05:08:10 +00:00
|
|
|
#if OLD_JOKE
|
|
|
|
if (strcmp(gn->name,"love") == 0)
|
|
|
|
(*abortProc)("Not war.");
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
(*abortProc)("%s %s. Stop", msg, gn->name);
|
2004-11-30 17:46:29 +00:00
|
|
|
return (FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (TRUE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobExec --
|
|
|
|
* Execute the shell for the given job. Called from JobStart and
|
|
|
|
* JobRestart.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A shell is executed, outputs is altered and the Job structure added
|
|
|
|
* to the job table.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobExec(Job *job, char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int cpid; /* ID of new child */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
int i;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-05 11:41:36 +00:00
|
|
|
DEBUGF(JOB, ("Running %s\n", job->node->name));
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("\tCommand: "));
|
1996-10-06 02:35:38 +00:00
|
|
|
for (i = 0; argv[i] != NULL; i++) {
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("%s ", argv[i]));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("\n"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if ((lastNode != job->node) && (job->flags & JOB_FIRST) &&
|
1996-10-06 02:35:38 +00:00
|
|
|
!(job->flags & JOB_SILENT)) {
|
|
|
|
MESSAGE(stdout, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = job->node;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if ((cpid = vfork()) == -1) {
|
|
|
|
Punt("Cannot fork");
|
1994-05-27 12:33:43 +00:00
|
|
|
} else if (cpid == 0) {
|
|
|
|
|
2004-11-12 08:58:07 +00:00
|
|
|
if (fifoFd >= 0)
|
|
|
|
close(fifoFd);
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Must duplicate the input stream down to the child's input and
|
|
|
|
* reset it to the beginning (again). Since the stream was marked
|
|
|
|
* close-on-exec, we must clear that bit in the new input.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (dup2(FILENO(job->cmdFILE), 0) == -1)
|
|
|
|
Punt("Cannot dup2: %s", strerror(errno));
|
2004-11-30 17:46:29 +00:00
|
|
|
fcntl(0, F_SETFD, 0);
|
|
|
|
lseek(0, (off_t)0, SEEK_SET);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (usePipes) {
|
|
|
|
/*
|
|
|
|
* Set up the child's output to be routed through the pipe
|
|
|
|
* we've created for it.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (dup2(job->outPipe, 1) == -1)
|
|
|
|
Punt("Cannot dup2: %s", strerror(errno));
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We're capturing output in a file, so we duplicate the
|
|
|
|
* descriptor to the temporary file into the standard
|
|
|
|
* output.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (dup2(job->outFd, 1) == -1)
|
|
|
|
Punt("Cannot dup2: %s", strerror(errno));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The output channels are marked close on exec. This bit was
|
|
|
|
* duplicated by the dup2 (on some systems), so we have to clear
|
|
|
|
* it before routing the shell's error output to the same place as
|
|
|
|
* its standard output.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
fcntl(1, F_SETFD, 0);
|
1996-10-06 02:35:38 +00:00
|
|
|
if (dup2(1, 2) == -1)
|
|
|
|
Punt("Cannot dup2: %s", strerror(errno));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#ifdef USE_PGRP
|
|
|
|
/*
|
|
|
|
* We want to switch the child into a different process family so
|
|
|
|
* we can kill it and all its descendants in one fell swoop,
|
|
|
|
* by killing its process family, but not commit suicide.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
# if defined(SYSV)
|
2004-11-30 17:46:29 +00:00
|
|
|
setsid();
|
1996-10-06 02:35:38 +00:00
|
|
|
# else
|
2004-11-30 17:46:29 +00:00
|
|
|
setpgid(0, getpid());
|
1996-10-06 02:35:38 +00:00
|
|
|
# endif
|
|
|
|
#endif /* USE_PGRP */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
execv(shellPath, argv);
|
1996-10-06 02:35:38 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
write(STDERR_FILENO, "Could not execute shell\n",
|
1996-10-06 02:35:38 +00:00
|
|
|
sizeof("Could not execute shell"));
|
|
|
|
_exit(1);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
job->pid = cpid;
|
|
|
|
|
|
|
|
if (usePipes && (job->flags & JOB_FIRST) ) {
|
|
|
|
/*
|
|
|
|
* The first time a job is run for a node, we set the current
|
|
|
|
* position in the buffer to the beginning and mark another
|
|
|
|
* stream to watch in the outputs mask
|
|
|
|
*/
|
2002-10-04 20:30:03 +00:00
|
|
|
#ifdef USE_KQUEUE
|
|
|
|
struct kevent kev[2];
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
job->curPos = 0;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-04 12:57:41 +00:00
|
|
|
#if defined(USE_KQUEUE)
|
2002-10-04 20:30:03 +00:00
|
|
|
EV_SET(&kev[0], job->inPipe, EVFILT_READ, EV_ADD, 0, 0, job);
|
|
|
|
EV_SET(&kev[1], job->pid, EVFILT_PROC, EV_ADD | EV_ONESHOT,
|
|
|
|
NOTE_EXIT, 0, NULL);
|
|
|
|
if (kevent(kqfd, kev, 2, NULL, 0, NULL) != 0) {
|
|
|
|
/* kevent() will fail if the job is already finished */
|
2004-04-20 22:04:12 +00:00
|
|
|
if (errno != EINTR && errno != EBADF && errno != ESRCH)
|
2002-10-04 20:30:03 +00:00
|
|
|
Punt("kevent: %s", strerror(errno));
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
#else
|
|
|
|
FD_SET(job->inPipe, &outputs);
|
2004-11-04 12:57:41 +00:00
|
|
|
#endif /* USE_KQUEUE */
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-11-05 11:41:36 +00:00
|
|
|
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
|
2004-11-30 17:46:29 +00:00
|
|
|
fclose(job->cmdFILE);
|
2004-11-05 11:41:36 +00:00
|
|
|
job->cmdFILE = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now the job is actually running, add it to the table.
|
|
|
|
*/
|
|
|
|
nJobs += 1;
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_AtEnd(jobs, job);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (nJobs == maxJobs) {
|
|
|
|
jobFull = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobMakeArgv --
|
|
|
|
* Create the argv needed to execute the shell for a given job.
|
1995-05-30 06:41:30 +00:00
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobMakeArgv(Job *job, char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
static char args[10]; /* For merged arguments */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
argv[0] = shellName;
|
|
|
|
argc = 1;
|
|
|
|
|
|
|
|
if ((commandShell->exit && (*commandShell->exit != '-')) ||
|
|
|
|
(commandShell->echo && (*commandShell->echo != '-')))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* At least one of the flags doesn't have a minus before it, so
|
|
|
|
* merge them together. Have to do this because the *(&(@*#*&#$#
|
|
|
|
* Bourne shell thinks its second argument is a file to source.
|
|
|
|
* Grrrr. Note the ten-character limitation on the combined arguments.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
sprintf(args, "-%s%s",
|
1994-05-27 12:33:43 +00:00
|
|
|
((job->flags & JOB_IGNERR) ? "" :
|
|
|
|
(commandShell->exit ? commandShell->exit : "")),
|
|
|
|
((job->flags & JOB_SILENT) ? "" :
|
|
|
|
(commandShell->echo ? commandShell->echo : "")));
|
|
|
|
|
|
|
|
if (args[1]) {
|
|
|
|
argv[argc] = args;
|
|
|
|
argc++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(job->flags & JOB_IGNERR) && commandShell->exit) {
|
|
|
|
argv[argc] = commandShell->exit;
|
|
|
|
argc++;
|
|
|
|
}
|
|
|
|
if (!(job->flags & JOB_SILENT) && commandShell->echo) {
|
|
|
|
argv[argc] = commandShell->echo;
|
|
|
|
argc++;
|
|
|
|
}
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
argv[argc] = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobRestart --
|
1995-05-30 06:41:30 +00:00
|
|
|
* Restart a job that stopped for some reason.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* jobFull will be set if the job couldn't be run.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobRestart(Job *job)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1996-10-06 02:35:38 +00:00
|
|
|
|
2004-11-05 11:41:36 +00:00
|
|
|
if (job->flags & JOB_RESTART) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Set up the control arguments to the shell. This is based on the
|
|
|
|
* flags set earlier for this job. If the JOB_IGNERR flag is clear,
|
|
|
|
* the 'exit' flag of the commandShell is used to cause it to exit
|
|
|
|
* upon receiving an error. If the JOB_SILENT flag is clear, the
|
|
|
|
* 'echo' flag of the commandShell is used to get it to start echoing
|
1995-05-30 06:41:30 +00:00
|
|
|
* as soon as it starts processing commands.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
char *argv[4];
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
JobMakeArgv(job, argv);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Restarting %s...", job->node->name));
|
2004-11-11 12:52:16 +00:00
|
|
|
if (((nJobs >= maxJobs) && !(job->flags & JOB_SPECIAL))) {
|
2004-11-04 12:57:41 +00:00
|
|
|
/*
|
|
|
|
* Can't be exported and not allowed to run locally -- put it
|
|
|
|
* back on the hold queue and mark the table full
|
|
|
|
*/
|
|
|
|
DEBUGF(JOB, ("holding\n"));
|
2004-11-30 17:46:29 +00:00
|
|
|
Lst_AtFront(stoppedJobs, (void *)job);
|
2004-11-04 12:57:41 +00:00
|
|
|
jobFull = TRUE;
|
|
|
|
DEBUGF(JOB, ("Job queue is full.\n"));
|
|
|
|
return;
|
|
|
|
} else {
|
1996-10-06 02:35:38 +00:00
|
|
|
/*
|
2004-11-04 12:57:41 +00:00
|
|
|
* Job may be run locally.
|
1996-10-06 02:35:38 +00:00
|
|
|
*/
|
2004-11-04 12:57:41 +00:00
|
|
|
DEBUGF(JOB, ("running locally\n"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
JobExec(job, argv);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The job has stopped and needs to be restarted. Why it stopped,
|
|
|
|
* we don't know...
|
|
|
|
*/
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Resuming %s...", job->node->name));
|
2004-11-11 12:52:16 +00:00
|
|
|
if (((nJobs < maxJobs) ||
|
1996-10-06 02:35:38 +00:00
|
|
|
((job->flags & JOB_SPECIAL) &&
|
2004-11-11 12:52:16 +00:00
|
|
|
(maxJobs == 0))) &&
|
1996-10-06 02:35:38 +00:00
|
|
|
(nJobs != maxJobs))
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
/*
|
2004-11-05 11:41:36 +00:00
|
|
|
* If we haven't reached the concurrency limit already (or the
|
2004-11-11 12:52:16 +00:00
|
|
|
* job must be run and maxJobs is 0), it's ok to resume it.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
Boolean error;
|
1996-10-06 02:35:38 +00:00
|
|
|
int status;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-04 12:57:41 +00:00
|
|
|
error = (KILL(job->pid, SIGCONT) != 0);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
/*
|
|
|
|
* Make sure the user knows we've continued the beast and
|
|
|
|
* actually put the thing in the job table.
|
|
|
|
*/
|
|
|
|
job->flags |= JOB_CONTINUING;
|
1996-10-06 02:35:38 +00:00
|
|
|
W_SETTERMSIG(&status, SIGCONT);
|
|
|
|
JobFinish(job, &status);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
job->flags &= ~(JOB_RESUME|JOB_CONTINUING);
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("done\n"));
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
Error("couldn't resume %s: %s",
|
|
|
|
job->node->name, strerror(errno));
|
1996-10-06 02:35:38 +00:00
|
|
|
status = 0;
|
|
|
|
W_SETEXITSTATUS(&status, 1);
|
|
|
|
JobFinish(job, &status);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Job cannot be restarted. Mark the table as full and
|
|
|
|
* place the job back on the list of stopped jobs.
|
|
|
|
*/
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("table full\n"));
|
2004-11-30 17:46:29 +00:00
|
|
|
Lst_AtFront(stoppedJobs, (void *)job);
|
1994-05-27 12:33:43 +00:00
|
|
|
jobFull = TRUE;
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Job queue is full.\n"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobStart --
|
|
|
|
* Start a target-creation process going for the target described
|
1995-05-30 06:41:30 +00:00
|
|
|
* by the graph node gn.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* JOB_ERROR if there was an error in the commands, JOB_FINISHED
|
|
|
|
* if there isn't actually anything left to do for the job and
|
|
|
|
* JOB_RUNNING if the job has been started.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A new Job node is created and added to the list of running
|
|
|
|
* jobs. PMake is forked and a child shell created.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
JobStart(GNode *gn, int flags, Job *previous)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-04-13 10:05:30 +00:00
|
|
|
Job *job; /* new job descriptor */
|
1994-05-27 12:33:43 +00:00
|
|
|
char *argv[4]; /* Argument vector to shell */
|
|
|
|
Boolean cmdsOK; /* true if the nodes commands were all right */
|
|
|
|
Boolean noExec; /* Set true if we decide not to run the job */
|
2000-01-17 06:43:41 +00:00
|
|
|
int tfd; /* File descriptor for temp file */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-12 07:57:17 +00:00
|
|
|
if (interrupted) {
|
|
|
|
JobPassSig(interrupted);
|
|
|
|
return (JOB_ERROR);
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (previous != NULL) {
|
2004-11-05 11:41:36 +00:00
|
|
|
previous->flags &= ~(JOB_FIRST|JOB_IGNERR|JOB_SILENT);
|
1994-05-27 12:33:43 +00:00
|
|
|
job = previous;
|
|
|
|
} else {
|
2004-12-01 10:29:20 +00:00
|
|
|
job = emalloc(sizeof(Job));
|
1994-05-27 12:33:43 +00:00
|
|
|
flags |= JOB_FIRST;
|
|
|
|
}
|
|
|
|
|
|
|
|
job->node = gn;
|
2000-12-02 18:58:01 +00:00
|
|
|
job->tailCmds = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the initial value of the flags for this job based on the global
|
|
|
|
* ones and the node's attributes... Any flags supplied by the caller
|
|
|
|
* are also added to the field.
|
|
|
|
*/
|
|
|
|
job->flags = 0;
|
1996-10-06 02:35:38 +00:00
|
|
|
if (Targ_Ignore(gn)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
job->flags |= JOB_IGNERR;
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (Targ_Silent(gn)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
job->flags |= JOB_SILENT;
|
|
|
|
}
|
|
|
|
job->flags |= flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the commands now so any attributes from .DEFAULT have a chance
|
|
|
|
* to migrate to the node
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!compatMake && job->flags & JOB_FIRST) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cmdsOK = Job_CheckCommands(gn, Error);
|
|
|
|
} else {
|
|
|
|
cmdsOK = TRUE;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If the -n flag wasn't given, we open up OUR (not the child's)
|
|
|
|
* temporary file to stuff commands in it. The thing is rd/wr so we don't
|
|
|
|
* need to reopen it to feed it to the shell. If the -n flag *was* given,
|
|
|
|
* we just set the file to be stdout. Cute, huh?
|
|
|
|
*/
|
|
|
|
if ((gn->type & OP_MAKE) || (!noExecute && !touchFlag)) {
|
|
|
|
/*
|
|
|
|
* We're serious here, but if the commands were bogus, we're
|
|
|
|
* also dead...
|
|
|
|
*/
|
|
|
|
if (!cmdsOK) {
|
|
|
|
DieHorribly();
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
strcpy(tfile, TMPPAT);
|
2000-11-19 12:04:12 +00:00
|
|
|
if ((tfd = mkstemp(tfile)) == -1)
|
|
|
|
Punt("Cannot create temp file: %s", strerror(errno));
|
|
|
|
job->cmdFILE = fdopen(tfd, "w+");
|
|
|
|
eunlink(tfile);
|
1996-10-06 02:35:38 +00:00
|
|
|
if (job->cmdFILE == NULL) {
|
2000-11-19 12:04:12 +00:00
|
|
|
close(tfd);
|
|
|
|
Punt("Could not open %s", tfile);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fcntl(FILENO(job->cmdFILE), F_SETFD, 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Send the commands to the command file, flush all its buffers then
|
|
|
|
* rewind and remove the thing.
|
|
|
|
*/
|
|
|
|
noExec = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* used to be backwards; replace when start doing multiple commands
|
|
|
|
* per shell.
|
|
|
|
*/
|
|
|
|
if (compatMake) {
|
|
|
|
/*
|
|
|
|
* Be compatible: If this is the first time for this node,
|
|
|
|
* verify its commands are ok and open the commands list for
|
|
|
|
* sequential access by later invocations of JobStart.
|
|
|
|
* Once that is done, we take the next command off the list
|
|
|
|
* and print it to the command file. If the command was an
|
|
|
|
* ellipsis, note that there's nothing more to execute.
|
|
|
|
*/
|
|
|
|
if ((job->flags&JOB_FIRST) && (Lst_Open(gn->commands) != SUCCESS)){
|
|
|
|
cmdsOK = FALSE;
|
|
|
|
} else {
|
1996-10-06 02:35:38 +00:00
|
|
|
LstNode ln = Lst_Next(gn->commands);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
if ((ln == NULL) ||
|
2004-12-01 10:29:20 +00:00
|
|
|
JobPrintCommand(Lst_Datum(ln), job))
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
noExec = TRUE;
|
1996-10-06 02:35:38 +00:00
|
|
|
Lst_Close(gn->commands);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (noExec && !(job->flags & JOB_FIRST)) {
|
|
|
|
/*
|
|
|
|
* If we're not going to execute anything, the job
|
|
|
|
* is done and we need to close down the various
|
|
|
|
* file descriptors we've opened for output, then
|
|
|
|
* call JobDoOutput to catch the final characters or
|
|
|
|
* send the file to the screen... Note that the i/o streams
|
|
|
|
* are only open if this isn't the first job.
|
|
|
|
* Note also that this could not be done in
|
|
|
|
* Job_CatchChildren b/c it wasn't clear if there were
|
|
|
|
* more commands to execute or not...
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
JobClose(job);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We can do all the commands at once. hooray for sanity
|
|
|
|
*/
|
|
|
|
numCommands = 0;
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_ForEach(gn->commands, JobPrintCommand, job);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If we didn't print out any commands to the shell script,
|
|
|
|
* there's not much point in executing the shell, is there?
|
|
|
|
*/
|
|
|
|
if (numCommands == 0) {
|
|
|
|
noExec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (noExecute) {
|
|
|
|
/*
|
|
|
|
* Not executing anything -- just print all the commands to stdout
|
|
|
|
* in one fell swoop. This will still set up job->tailCmds correctly.
|
|
|
|
*/
|
|
|
|
if (lastNode != gn) {
|
1996-10-06 02:35:38 +00:00
|
|
|
MESSAGE(stdout, gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = gn;
|
|
|
|
}
|
|
|
|
job->cmdFILE = stdout;
|
|
|
|
/*
|
|
|
|
* Only print the commands if they're ok, but don't die if they're
|
|
|
|
* not -- just let the user know they're bad and keep going. It
|
|
|
|
* doesn't do any harm in this case and may do some good.
|
|
|
|
*/
|
|
|
|
if (cmdsOK) {
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_ForEach(gn->commands, JobPrintCommand, job);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Don't execute the shell, thank you.
|
|
|
|
*/
|
|
|
|
noExec = TRUE;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Just touch the target and note that no shell should be executed.
|
|
|
|
* Set cmdFILE to stdout to make life easier. Check the commands, too,
|
|
|
|
* but don't die if they're no good -- it does no harm to keep working
|
|
|
|
* up the graph.
|
|
|
|
*/
|
|
|
|
job->cmdFILE = stdout;
|
2004-12-01 10:29:20 +00:00
|
|
|
Job_Touch(gn, job->flags & JOB_SILENT);
|
1994-05-27 12:33:43 +00:00
|
|
|
noExec = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* If we're not supposed to execute a shell, don't.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
if (noExec) {
|
|
|
|
/*
|
|
|
|
* Unlink and close the command file if we opened one
|
|
|
|
*/
|
|
|
|
if (job->cmdFILE != stdout) {
|
1996-10-06 02:35:38 +00:00
|
|
|
if (job->cmdFILE != NULL)
|
2004-11-30 17:46:29 +00:00
|
|
|
fclose(job->cmdFILE);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only want to work our way up the graph if we aren't here because
|
|
|
|
* the commands for the job were no good.
|
|
|
|
*/
|
|
|
|
if (cmdsOK) {
|
|
|
|
if (aborting == 0) {
|
2000-12-02 18:58:01 +00:00
|
|
|
if (job->tailCmds != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
Lst_ForEachFrom(job->node->commands, job->tailCmds,
|
2004-12-01 10:29:20 +00:00
|
|
|
JobSaveCommand, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-06-04 05:48:57 +00:00
|
|
|
job->node->made = MADE;
|
1994-05-27 12:33:43 +00:00
|
|
|
Make_Update(job->node);
|
|
|
|
}
|
2000-12-02 20:24:42 +00:00
|
|
|
free(job);
|
1994-05-27 12:33:43 +00:00
|
|
|
return(JOB_FINISHED);
|
|
|
|
} else {
|
2000-12-02 20:24:42 +00:00
|
|
|
free(job);
|
1994-05-27 12:33:43 +00:00
|
|
|
return(JOB_ERROR);
|
|
|
|
}
|
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
fflush(job->cmdFILE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the control arguments to the shell. This is based on the flags
|
|
|
|
* set earlier for this job.
|
|
|
|
*/
|
|
|
|
JobMakeArgv(job, argv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're using pipes to catch output, create the pipe by which we'll
|
|
|
|
* get the shell's output. If we're using files, print out that we're
|
1999-08-22 05:28:13 +00:00
|
|
|
* starting a job and then set up its temporary-file name.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!compatMake || (job->flags & JOB_FIRST)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (usePipes) {
|
|
|
|
int fd[2];
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (pipe(fd) == -1)
|
|
|
|
Punt("Cannot create pipe: %s", strerror(errno));
|
1994-05-27 12:33:43 +00:00
|
|
|
job->inPipe = fd[0];
|
|
|
|
job->outPipe = fd[1];
|
2004-11-30 17:46:29 +00:00
|
|
|
fcntl(job->inPipe, F_SETFD, 1);
|
|
|
|
fcntl(job->outPipe, F_SETFD, 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "Remaking `%s'\n", gn->name);
|
|
|
|
fflush(stdout);
|
|
|
|
strcpy(job->outFile, TMPPAT);
|
1999-08-22 05:28:13 +00:00
|
|
|
if ((job->outFd = mkstemp(job->outFile)) == -1)
|
|
|
|
Punt("cannot create temp file: %s", strerror(errno));
|
2004-11-30 17:46:29 +00:00
|
|
|
fcntl(job->outFd, F_SETFD, 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-11 12:52:16 +00:00
|
|
|
if ((nJobs >= maxJobs) && !(job->flags & JOB_SPECIAL) && (maxJobs != 0)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2004-11-05 11:41:36 +00:00
|
|
|
* We've hit the limit of concurrency, so put the job on hold until
|
|
|
|
* some other job finishes. Note that the special jobs (.BEGIN,
|
|
|
|
* .INTERRUPT and .END) may be run even when the limit has been reached
|
2004-11-11 12:52:16 +00:00
|
|
|
* (e.g. when maxJobs == 0).
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
jobFull = TRUE;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Can only run job locally.\n"));
|
1994-05-27 12:33:43 +00:00
|
|
|
job->flags |= JOB_RESTART;
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_AtEnd(stoppedJobs, job);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-11-11 12:52:16 +00:00
|
|
|
if (nJobs >= maxJobs) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If we're running this job locally as a special case (see above),
|
|
|
|
* at least say the table is full.
|
|
|
|
*/
|
|
|
|
jobFull = TRUE;
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Local job queue is full.\n"));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
JobExec(job, argv);
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (JOB_RUNNING);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
static char *
|
2002-10-09 03:42:10 +00:00
|
|
|
JobOutput(Job *job, char *cp, char *endp, int msg)
|
1996-10-06 02:35:38 +00:00
|
|
|
{
|
2002-04-13 10:05:30 +00:00
|
|
|
char *ecp;
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
if (commandShell->noPrint) {
|
2002-10-28 23:33:57 +00:00
|
|
|
ecp = strstr(cp, commandShell->noPrint);
|
1996-10-06 02:35:38 +00:00
|
|
|
while (ecp != NULL) {
|
|
|
|
if (cp != ecp) {
|
|
|
|
*ecp = '\0';
|
|
|
|
if (msg && job->node != lastNode) {
|
|
|
|
MESSAGE(stdout, job->node);
|
|
|
|
lastNode = job->node;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The only way there wouldn't be a newline after
|
|
|
|
* this line is if it were the last in the buffer.
|
|
|
|
* however, since the non-printable comes after it,
|
|
|
|
* there must be a newline, so we don't print one.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "%s", cp);
|
|
|
|
fflush(stdout);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
cp = ecp + commandShell->noPLen;
|
|
|
|
if (cp != endp) {
|
|
|
|
/*
|
|
|
|
* Still more to print, look again after skipping
|
|
|
|
* the whitespace following the non-printable
|
|
|
|
* command....
|
|
|
|
*/
|
|
|
|
cp++;
|
|
|
|
while (*cp == ' ' || *cp == '\t' || *cp == '\n') {
|
|
|
|
cp++;
|
|
|
|
}
|
2002-10-28 23:33:57 +00:00
|
|
|
ecp = strstr(cp, commandShell->noPrint);
|
1996-10-06 02:35:38 +00:00
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
return (cp);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (cp);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobDoOutput --
|
|
|
|
* This function is called at different times depending on
|
|
|
|
* whether the user has specified that output is to be collected
|
|
|
|
* via pipes or temporary files. In the former case, we are called
|
|
|
|
* whenever there is something to read on the pipe. We collect more
|
|
|
|
* output from the given job and store it in the job's outBuf. If
|
|
|
|
* this makes up a line, we print it tagged by the job's identifier,
|
|
|
|
* as necessary.
|
|
|
|
* If output has been collected in a temporary file, we open the
|
|
|
|
* file and read it line by line, transfering it to our own
|
|
|
|
* output channel until the file is empty. At which point we
|
|
|
|
* remove the temporary file.
|
|
|
|
* In both cases, however, we keep our figurative eye out for the
|
|
|
|
* 'noPrint' line for the shell from which the output came. If
|
|
|
|
* we recognize a line, we don't print it. If the command is not
|
|
|
|
* alone on the line (the character after it is not \0 or \n), we
|
|
|
|
* do print whatever follows it.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* curPos may be shifted as may the contents of outBuf.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
STATIC void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobDoOutput(Job *job, Boolean finish)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
Boolean gotNL = FALSE; /* true if got a newline */
|
1996-10-06 02:35:38 +00:00
|
|
|
Boolean fbuf; /* true if our buffer filled up */
|
2002-04-13 10:05:30 +00:00
|
|
|
int nr; /* number of bytes read */
|
|
|
|
int i; /* auxiliary index into outBuf */
|
|
|
|
int max; /* limit for i (end of current data) */
|
1994-05-27 12:33:43 +00:00
|
|
|
int nRead; /* (Temporary) number of bytes read */
|
|
|
|
|
|
|
|
FILE *oFILE; /* Stream pointer to shell's output file */
|
|
|
|
char inLine[132];
|
|
|
|
|
|
|
|
if (usePipes) {
|
|
|
|
/*
|
|
|
|
* Read as many bytes as will fit in the buffer.
|
|
|
|
*/
|
|
|
|
end_loop:
|
1996-10-06 02:35:38 +00:00
|
|
|
gotNL = FALSE;
|
|
|
|
fbuf = FALSE;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
nRead = read(job->inPipe, &job->outBuf[job->curPos],
|
1994-05-27 12:33:43 +00:00
|
|
|
JOB_BUFSIZE - job->curPos);
|
2004-11-12 07:57:17 +00:00
|
|
|
/*
|
|
|
|
* Check for interrupt here too, because the above read may block
|
|
|
|
* when the child process is stopped. In this case the interrupt
|
|
|
|
* will unblock it (we don't use SA_RESTART).
|
|
|
|
*/
|
|
|
|
if (interrupted)
|
|
|
|
JobPassSig(interrupted);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (nRead < 0) {
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("JobDoOutput(piperead)"));
|
1994-05-27 12:33:43 +00:00
|
|
|
nr = 0;
|
|
|
|
} else {
|
|
|
|
nr = nRead;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* 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
|
1995-05-30 06:41:30 +00:00
|
|
|
* TRUE.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
max = job->curPos + nr;
|
|
|
|
for (i = job->curPos + nr - 1; i >= job->curPos; i--) {
|
|
|
|
if (job->outBuf[i] == '\n') {
|
|
|
|
gotNL = TRUE;
|
|
|
|
break;
|
|
|
|
} else if (job->outBuf[i] == '\0') {
|
|
|
|
/*
|
|
|
|
* Why?
|
|
|
|
*/
|
|
|
|
job->outBuf[i] = ' ';
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!gotNL) {
|
|
|
|
job->curPos += nr;
|
|
|
|
if (job->curPos == JOB_BUFSIZE) {
|
|
|
|
/*
|
|
|
|
* If we've run out of buffer space, we have no choice
|
1995-05-30 06:41:30 +00:00
|
|
|
* but to print the stuff. sigh.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
fbuf = TRUE;
|
1994-05-27 12:33:43 +00:00
|
|
|
i = job->curPos;
|
|
|
|
}
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (gotNL || fbuf) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Need to send the output to the screen. Null terminate it
|
|
|
|
* first, overwriting the newline character if there was one.
|
|
|
|
* So long as the line isn't one we should filter (according
|
2001-02-18 10:43:53 +00:00
|
|
|
* to the shell description), we print the line, preceded
|
1994-05-27 12:33:43 +00:00
|
|
|
* by a target banner if this target isn't the same as the
|
|
|
|
* one for which we last printed something.
|
|
|
|
* The rest of the data in the buffer are then shifted down
|
1995-05-30 06:41:30 +00:00
|
|
|
* to the start of the buffer and curPos is set accordingly.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
job->outBuf[i] = '\0';
|
|
|
|
if (i >= job->curPos) {
|
1996-10-06 02:35:38 +00:00
|
|
|
char *cp;
|
|
|
|
|
|
|
|
cp = JobOutput(job, job->outBuf, &job->outBuf[i], FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There's still more in that thar 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 (job->node != lastNode) {
|
1996-10-06 02:35:38 +00:00
|
|
|
MESSAGE(stdout, job->node);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastNode = job->node;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "%s%s", cp, gotNL ? "\n" : "");
|
|
|
|
fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i < max - 1) {
|
|
|
|
/* shift the remaining characters down */
|
2004-11-30 17:46:29 +00:00
|
|
|
memcpy(job->outBuf, &job->outBuf[i + 1], max - (i + 1));
|
1994-05-27 12:33:43 +00:00
|
|
|
job->curPos = max - (i + 1);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We have written everything out, so we just start over
|
|
|
|
* from the start of the buffer. No copying. No nothing.
|
|
|
|
*/
|
|
|
|
job->curPos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (finish) {
|
|
|
|
/*
|
|
|
|
* If the finish flag is true, we must loop until we hit
|
1996-10-06 02:35:38 +00:00
|
|
|
* end-of-file on the pipe. This is guaranteed to happen
|
|
|
|
* eventually since the other end of the pipe is now closed
|
|
|
|
* (we closed it explicitly and the child has exited). When
|
|
|
|
* we do get an EOF, finish will be set FALSE and we'll fall
|
|
|
|
* through and out.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
goto end_loop;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We've been called to retrieve the output of the job from the
|
|
|
|
* temporary file where it's been squirreled away. This consists of
|
|
|
|
* opening the file, reading the output line by line, being sure not
|
|
|
|
* to print the noPrint line for the shell we used, then close and
|
|
|
|
* remove the temporary file. Very simple.
|
|
|
|
*
|
|
|
|
* Change to read in blocks and do FindSubString type things as for
|
|
|
|
* pipes? That would allow for "@echo -n..."
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
oFILE = fopen(job->outFile, "r");
|
|
|
|
if (oFILE != NULL) {
|
2004-12-01 10:29:20 +00:00
|
|
|
fprintf(stdout, "Results of making %s:\n", job->node->name);
|
|
|
|
fflush(stdout);
|
1996-10-06 02:35:38 +00:00
|
|
|
while (fgets(inLine, sizeof(inLine), oFILE) != NULL) {
|
2002-04-13 10:05:30 +00:00
|
|
|
char *cp, *endp, *oendp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
cp = inLine;
|
1996-10-06 02:35:38 +00:00
|
|
|
oendp = endp = inLine + strlen(inLine);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (endp[-1] == '\n') {
|
|
|
|
*--endp = '\0';
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
cp = JobOutput(job, inLine, endp, FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There's still more in that thar buffer. This time, though,
|
|
|
|
* we know there's no newline at the end, so we add one of
|
|
|
|
* our own free will.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "%s", cp);
|
|
|
|
fflush(stdout);
|
1996-10-06 02:35:38 +00:00
|
|
|
if (endp != oendp) {
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stdout, "\n");
|
|
|
|
fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-01 10:29:20 +00:00
|
|
|
fclose(oFILE);
|
|
|
|
eunlink(job->outFile);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_CatchChildren --
|
|
|
|
* Handle the exit of a child. Called from Make_Make.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* none.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The job descriptor is removed from the list of children.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* We do waits, blocking or not, according to the wisdom of our
|
|
|
|
* caller, until there are no more children to report. For each
|
|
|
|
* job, call JobFinish to finish things off. This will take care of
|
|
|
|
* putting jobs on the stoppedJobs queue.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_CatchChildren(Boolean block)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int pid; /* pid of dead child */
|
2002-04-13 10:05:30 +00:00
|
|
|
Job *job; /* job descriptor for dead child */
|
1994-05-27 12:33:43 +00:00
|
|
|
LstNode jnode; /* list element for finding job */
|
1996-10-06 02:35:38 +00:00
|
|
|
int status; /* Exit/termination status */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't even bother if we know there's no one around.
|
|
|
|
*/
|
2004-11-11 12:52:16 +00:00
|
|
|
if (nJobs == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-12 08:58:07 +00:00
|
|
|
for (;;) {
|
2004-11-30 17:46:29 +00:00
|
|
|
pid = waitpid((pid_t)-1, &status, (block ? 0 : WNOHANG) | WUNTRACED);
|
2004-11-12 08:58:07 +00:00
|
|
|
if (pid <= 0)
|
|
|
|
break;
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Process %d exited or stopped.\n", pid));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
jnode = Lst_Find(jobs, &pid, JobCmpPid);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
if (jnode == NULL) {
|
1996-10-06 02:35:38 +00:00
|
|
|
if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGCONT)) {
|
2004-12-01 10:29:20 +00:00
|
|
|
jnode = Lst_Find(stoppedJobs, &pid, JobCmpPid);
|
2000-12-02 18:58:01 +00:00
|
|
|
if (jnode == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
Error("Resumed child (%d) not in table", pid);
|
|
|
|
continue;
|
|
|
|
}
|
2004-12-01 10:29:20 +00:00
|
|
|
job = Lst_Datum(jnode);
|
2004-11-30 17:46:29 +00:00
|
|
|
Lst_Remove(stoppedJobs, jnode);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
1996-10-06 02:35:38 +00:00
|
|
|
Error("Child (%d) not in table?", pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2004-12-01 10:29:20 +00:00
|
|
|
job = Lst_Datum(jnode);
|
2004-11-30 17:46:29 +00:00
|
|
|
Lst_Remove(jobs, jnode);
|
1994-05-27 12:33:43 +00:00
|
|
|
nJobs -= 1;
|
2004-11-12 08:58:07 +00:00
|
|
|
if (fifoFd >= 0 && maxJobs > 1) {
|
|
|
|
write(fifoFd, "+", 1);
|
|
|
|
maxJobs--;
|
|
|
|
if (nJobs >= maxJobs)
|
|
|
|
jobFull = TRUE;
|
|
|
|
else
|
|
|
|
jobFull = FALSE;
|
|
|
|
} else {
|
|
|
|
DEBUGF(JOB, ("Job queue is no longer full.\n"));
|
|
|
|
jobFull = FALSE;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
JobFinish(job, &status);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-12 07:57:17 +00:00
|
|
|
if (interrupted)
|
|
|
|
JobPassSig(interrupted);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_CatchOutput --
|
|
|
|
* Catch the output from our children, if we're using
|
|
|
|
* pipes do so. Otherwise just block time until we get a
|
2004-11-30 17:46:29 +00:00
|
|
|
* signal(most likely a SIGCHLD) since there's no point in
|
1994-05-27 12:33:43 +00:00
|
|
|
* just spinning when there's nothing to do and the reaping
|
1995-05-30 06:41:30 +00:00
|
|
|
* of a child can wait for a while.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
1995-05-30 06:41:30 +00:00
|
|
|
* None
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Output is read from pipes if we're piping.
|
|
|
|
* -----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2004-11-12 08:58:07 +00:00
|
|
|
Job_CatchOutput(int flag)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int nfds;
|
2002-10-04 20:30:03 +00:00
|
|
|
#ifdef USE_KQUEUE
|
|
|
|
#define KEV_SIZE 4
|
|
|
|
struct kevent kev[KEV_SIZE];
|
|
|
|
int i;
|
|
|
|
#else
|
1994-05-27 12:33:43 +00:00
|
|
|
struct timeval timeout;
|
|
|
|
fd_set readfds;
|
2002-04-13 10:05:30 +00:00
|
|
|
LstNode ln;
|
|
|
|
Job *job;
|
2002-10-04 20:30:03 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (usePipes) {
|
2002-10-04 20:30:03 +00:00
|
|
|
#ifdef USE_KQUEUE
|
|
|
|
if ((nfds = kevent(kqfd, NULL, 0, kev, KEV_SIZE, NULL)) == -1) {
|
2004-04-20 22:04:12 +00:00
|
|
|
if (errno != EINTR)
|
|
|
|
Punt("kevent: %s", strerror(errno));
|
2004-11-12 07:57:17 +00:00
|
|
|
if (interrupted)
|
|
|
|
JobPassSig(interrupted);
|
2002-10-04 20:30:03 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < nfds; i++) {
|
|
|
|
if (kev[i].flags & EV_ERROR) {
|
|
|
|
warnc(kev[i].data, "kevent");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (kev[i].filter) {
|
|
|
|
case EVFILT_READ:
|
|
|
|
JobDoOutput(kev[i].udata, FALSE);
|
|
|
|
break;
|
|
|
|
case EVFILT_PROC:
|
|
|
|
/* Just wake up and let Job_CatchChildren() collect the
|
|
|
|
* terminated job. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
1994-05-27 12:33:43 +00:00
|
|
|
readfds = outputs;
|
|
|
|
timeout.tv_sec = SEL_SEC;
|
|
|
|
timeout.tv_usec = SEL_USEC;
|
2004-11-12 08:58:07 +00:00
|
|
|
if (flag && jobFull && fifoFd >= 0)
|
|
|
|
FD_SET(fifoFd, &readfds);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
nfds = select(FD_SETSIZE, &readfds, (fd_set *)NULL,
|
|
|
|
(fd_set *)NULL, &timeout);
|
2004-11-12 08:58:07 +00:00
|
|
|
if (nfds <= 0) {
|
2004-11-30 17:46:29 +00:00
|
|
|
if (interrupted)
|
2004-11-12 07:57:17 +00:00
|
|
|
JobPassSig(interrupted);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
2004-11-12 08:58:07 +00:00
|
|
|
}
|
|
|
|
if (fifoFd >= 0 && FD_ISSET(fifoFd, &readfds)) {
|
|
|
|
if (--nfds <= 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Lst_Open(jobs) == FAILURE) {
|
|
|
|
Punt("Cannot open job table");
|
|
|
|
}
|
|
|
|
while (nfds && (ln = Lst_Next(jobs)) != NULL) {
|
2004-12-01 10:29:20 +00:00
|
|
|
job = Lst_Datum(ln);
|
2004-11-12 08:58:07 +00:00
|
|
|
if (FD_ISSET(job->inPipe, &readfds)) {
|
|
|
|
JobDoOutput(job, FALSE);
|
|
|
|
nfds -= 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-12 08:58:07 +00:00
|
|
|
Lst_Close(jobs);
|
2002-10-04 20:30:03 +00:00
|
|
|
#endif /* !USE_KQUEUE */
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_Make --
|
|
|
|
* Start the creation of a target. Basically a front-end for
|
|
|
|
* JobStart used by the Make module.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Another job is started.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_Make(GNode *gn)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
|
|
|
JobStart(gn, 0, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-11-25 10:01:26 +00:00
|
|
|
/*
|
|
|
|
* JobCopyShell:
|
|
|
|
*
|
|
|
|
* Make a new copy of the shell structure including a copy of the strings
|
|
|
|
* in it. This also defaults some fields in case they are NULL.
|
|
|
|
*
|
|
|
|
* The function returns a pointer to the new shell structure otherwise.
|
|
|
|
*/
|
|
|
|
static Shell *
|
|
|
|
JobCopyShell(const Shell *osh)
|
|
|
|
{
|
|
|
|
Shell *nsh;
|
|
|
|
|
|
|
|
nsh = emalloc(sizeof(*nsh));
|
|
|
|
nsh->name = estrdup(osh->name);
|
|
|
|
|
|
|
|
if (osh->echoOff != NULL)
|
|
|
|
nsh->echoOff = estrdup(osh->echoOff);
|
|
|
|
else
|
|
|
|
nsh->echoOff = NULL;
|
|
|
|
if (osh->echoOn != NULL)
|
|
|
|
nsh->echoOn = estrdup(osh->echoOn);
|
|
|
|
else
|
|
|
|
nsh->echoOn = NULL;
|
|
|
|
nsh->hasEchoCtl = osh->hasEchoCtl;
|
|
|
|
|
|
|
|
if (osh->noPrint != NULL)
|
|
|
|
nsh->noPrint = estrdup(osh->noPrint);
|
|
|
|
else
|
|
|
|
nsh->noPrint = NULL;
|
|
|
|
nsh->noPLen = osh->noPLen;
|
|
|
|
|
|
|
|
nsh->hasErrCtl = osh->hasErrCtl;
|
|
|
|
if (osh->errCheck == NULL)
|
|
|
|
nsh->errCheck = estrdup("");
|
|
|
|
else
|
|
|
|
nsh->errCheck = estrdup(osh->errCheck);
|
|
|
|
if (osh->ignErr == NULL)
|
|
|
|
nsh->ignErr = estrdup("%s");
|
|
|
|
else
|
|
|
|
nsh->ignErr = estrdup(osh->ignErr);
|
|
|
|
|
|
|
|
if (osh->echo == NULL)
|
|
|
|
nsh->echo = estrdup("");
|
|
|
|
else
|
|
|
|
nsh->echo = estrdup(osh->echo);
|
|
|
|
|
|
|
|
if (osh->exit == NULL)
|
|
|
|
nsh->exit = estrdup("");
|
|
|
|
else
|
|
|
|
nsh->exit = estrdup(osh->exit);
|
|
|
|
|
|
|
|
return (nsh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JobFreeShell:
|
|
|
|
*
|
|
|
|
* Free a shell structure and all associated strings.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
JobFreeShell(Shell *sh)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sh != NULL) {
|
|
|
|
free(sh->name);
|
|
|
|
free(sh->echoOff);
|
|
|
|
free(sh->echoOn);
|
|
|
|
free(sh->noPrint);
|
|
|
|
free(sh->errCheck);
|
|
|
|
free(sh->ignErr);
|
|
|
|
free(sh->echo);
|
|
|
|
free(sh->exit);
|
|
|
|
free(sh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-23 21:34:41 +00:00
|
|
|
void
|
|
|
|
Shell_Init(void)
|
|
|
|
{
|
2004-11-25 10:01:26 +00:00
|
|
|
|
|
|
|
if (commandShell == NULL)
|
2004-11-30 15:35:51 +00:00
|
|
|
commandShell = JobMatchShell(shells[DEFSHELL].name);
|
2004-11-25 10:01:26 +00:00
|
|
|
|
2004-10-23 21:34:41 +00:00
|
|
|
if (shellPath == NULL) {
|
|
|
|
/*
|
|
|
|
* The user didn't specify a shell to use, so we are using the
|
|
|
|
* default one... Both the absolute path and the last component
|
|
|
|
* must be set. The last component is taken from the 'name' field
|
|
|
|
* of the default shell description pointed-to by commandShell.
|
|
|
|
* All default shells are located in _PATH_DEFSHELLDIR.
|
|
|
|
*/
|
|
|
|
shellName = commandShell->name;
|
|
|
|
shellPath = str_concat(_PATH_DEFSHELLDIR, shellName, STR_ADDSLASH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_Init --
|
2004-11-11 12:52:16 +00:00
|
|
|
* Initialize the process module, given a maximum number of jobs.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* lists and counters are initialized
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2004-11-11 12:52:16 +00:00
|
|
|
Job_Init(int maxproc)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
GNode *begin; /* node for commands to do at the very start */
|
2004-11-12 08:58:07 +00:00
|
|
|
const char *env;
|
2004-11-12 07:57:17 +00:00
|
|
|
struct sigaction sa;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
fifoFd = -1;
|
|
|
|
jobs = Lst_Init(FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
stoppedJobs = Lst_Init(FALSE);
|
2004-11-12 08:58:07 +00:00
|
|
|
env = getenv("MAKE_JOBS_FIFO");
|
|
|
|
|
|
|
|
if (env == NULL && maxproc > 1) {
|
|
|
|
/*
|
|
|
|
* We did not find the environment variable so we are the leader.
|
|
|
|
* Create the fifo, open it, write one char per allowed job into
|
|
|
|
* the pipe.
|
|
|
|
*/
|
|
|
|
mktemp(fifoName);
|
|
|
|
if (!mkfifo(fifoName, 0600)) {
|
|
|
|
fifoFd = open(fifoName, O_RDWR | O_NONBLOCK, 0);
|
|
|
|
if (fifoFd >= 0) {
|
|
|
|
fifoMaster = 1;
|
|
|
|
fcntl(fifoFd, F_SETFL, O_NONBLOCK);
|
|
|
|
env = fifoName;
|
|
|
|
setenv("MAKE_JOBS_FIFO", env, 1);
|
|
|
|
while (maxproc-- > 0) {
|
|
|
|
write(fifoFd, "+", 1);
|
|
|
|
}
|
2004-12-01 10:29:20 +00:00
|
|
|
/* The master make does not get a magic token */
|
2004-11-12 08:58:07 +00:00
|
|
|
jobFull = TRUE;
|
|
|
|
maxJobs = 0;
|
|
|
|
} else {
|
|
|
|
unlink(fifoName);
|
|
|
|
env = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (env != NULL) {
|
|
|
|
/*
|
|
|
|
* We had the environment variable so we are a slave.
|
|
|
|
* Open fifo and give ourselves a magic token which represents
|
|
|
|
* the token our parent make has grabbed to start his make process.
|
|
|
|
* Otherwise the sub-makes would gobble up tokens and the proper
|
2004-11-12 13:14:56 +00:00
|
|
|
* number of tokens to specify to -j would depend on the depth of
|
|
|
|
* the tree and the order of execution.
|
2004-11-12 08:58:07 +00:00
|
|
|
*/
|
|
|
|
fifoFd = open(env, O_RDWR, 0);
|
|
|
|
if (fifoFd >= 0) {
|
|
|
|
fcntl(fifoFd, F_SETFL, O_NONBLOCK);
|
|
|
|
maxJobs = 1;
|
|
|
|
jobFull = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fifoFd <= 0) {
|
|
|
|
maxJobs = maxproc;
|
|
|
|
jobFull = FALSE;
|
|
|
|
} else {
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
nJobs = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
aborting = 0;
|
|
|
|
errors = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
lastNode = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-12 08:58:07 +00:00
|
|
|
if ((maxJobs == 1 && fifoFd < 0) || beVerbose == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If only one job can run at a time, there's no need for a banner,
|
|
|
|
* no is there?
|
|
|
|
*/
|
|
|
|
targFmt = "";
|
|
|
|
} else {
|
|
|
|
targFmt = TARG_FMT;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-10-23 21:34:41 +00:00
|
|
|
Shell_Init();
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Catch the four signals that POSIX specifies if they aren't ignored.
|
2004-11-12 07:57:17 +00:00
|
|
|
* JobCatchSignal will just set global variables and hope someone
|
|
|
|
* else is going to handle the interrupt.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2004-11-12 07:57:17 +00:00
|
|
|
sa.sa_handler = JobCatchSig;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGINT, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGHUP, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGQUIT, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* There are additional signals that need to be caught and passed if
|
|
|
|
* either the export system wants to be told directly of signals or if
|
|
|
|
* we're giving each job its own process group (since then it won't get
|
|
|
|
* signals from the terminal driver as we own the terminal)
|
|
|
|
*/
|
2004-11-04 12:57:41 +00:00
|
|
|
#if defined(USE_PGRP)
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGTSTP, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGTSTP, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGTTOU, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGTTOU, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGTTIN, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGTTIN, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
if (signal(SIGWINCH, SIG_IGN) != SIG_IGN) {
|
2004-11-30 17:46:29 +00:00
|
|
|
sigaction(SIGWINCH, &sa, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2002-10-04 20:30:03 +00:00
|
|
|
#ifdef USE_KQUEUE
|
|
|
|
if ((kqfd = kqueue()) == -1) {
|
|
|
|
Punt("kqueue: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
begin = Targ_FindNode(".BEGIN", TARG_NOCREATE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
if (begin != NULL) {
|
2004-12-01 10:29:20 +00:00
|
|
|
JobStart(begin, JOB_SPECIAL, (Job *)NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
while (nJobs) {
|
2004-11-12 08:58:07 +00:00
|
|
|
Job_CatchOutput(0);
|
1996-10-06 02:35:38 +00:00
|
|
|
Job_CatchChildren(!usePipes);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
postCommands = Targ_FindNode(".END", TARG_CREATE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_Full --
|
|
|
|
* See if the job table is full. It is considered full if it is OR
|
|
|
|
* if we are in the process of aborting OR if we have
|
|
|
|
* reached/exceeded our local quota. This prevents any more jobs
|
|
|
|
* from starting up.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if the job table is full, FALSE otherwise
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Boolean
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_Full(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-12 08:58:07 +00:00
|
|
|
char c;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (aborting)
|
2004-11-30 17:46:29 +00:00
|
|
|
return (aborting);
|
2004-11-12 08:58:07 +00:00
|
|
|
if (fifoFd >= 0 && jobFull) {
|
|
|
|
i = read(fifoFd, &c, 1);
|
|
|
|
if (i > 0) {
|
|
|
|
maxJobs++;
|
|
|
|
jobFull = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (jobFull);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_Empty --
|
|
|
|
* See if the job table is empty. Because the local concurrency may
|
|
|
|
* be set to 0, it is possible for the job table to become empty,
|
|
|
|
* while the list of stoppedJobs remains non-empty. In such a case,
|
|
|
|
* we want to restart as many jobs as we can.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if it is. FALSE if it ain't.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* -----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Boolean
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_Empty(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
if (nJobs == 0) {
|
|
|
|
if (!Lst_IsEmpty(stoppedJobs) && !aborting) {
|
|
|
|
/*
|
|
|
|
* The job table is obviously not full if it has no jobs in
|
|
|
|
* it...Try and restart the stopped jobs.
|
|
|
|
*/
|
|
|
|
jobFull = FALSE;
|
1996-10-06 02:35:38 +00:00
|
|
|
JobRestartJobs();
|
2004-11-30 17:46:29 +00:00
|
|
|
return (FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
return (TRUE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
return (FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobMatchShell --
|
|
|
|
* Find a matching shell in 'shells' given its final component.
|
|
|
|
*
|
|
|
|
* Results:
|
2004-12-03 08:02:52 +00:00
|
|
|
* A pointer to a freshly allocated Shell structure with a copy
|
2004-11-30 15:35:51 +00:00
|
|
|
* of the static structure or NULL if no shell with the given name
|
|
|
|
* is found.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static Shell *
|
2004-11-30 15:35:51 +00:00
|
|
|
JobMatchShell(const char *name)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 15:35:51 +00:00
|
|
|
const struct CShell *sh; /* Pointer into shells table */
|
|
|
|
struct Shell *nsh;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-03 08:02:52 +00:00
|
|
|
for (sh = shells; sh < shells + sizeof(shells) / sizeof(shells[0]); sh++)
|
|
|
|
if (strcmp(sh->name, name) == 0)
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-03 08:02:52 +00:00
|
|
|
if (sh == shells + sizeof(shells) / sizeof(shells[0]))
|
2004-11-30 15:35:51 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/* make a copy */
|
|
|
|
nsh = emalloc(sizeof(*nsh));
|
|
|
|
|
2004-12-03 08:02:52 +00:00
|
|
|
nsh->name = estrdup(sh->name);
|
|
|
|
nsh->echoOff = estrdup(sh->echoOff);
|
|
|
|
nsh->echoOn = estrdup(sh->echoOn);
|
|
|
|
nsh->hasEchoCtl = sh->hasEchoCtl;
|
|
|
|
nsh->noPrint = estrdup(sh->noPrint);
|
|
|
|
nsh->noPLen = sh->noPLen;
|
|
|
|
nsh->hasErrCtl = sh->hasErrCtl;
|
|
|
|
nsh->errCheck = estrdup(sh->errCheck);
|
|
|
|
nsh->ignErr = estrdup(sh->ignErr);
|
|
|
|
nsh->echo = estrdup(sh->echo);
|
|
|
|
nsh->exit = estrdup(sh->exit);
|
2004-11-30 15:35:51 +00:00
|
|
|
|
|
|
|
return (nsh);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_ParseShell --
|
|
|
|
* Parse a shell specification and set up commandShell, shellPath
|
|
|
|
* and shellName appropriately.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* FAILURE if the specification was incorrect.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* commandShell points to a Shell structure (either predefined or
|
|
|
|
* created from the shell spec), shellPath is the full path of the
|
|
|
|
* shell described by commandShell, while shellName is just the
|
|
|
|
* final component of shellPath.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* A shell specification consists of a .SHELL target, with dependency
|
|
|
|
* operator, followed by a series of blank-separated words. Double
|
|
|
|
* quotes can be used to use blanks in words. A backslash escapes
|
|
|
|
* anything (most notably a double-quote and a space) and
|
|
|
|
* provides the functionality it does in C. Each word consists of
|
|
|
|
* keyword and value separated by an equal sign. There should be no
|
|
|
|
* unnecessary spaces in the word. The keywords are as follows:
|
|
|
|
* name Name of shell.
|
|
|
|
* path Location of shell. Overrides "name" if given
|
|
|
|
* quiet Command to turn off echoing.
|
|
|
|
* echo Command to turn echoing on
|
|
|
|
* filter Result of turning off echoing that shouldn't be
|
|
|
|
* printed.
|
|
|
|
* echoFlag Flag to turn echoing on at the start
|
|
|
|
* errFlag Flag to turn error checking on at the start
|
|
|
|
* hasErrCtl True if shell has error checking control
|
|
|
|
* check Command to turn on error checking if hasErrCtl
|
|
|
|
* is TRUE or template of command to echo a command
|
|
|
|
* for which error checking is off if hasErrCtl is
|
|
|
|
* FALSE.
|
|
|
|
* ignore Command to turn off error checking if hasErrCtl
|
|
|
|
* is TRUE or template of command to execute a
|
|
|
|
* command so as to ignore any errors it returns if
|
|
|
|
* hasErrCtl is FALSE.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
ReturnStatus
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_ParseShell(char *line)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char **words;
|
|
|
|
int wordCount;
|
2002-04-13 10:05:30 +00:00
|
|
|
char **argv;
|
|
|
|
int argc;
|
1994-05-27 12:33:43 +00:00
|
|
|
char *path;
|
2004-11-30 15:35:51 +00:00
|
|
|
Shell newShell;
|
|
|
|
Shell *sh;
|
1994-05-27 12:33:43 +00:00
|
|
|
Boolean fullSpec = FALSE;
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
while (isspace((unsigned char)*line)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
line++;
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
words = brk_string(line, &wordCount, TRUE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-12-02 20:24:42 +00:00
|
|
|
memset(&newShell, 0, sizeof(newShell));
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Parse the specification by keyword
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
for (path = NULL, argc = wordCount - 1, argv = words + 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
argc != 0;
|
|
|
|
argc--, argv++) {
|
1996-10-06 02:35:38 +00:00
|
|
|
if (strncmp(*argv, "path=", 5) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
path = &argv[0][5];
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (strncmp(*argv, "name=", 5) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.name = &argv[0][5];
|
|
|
|
} else {
|
1996-10-06 02:35:38 +00:00
|
|
|
if (strncmp(*argv, "quiet=", 6) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.echoOff = &argv[0][6];
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (strncmp(*argv, "echo=", 5) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.echoOn = &argv[0][5];
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (strncmp(*argv, "filter=", 7) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.noPrint = &argv[0][7];
|
|
|
|
newShell.noPLen = strlen(newShell.noPrint);
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (strncmp(*argv, "echoFlag=", 9) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.echo = &argv[0][9];
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (strncmp(*argv, "errFlag=", 8) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.exit = &argv[0][8];
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (strncmp(*argv, "hasErrCtl=", 10) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
char c = argv[0][10];
|
|
|
|
newShell.hasErrCtl = !((c != 'Y') && (c != 'y') &&
|
1996-10-06 02:35:38 +00:00
|
|
|
(c != 'T') && (c != 't'));
|
|
|
|
} else if (strncmp(*argv, "check=", 6) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.errCheck = &argv[0][6];
|
1996-10-06 02:35:38 +00:00
|
|
|
} else if (strncmp(*argv, "ignore=", 7) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
newShell.ignErr = &argv[0][7];
|
|
|
|
} else {
|
1996-10-06 02:35:38 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Unknown keyword \"%s\"",
|
1994-05-27 12:33:43 +00:00
|
|
|
*argv);
|
2004-11-30 17:46:29 +00:00
|
|
|
return (FAILURE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
fullSpec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-25 10:01:26 +00:00
|
|
|
/*
|
|
|
|
* Some checks (could be more)
|
|
|
|
*/
|
|
|
|
if (fullSpec) {
|
|
|
|
if ((newShell.echoOn != NULL) ^ (newShell.echoOff != NULL))
|
|
|
|
Parse_Error(PARSE_FATAL, "Shell must have either both echoOff and "
|
|
|
|
"echoOn or none of them");
|
|
|
|
|
|
|
|
if (newShell.echoOn != NULL && newShell.echoOff)
|
|
|
|
newShell.hasEchoCtl = TRUE;
|
|
|
|
}
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (path == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If no path was given, the user wants one of the pre-defined shells,
|
|
|
|
* yes? So we find the one s/he wants with the help of JobMatchShell
|
|
|
|
* and set things up the right way. shellPath will be set up by
|
|
|
|
* Job_Init.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
if (newShell.name == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL, "Neither path nor name specified");
|
2004-11-25 10:01:26 +00:00
|
|
|
return (FAILURE);
|
|
|
|
}
|
|
|
|
if ((sh = JobMatchShell(newShell.name)) == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL, "%s: no matching shell", newShell.name);
|
|
|
|
return (FAILURE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-25 10:01:26 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
} 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.
|
|
|
|
*/
|
2004-11-25 10:01:26 +00:00
|
|
|
free(shellPath);
|
|
|
|
shellPath = estrdup(path);
|
|
|
|
if (newShell.name == NULL) {
|
|
|
|
/* get the base name as the name */
|
|
|
|
path = strrchr(path, '/');
|
|
|
|
if (path == NULL) {
|
|
|
|
path = shellPath;
|
|
|
|
} else {
|
|
|
|
path += 1;
|
|
|
|
}
|
|
|
|
newShell.name = path;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-25 10:01:26 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!fullSpec) {
|
2004-11-25 10:01:26 +00:00
|
|
|
if ((sh = JobMatchShell(newShell.name)) == NULL) {
|
2004-10-23 21:34:41 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "%s: no matching shell",
|
2004-11-25 10:01:26 +00:00
|
|
|
newShell.name);
|
|
|
|
return (FAILURE);
|
2004-10-23 21:34:41 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-11-30 15:35:51 +00:00
|
|
|
sh = JobCopyShell(&newShell);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-25 10:01:26 +00:00
|
|
|
/* set the new shell */
|
|
|
|
JobFreeShell(commandShell);
|
2004-11-30 15:35:51 +00:00
|
|
|
commandShell = sh;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-25 10:01:26 +00:00
|
|
|
shellName = commandShell->name;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-25 10:01:26 +00:00
|
|
|
return (SUCCESS);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobInterrupt --
|
|
|
|
* Handle the receipt of an interrupt.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* All children are killed. Another job will be started if the
|
|
|
|
* .INTERRUPT target was given.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobInterrupt(int runINTERRUPT, int signo)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
LstNode ln; /* element in job table */
|
2000-07-09 00:05:09 +00:00
|
|
|
Job *job = NULL; /* job descriptor in that element */
|
1994-05-27 12:33:43 +00:00
|
|
|
GNode *interrupt; /* the node describing the .INTERRUPT target */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
aborting = ABORT_INTERRUPT;
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
Lst_Open(jobs);
|
2000-12-02 18:58:01 +00:00
|
|
|
while ((ln = Lst_Next(jobs)) != NULL) {
|
2004-12-01 10:29:20 +00:00
|
|
|
job = Lst_Datum(ln);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!Targ_Precious(job->node)) {
|
2004-11-30 17:46:29 +00:00
|
|
|
char *file = (job->node->path == NULL ?
|
|
|
|
job->node->name :
|
|
|
|
job->node->path);
|
1996-10-06 02:35:38 +00:00
|
|
|
if (!noExecute && eunlink(file) != -1) {
|
|
|
|
Error("*** %s removed", file);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (job->pid) {
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("JobInterrupt passing signal to child %d.\n",
|
|
|
|
job->pid));
|
1996-10-06 02:35:38 +00:00
|
|
|
KILL(job->pid, signo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (runINTERRUPT && !touchFlag) {
|
2004-11-12 07:57:17 +00:00
|
|
|
/* clear the interrupted flag because we would get an
|
|
|
|
* infinite loop otherwise */
|
|
|
|
interrupted = 0;
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
|
2000-12-02 18:58:01 +00:00
|
|
|
if (interrupt != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
ignoreErrors = FALSE;
|
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
JobStart(interrupt, JOB_IGNDOTS, (Job *)NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
while (nJobs) {
|
2004-11-12 08:58:07 +00:00
|
|
|
Job_CatchOutput(0);
|
1996-10-06 02:35:38 +00:00
|
|
|
Job_CatchChildren(!usePipes);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*-----------------------------------------------------------------------
|
2002-04-13 12:18:00 +00:00
|
|
|
* Job_Finish --
|
1994-05-27 12:33:43 +00:00
|
|
|
* Do final processing such as the running of the commands
|
1995-05-30 06:41:30 +00:00
|
|
|
* attached to the .END target.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Number of errors reported.
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
int
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_Finish(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
if (postCommands != NULL && !Lst_IsEmpty(postCommands->commands)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (errors) {
|
1996-10-06 02:35:38 +00:00
|
|
|
Error("Errors reported so .END ignored");
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
1996-10-06 02:35:38 +00:00
|
|
|
JobStart(postCommands, JOB_SPECIAL | JOB_IGNDOTS, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
while (nJobs) {
|
2004-11-12 08:58:07 +00:00
|
|
|
Job_CatchOutput(0);
|
1996-10-06 02:35:38 +00:00
|
|
|
Job_CatchChildren(!usePipes);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-12 08:58:07 +00:00
|
|
|
if (fifoFd >= 0) {
|
|
|
|
close(fifoFd);
|
|
|
|
fifoFd = -1;
|
|
|
|
if (fifoMaster)
|
|
|
|
unlink(fifoName);
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
return (errors);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_Wait --
|
|
|
|
* Waits for all running jobs to finish and returns. Sets 'aborting'
|
|
|
|
* to ABORT_WAIT to prevent other jobs from starting.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Currently running jobs finish.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_Wait(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
aborting = ABORT_WAIT;
|
|
|
|
while (nJobs != 0) {
|
2004-11-12 08:58:07 +00:00
|
|
|
Job_CatchOutput(0);
|
1994-05-27 12:33:43 +00:00
|
|
|
Job_CatchChildren(!usePipes);
|
|
|
|
}
|
|
|
|
aborting = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Job_AbortAll --
|
|
|
|
* Abort all currently running jobs without handling output or anything.
|
|
|
|
* This function is to be called only in the event of a major
|
|
|
|
* error. Most definitely NOT to be called from JobInterrupt.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* All children are killed, not just the firstborn
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-10-09 03:42:10 +00:00
|
|
|
Job_AbortAll(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1996-10-06 02:35:38 +00:00
|
|
|
LstNode ln; /* element in job table */
|
1994-05-27 12:33:43 +00:00
|
|
|
Job *job; /* the job descriptor in that element */
|
|
|
|
int foo;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
aborting = ABORT_ERROR;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (nJobs) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Lst_Open(jobs);
|
2000-12-02 18:58:01 +00:00
|
|
|
while ((ln = Lst_Next(jobs)) != NULL) {
|
2004-12-01 10:29:20 +00:00
|
|
|
job = Lst_Datum(ln);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* kill the child process with increasingly drastic signals to make
|
1995-05-30 06:41:30 +00:00
|
|
|
* darn sure it's dead.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
KILL(job->pid, SIGINT);
|
|
|
|
KILL(job->pid, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Catch as many children as want to report in at first, then give up
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
while (waitpid((pid_t)-1, &foo, WNOHANG) > 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* JobRestartJobs --
|
|
|
|
* Tries to restart stopped jobs if there are slots available.
|
|
|
|
* Note that this tries to restart them regardless of pending errors.
|
|
|
|
* It's not good to leave stopped jobs lying around!
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Resumes(and possibly migrates) jobs.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
JobRestartJobs(void)
|
1996-10-06 02:35:38 +00:00
|
|
|
{
|
|
|
|
while (!jobFull && !Lst_IsEmpty(stoppedJobs)) {
|
2002-09-18 16:13:03 +00:00
|
|
|
DEBUGF(JOB, ("Job queue is not full. Restarting a stopped job.\n"));
|
2004-12-01 10:29:20 +00:00
|
|
|
JobRestart(Lst_DeQueue(stoppedJobs));
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|