2005-06-29 23:59:42 +04:00
|
|
|
|
/* $NetBSD: job.c,v 1.95 2005/06/29 19:59:42 christos Exp $ */
|
1995-06-14 19:18:37 +04:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
2003-08-07 15:13:06 +04:00
|
|
|
|
* 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. 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Copyright (c) 1988, 1989 by Adam de Boor
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-05-07 04:04:38 +04:00
|
|
|
|
#ifndef MAKE_NATIVE
|
2005-06-29 23:59:42 +04:00
|
|
|
|
static char rcsid[] = "$NetBSD: job.c,v 1.95 2005/06/29 19:59:42 christos Exp $";
|
1997-09-28 07:30:58 +04:00
|
|
|
|
#else
|
1997-07-02 01:17:00 +04:00
|
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifndef lint
|
1995-06-14 19:18:37 +04:00
|
|
|
|
#if 0
|
1996-11-06 20:58:58 +03:00
|
|
|
|
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
|
1995-06-14 19:18:37 +04:00
|
|
|
|
#else
|
2005-06-29 23:59:42 +04:00
|
|
|
|
__RCSID("$NetBSD: job.c,v 1.95 2005/06/29 19:59:42 christos Exp $");
|
1995-06-14 19:18:37 +04:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#endif /* not lint */
|
1997-09-28 07:30:58 +04:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*
|
1998-03-26 22:20:36 +03:00
|
|
|
|
* Job_End Cleanup any memory used.
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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.
|
|
|
|
|
*
|
1998-03-26 22:20:36 +03:00
|
|
|
|
* Job_Finish Perform any final processing which needs doing.
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#include <sys/types.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/file.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <sys/wait.h>
|
2002-06-15 22:24:55 +04:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#include <errno.h>
|
2002-06-15 22:24:55 +04:00
|
|
|
|
#include <fcntl.h>
|
2000-12-03 05:19:32 +03:00
|
|
|
|
#ifndef RMT_WILL_WATCH
|
|
|
|
|
#ifndef USE_SELECT
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2002-06-15 22:24:55 +04:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <utime.h>
|
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#include "make.h"
|
|
|
|
|
#include "hash.h"
|
|
|
|
|
#include "dir.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#include "job.h"
|
|
|
|
|
#include "pathnames.h"
|
2000-12-30 05:05:20 +03:00
|
|
|
|
#include "trace.h"
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
#include "rmt.h"
|
1996-11-06 20:58:58 +03:00
|
|
|
|
# define STATIC
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#else
|
|
|
|
|
# define STATIC static
|
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* error handling variables
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
|
static int errors = 0; /* number of errors reported */
|
|
|
|
|
static int aborting = 0; /* why is the make aborting? */
|
1993-03-21 12:45:37 +03: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 */
|
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
|
/*
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* XXX: Avoid SunOS bug... FILENO() is fp->_file, and file
|
|
|
|
|
* is a char! So when we go above 127 we turn negative!
|
|
|
|
|
*/
|
|
|
|
|
#define FILENO(a) ((unsigned) fileno(a))
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
2002-04-15 16:45:33 +04:00
|
|
|
|
static GNode *postCommands = NILGNODE;
|
|
|
|
|
/* node containing commands to execute when
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
#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 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Descriptions for various shells.
|
|
|
|
|
*/
|
|
|
|
|
static Shell shells[] = {
|
|
|
|
|
/*
|
|
|
|
|
* 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",
|
|
|
|
|
TRUE, "unset verbose", "set verbose", "unset verbose", 10,
|
2005-02-01 01:41:43 +03:00
|
|
|
|
FALSE, "echo \"%s\"\n", "csh -c \"%s || exit 0\"\n", "", '#',
|
1993-03-21 12:45:37 +03:00
|
|
|
|
"v", "e",
|
|
|
|
|
},
|
|
|
|
|
/*
|
|
|
|
|
* SH description. Echo control is also possible and, under
|
|
|
|
|
* sun UNIX anyway, one can even control error checking.
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
"sh",
|
2003-12-20 03:18:22 +03:00
|
|
|
|
FALSE, "", "", "", 0,
|
|
|
|
|
FALSE, "echo \"%s\"\n", "%s\n", "{ %s \n} || exit $?\n", '#',
|
1999-07-06 18:02:56 +04:00
|
|
|
|
#ifdef __NetBSD__
|
2003-12-20 03:18:22 +03:00
|
|
|
|
"q",
|
1999-07-06 18:02:56 +04:00
|
|
|
|
#else
|
2003-12-20 03:18:22 +03:00
|
|
|
|
"",
|
1999-07-06 18:02:56 +04:00
|
|
|
|
#endif
|
2003-12-20 03:18:22 +03:00
|
|
|
|
"",
|
2003-08-01 04:39:52 +04:00
|
|
|
|
},
|
|
|
|
|
/*
|
|
|
|
|
* KSH description.
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
"ksh",
|
|
|
|
|
TRUE, "set +v", "set -v", "set +v", 6,
|
2003-12-20 03:18:22 +03:00
|
|
|
|
FALSE, "echo \"%s\"\n", "%s\n", "{ %s \n} || exit $?\n", '#',
|
2003-08-01 04:39:52 +04:00
|
|
|
|
"v",
|
2003-12-20 03:18:22 +03:00
|
|
|
|
"",
|
1993-03-21 12:45:37 +03:00
|
|
|
|
},
|
|
|
|
|
/*
|
|
|
|
|
* UNKNOWN.
|
|
|
|
|
*/
|
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(char *) 0,
|
|
|
|
|
FALSE, (char *) 0, (char *) 0, (char *) 0, 0,
|
2003-12-20 03:18:22 +03:00
|
|
|
|
FALSE, (char *) 0, (char *) 0, (char *) 0, 0,
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(char *) 0, (char *) 0,
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
};
|
1994-03-05 03:34:29 +03:00
|
|
|
|
static Shell *commandShell = &shells[DEFSHELL];/* this is the shell to
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* which we pass all
|
|
|
|
|
* commands in the Makefile.
|
|
|
|
|
* It is set by the
|
|
|
|
|
* Job_ParseShell function */
|
2003-08-01 04:39:52 +04:00
|
|
|
|
const char *shellPath = NULL, /* full pathname of
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* executable image */
|
2003-08-01 04:39:52 +04:00
|
|
|
|
*shellName = NULL; /* last component of shell */
|
|
|
|
|
static const char *shellArgv = NULL; /* Custom shell args */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int maxJobs; /* The most children we can run at once */
|
|
|
|
|
static int maxLocal; /* The most local ones we can have */
|
1995-11-03 02:54:35 +03:00
|
|
|
|
STATIC int nJobs; /* The number of children currently running */
|
|
|
|
|
STATIC int nLocal; /* The number of local children */
|
|
|
|
|
STATIC Lst jobs; /* The structures that describe them */
|
2000-12-30 05:05:20 +03:00
|
|
|
|
static Boolean wantToken; /* we want a token */
|
|
|
|
|
|
2000-12-03 05:19:32 +03:00
|
|
|
|
/*
|
|
|
|
|
* Set of descriptors of pipes connected to
|
|
|
|
|
* the output channels of children
|
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifndef RMT_WILL_WATCH
|
2000-12-03 05:19:32 +03:00
|
|
|
|
static struct pollfd *fds = NULL;
|
2000-12-04 20:45:17 +03:00
|
|
|
|
static Job **jobfds = NULL;
|
2000-12-03 05:19:32 +03:00
|
|
|
|
static int nfds = 0;
|
|
|
|
|
static int maxfds = 0;
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void watchfd(Job *);
|
|
|
|
|
static void clearfd(Job *);
|
|
|
|
|
static int readyfd(Job *);
|
2000-12-04 20:45:17 +03:00
|
|
|
|
#define JBSTART 256
|
2000-12-06 00:57:20 +03:00
|
|
|
|
#define JBFACTOR 2
|
2000-12-03 05:19:32 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
STATIC GNode *lastNode; /* The node for which output was most recently
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* produced. */
|
2003-07-14 22:19:11 +04:00
|
|
|
|
STATIC const char *targFmt; /* Format string to use to head output from a
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* job when it's not the most-recent job heard
|
|
|
|
|
* from */
|
2000-12-30 05:05:20 +03:00
|
|
|
|
static Job tokenWaitJob; /* token wait pseudo-job */
|
|
|
|
|
int job_pipe[2] = { -1, -1 }; /* job server pipes. */
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
2002-11-17 01:22:23 +03:00
|
|
|
|
static Job childExitJob; /* child exit pseudo-job */
|
|
|
|
|
int exit_pipe[2] = { -1, -1 }; /* child exit signal pipe. */
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
# define TARG_FMT "--- %s at %s ---\n" /* Default format */
|
|
|
|
|
# define MESSAGE(fp, gn) \
|
2000-12-03 04:27:03 +03:00
|
|
|
|
(void) fprintf(fp, targFmt, gn->name, gn->rem.hname)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#else
|
|
|
|
|
# define TARG_FMT "--- %s ---\n" /* Default format */
|
|
|
|
|
# define MESSAGE(fp, gn) \
|
2000-12-03 04:27:03 +03:00
|
|
|
|
(void) fprintf(fp, targFmt, gn->name)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When JobStart attempts to run a job remotely but can't, and isn't allowed
|
|
|
|
|
* to run the job locally, or when Job_CatchChildren detects a job that has
|
|
|
|
|
* been migrated home, the job is placed on the stoppedJobs queue to be run
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* when the next job finishes.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
STATIC Lst stoppedJobs; /* Lst of Job structures describing
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* jobs that were stopped due to concurrency
|
|
|
|
|
* limits or migration home */
|
|
|
|
|
|
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigset_t caught_signals; /* Set of signals we handle */
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#if defined(USE_PGRP) && defined(SYSV)
|
1999-05-03 13:49:55 +04:00
|
|
|
|
# define KILL(pid, sig) kill(-(pid), (sig))
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
|
# if defined(USE_PGRP)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
# define KILL(pid, sig) killpg((pid), (sig))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
# else
|
1995-11-03 02:54:35 +03:00
|
|
|
|
# define KILL(pid, sig) kill((pid), (sig))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
# endif
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
|
/*
|
1995-11-22 20:39:53 +03: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.
|
|
|
|
|
*/
|
1999-07-16 09:38:20 +04:00
|
|
|
|
#ifndef W_STOPCODE
|
|
|
|
|
#define W_STOPCODE(sig) (((sig) << 8) | 0177)
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef W_EXITCODE
|
|
|
|
|
#define W_EXITCODE(ret, sig) ((ret << 8) | (sig))
|
|
|
|
|
#endif
|
1995-11-22 20:39:53 +03:00
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static int JobCondPassSig(ClientData, ClientData);
|
|
|
|
|
static void JobPassSig(int);
|
2002-11-17 01:22:23 +03:00
|
|
|
|
static void JobChildSig(int);
|
2001-05-01 07:27:50 +04:00
|
|
|
|
#ifdef USE_PGRP
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobContinueSig(int);
|
2001-05-01 07:27:50 +04:00
|
|
|
|
#endif
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static int JobCmpPid(ClientData, ClientData);
|
|
|
|
|
static int JobPrintCommand(ClientData, ClientData);
|
|
|
|
|
static int JobSaveCommand(ClientData, ClientData);
|
|
|
|
|
static void JobClose(Job *);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static int JobCmpRmtID(ClientData, ClientData);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
# ifdef RMT_WILL_WATCH
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobLocalInput(int, Job *);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
# endif
|
|
|
|
|
#else
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobFinish(Job *, int *);
|
|
|
|
|
static void JobExec(Job *, char **);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobMakeArgv(Job *, char **);
|
|
|
|
|
static int JobRestart(Job *);
|
|
|
|
|
static int JobStart(GNode *, int, Job *);
|
|
|
|
|
static char *JobOutput(Job *, char *, char *, int);
|
|
|
|
|
static void JobDoOutput(Job *, Boolean);
|
2003-07-14 22:19:11 +04:00
|
|
|
|
static Shell *JobMatchShell(const char *);
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobInterrupt(int, int);
|
|
|
|
|
static void JobRestartJobs(void);
|
|
|
|
|
static void JobTokenAdd(void);
|
2002-03-18 16:28:25 +03:00
|
|
|
|
static void JobSigLock(sigset_t *);
|
|
|
|
|
static void JobSigUnlock(sigset_t *);
|
|
|
|
|
static void JobSigReset(void);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* JobSigLock/JobSigUnlock
|
|
|
|
|
*
|
|
|
|
|
* Signal lock routines to get exclusive access. Currently used to
|
|
|
|
|
* protect `jobs' and `stoppedJobs' list manipulations.
|
|
|
|
|
*/
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobSigLock(sigset_t *omaskp)
|
2002-03-18 16:28:25 +03:00
|
|
|
|
{
|
|
|
|
|
if (sigprocmask(SIG_BLOCK, &caught_signals, omaskp) != 0) {
|
|
|
|
|
Punt("JobSigLock: sigprocmask: %s", strerror(errno));
|
|
|
|
|
sigemptyset(omaskp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobSigUnlock(sigset_t *omaskp)
|
2002-03-18 16:28:25 +03:00
|
|
|
|
{
|
|
|
|
|
(void) sigprocmask(SIG_SETMASK, omaskp, NULL);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobCondPassSig --
|
|
|
|
|
* Pass a signal to a job if the job is remote or if USE_PGRP
|
|
|
|
|
* is defined.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* jobp Job to biff
|
|
|
|
|
* signop Signal to send it
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* === 0
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* None, except the job may bite it.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobCondPassSig(ClientData jobp, ClientData signop)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
|
Job *job = (Job *) jobp;
|
|
|
|
|
int signo = *(int *) signop;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifdef RMT_WANTS_SIGNALS
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) Rmt_Signal(job, signo);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
KILL(job->pid, signo);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
/*
|
|
|
|
|
* Assume that sending the signal to job->pid will signal any remote
|
|
|
|
|
* job as well.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
1996-11-06 20:58:58 +03:00
|
|
|
|
(void) fprintf(stdout,
|
1995-11-03 02:54:35 +03:00
|
|
|
|
"JobCondPassSig passing signal %d to child %d.\n",
|
|
|
|
|
signo, job->pid);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
KILL(job->pid, signo);
|
|
|
|
|
#endif
|
1995-11-03 02:54:35 +03:00
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2000-12-05 18:20:10 +03:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
2002-11-17 01:22:23 +03:00
|
|
|
|
* JobChldSig --
|
|
|
|
|
* SIGCHLD handler.
|
2000-12-05 18:20:10 +03:00
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* signo The signal number we've received
|
|
|
|
|
*
|
2000-12-05 18:20:10 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
2002-11-17 01:22:23 +03:00
|
|
|
|
* Sends a token on the child exit pipe to wake us up from
|
|
|
|
|
* select()/poll().
|
2000-12-05 18:20:10 +03:00
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2004-07-02 00:38:09 +04:00
|
|
|
|
JobChildSig(int signo __unused)
|
2000-12-05 18:20:10 +03:00
|
|
|
|
{
|
2002-11-17 01:22:23 +03:00
|
|
|
|
write(exit_pipe[1], ".", 1);
|
2000-12-05 18:20:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-05-01 07:27:50 +04:00
|
|
|
|
#ifdef USE_PGRP
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobContinueSig --
|
|
|
|
|
* Resume all stopped jobs.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* signo The signal number we've received
|
|
|
|
|
*
|
2001-05-01 07:27:50 +04:00
|
|
|
|
* Results:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* Jobs start running again.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2004-07-02 00:38:09 +04:00
|
|
|
|
JobContinueSig(int signo __unused)
|
2001-05-01 07:27:50 +04:00
|
|
|
|
{
|
|
|
|
|
JobRestartJobs();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-12-05 18:20:10 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobPassSig --
|
|
|
|
|
* Pass a signal on to all remote jobs and to all local jobs if
|
|
|
|
|
* USE_PGRP is defined, then die ourselves.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* signo The signal number we've received
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* We die by the same signal.
|
1996-11-06 20:58:58 +03:00
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobPassSig(int signo)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-22 20:39:53 +03:00
|
|
|
|
sigset_t nmask, omask;
|
1996-02-05 01:20:27 +03:00
|
|
|
|
struct sigaction act;
|
1999-07-16 09:38:20 +04:00
|
|
|
|
int sigcont;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "JobPassSig(%d) called.\n", signo);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
Lst_ForEach(jobs, JobCondPassSig, (ClientData) &signo);
|
1993-03-21 12:45:37 +03: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) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobInterrupt(TRUE, signo);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else if ((signo == SIGHUP) || (signo == SIGTERM) || (signo == SIGQUIT)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobInterrupt(FALSE, signo);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Leave gracefully if SIGQUIT, rather than core dumping.
|
|
|
|
|
*/
|
|
|
|
|
if (signo == SIGQUIT) {
|
1994-03-05 03:34:29 +03:00
|
|
|
|
Finish(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2001-05-01 07:27:50 +04:00
|
|
|
|
if (signo == SIGTSTP) {
|
|
|
|
|
Job_CatchChildren(FALSE);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1999-07-16 09:38:20 +04:00
|
|
|
|
sigfillset(&nmask);
|
2002-03-18 15:28:07 +03:00
|
|
|
|
sigdelset(&nmask, signo);
|
|
|
|
|
(void) sigprocmask(SIG_SETMASK, &nmask, &omask);
|
|
|
|
|
|
1996-02-05 01:20:27 +03:00
|
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
|
act.sa_flags = 0;
|
2002-03-18 15:28:07 +03:00
|
|
|
|
(void) sigaction(signo, &act, NULL);
|
1995-11-22 20:39:53 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
2001-05-01 07:27:50 +04:00
|
|
|
|
"JobPassSig passing signal %d to self.\n", signo);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1999-07-16 09:38:20 +04:00
|
|
|
|
(void) kill(getpid(), signo);
|
|
|
|
|
if (signo != SIGTSTP) {
|
|
|
|
|
sigcont = SIGCONT;
|
|
|
|
|
Lst_ForEach(jobs, JobCondPassSig, (ClientData) &sigcont);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
2002-03-18 15:28:07 +03:00
|
|
|
|
/* Restore handler and signal mask */
|
|
|
|
|
act.sa_handler = JobPassSig;
|
|
|
|
|
(void) sigaction(signo, &act, NULL);
|
1995-11-22 20:39:53 +03:00
|
|
|
|
(void) sigprocmask(SIG_SETMASK, &omask, NULL);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* job job to examine
|
|
|
|
|
* pid process id desired
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* 0 if the pid's match
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* None
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobCmpPid(ClientData job, ClientData pid)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1996-11-06 20:58:58 +03:00
|
|
|
|
return *(int *) pid - ((Job *) job)->pid;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobCmpRmtID --
|
|
|
|
|
* Compare the rmtID of the job with the given rmtID and return 0 if they
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* are equal.
|
1995-11-03 02:54:35 +03:00
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* job job to examine
|
|
|
|
|
* rmtID remote id desired
|
|
|
|
|
*
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* 0 if the rmtID's match
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* None.
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobCmpRmtID(ClientData job, ClientData rmtID)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
{
|
2002-03-18 16:32:36 +03:00
|
|
|
|
return(*(int *) rmtID - ((Job *) job)->rmtID);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03: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
|
|
|
|
|
* node and executed by Job_End when all things are done.
|
|
|
|
|
* This function is called from JobStart via Lst_ForEach.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* cmdp command string to print
|
|
|
|
|
* jobp job for which to print it
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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-06-15 22:24:55 +04:00
|
|
|
|
JobPrintCommand(ClientData cmdp, ClientData jobp)
|
1993-03-21 12:45:37 +03: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 */
|
2003-07-14 22:19:11 +04:00
|
|
|
|
const char *cmdTemplate; /* Template to use when printing the
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* command */
|
|
|
|
|
char *cmdStart; /* Start of expanded command */
|
2003-12-20 03:18:22 +03:00
|
|
|
|
char *escCmd = NULL; /* Command with quotes/backticks escaped */
|
1994-06-07 02:45:17 +04:00
|
|
|
|
char *cmd = (char *) cmdp;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
Job *job = (Job *) jobp;
|
2005-02-01 01:41:43 +03:00
|
|
|
|
char *cp, *tmp;
|
2003-12-20 03:18:22 +03:00
|
|
|
|
int i, j;
|
|
|
|
|
|
2001-01-01 18:47:37 +03:00
|
|
|
|
noSpecials = NoExecute(job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (strcmp(cmd, "...") == 0) {
|
1996-11-06 20:58:58 +03:00
|
|
|
|
job->node->type |= OP_SAVE_CMDS;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if ((job->flags & JOB_IGNDOTS) == 0) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
job->tailCmds = Lst_Succ(Lst_Member(job->node->commands,
|
|
|
|
|
(ClientData)cmd));
|
1996-11-06 20:58:58 +03:00
|
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#define DBPRINTF(fmt, arg) if (DEBUG(JOB)) { \
|
|
|
|
|
(void) fprintf(stdout, fmt, arg); \
|
|
|
|
|
(void) fflush(stdout); \
|
|
|
|
|
} \
|
|
|
|
|
(void) fprintf(job->cmdFILE, fmt, arg); \
|
|
|
|
|
(void) fflush(job->cmdFILE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
numCommands += 1;
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
cmdStart = cmd = Var_Subst(NULL, cmd, job->node, FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
cmdTemplate = "%s\n";
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check for leading @' and -'s to control echoing and error checking.
|
|
|
|
|
*/
|
2004-05-07 12:12:15 +04:00
|
|
|
|
while (*cmd == '@' || *cmd == '-' || (*cmd == '+')) {
|
|
|
|
|
switch (*cmd) {
|
|
|
|
|
case '@':
|
1993-03-21 12:45:37 +03:00
|
|
|
|
shutUp = TRUE;
|
2004-05-07 12:12:15 +04:00
|
|
|
|
break;
|
|
|
|
|
case '-':
|
1993-03-21 12:45:37 +03:00
|
|
|
|
errOff = TRUE;
|
2004-05-07 12:12:15 +04:00
|
|
|
|
break;
|
|
|
|
|
case '+':
|
|
|
|
|
if (noSpecials) {
|
|
|
|
|
/*
|
|
|
|
|
* We're not actually executing anything...
|
|
|
|
|
* but this one needs to be - use compat mode just for it.
|
|
|
|
|
*/
|
|
|
|
|
CompatRunCommand(cmdp, (ClientData)job->node);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
cmd++;
|
|
|
|
|
}
|
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
|
while (isspace((unsigned char) *cmd))
|
|
|
|
|
cmd++;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
2003-12-20 03:18:22 +03:00
|
|
|
|
/*
|
|
|
|
|
* If the shell doesn't have error control the alternate echo'ing will
|
|
|
|
|
* be done (to avoid showing additional error checking code)
|
|
|
|
|
* and this will need the characters '$ ` \ "' escaped
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!commandShell->hasErrCtl) {
|
|
|
|
|
/* Worst that could happen is every char needs escaping. */
|
2005-02-16 18:11:52 +03:00
|
|
|
|
escCmd = emalloc((strlen(cmd) * 2) + 1);
|
2003-12-20 03:18:22 +03:00
|
|
|
|
for (i = 0, j= 0; cmd[i] != '\0'; i++, j++) {
|
|
|
|
|
if (cmd[i] == '$' || cmd[i] == '`' || cmd[i] == '\\' ||
|
|
|
|
|
cmd[i] == '"')
|
|
|
|
|
escCmd[j++] = '\\';
|
|
|
|
|
escCmd[j] = cmd[i];
|
|
|
|
|
}
|
|
|
|
|
escCmd[j] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (shutUp) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!(job->flags & JOB_SILENT) && !noSpecials &&
|
1993-03-21 12:45:37 +03:00
|
|
|
|
commandShell->hasEchoCtl) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
2003-12-20 03:18:22 +03:00
|
|
|
|
if (commandShell->hasErrCtl)
|
|
|
|
|
shutUp = FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errOff) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if ( !(job->flags & JOB_IGNERR) && !noSpecials) {
|
1993-03-21 12:45:37 +03: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?
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!(job->flags & JOB_SILENT) && !shutUp &&
|
1993-03-21 12:45:37 +03:00
|
|
|
|
commandShell->hasEchoCtl) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
|
|
|
|
DBPRINTF("%s\n", commandShell->ignErr);
|
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOn);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
2003-12-20 03:18:22 +03:00
|
|
|
|
DBPRINTF("%s\n", commandShell->ignErr);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
} else if (commandShell->ignErr &&
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(*commandShell->ignErr != '\0'))
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
2003-12-20 03:18:22 +03:00
|
|
|
|
if (!(job->flags & JOB_SILENT) && !shutUp) {
|
|
|
|
|
if (commandShell->hasEchoCtl) {
|
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
|
|
|
|
}
|
|
|
|
|
DBPRINTF(commandShell->errCheck, escCmd);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
shutUp = TRUE;
|
2003-12-20 03:18:22 +03:00
|
|
|
|
} else {
|
|
|
|
|
if (!shutUp) {
|
|
|
|
|
DBPRINTF(commandShell->errCheck, escCmd);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
cmdTemplate = commandShell->ignErr;
|
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* The error ignoration (hee hee) is already taken care
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* of by the ignErr template, so pretend error checking
|
|
|
|
|
* is still on.
|
|
|
|
|
*/
|
|
|
|
|
errOff = FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
errOff = FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
errOff = FALSE;
|
|
|
|
|
}
|
2003-12-20 03:18:22 +03:00
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If errors are being checked and the shell doesn't have error control
|
|
|
|
|
* but does supply an errOut template, then setup commands to run
|
|
|
|
|
* through it.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!commandShell->hasErrCtl && commandShell->errOut &&
|
|
|
|
|
(*commandShell->errOut != '\0')) {
|
|
|
|
|
if (!(job->flags & JOB_SILENT) && !shutUp) {
|
|
|
|
|
if (commandShell->hasEchoCtl) {
|
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
|
|
|
|
}
|
|
|
|
|
DBPRINTF(commandShell->errCheck, escCmd);
|
|
|
|
|
shutUp = TRUE;
|
|
|
|
|
}
|
2005-06-16 22:07:45 +04:00
|
|
|
|
/* If it's a comment line or blank, treat as an ignored error */
|
|
|
|
|
if ((escCmd[0] == commandShell->commentChar) ||
|
|
|
|
|
(escCmd[0] == 0))
|
2003-12-20 03:18:22 +03:00
|
|
|
|
cmdTemplate = commandShell->ignErr;
|
|
|
|
|
else
|
|
|
|
|
cmdTemplate = commandShell->errOut;
|
|
|
|
|
errOff = FALSE;
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2001-06-02 00:33:37 +04:00
|
|
|
|
if (DEBUG(SHELL) && strcmp(shellName, "sh") == 0 &&
|
|
|
|
|
(job->flags & JOB_TRACED) == 0) {
|
|
|
|
|
DBPRINTF("set -%s\n", "x");
|
|
|
|
|
job->flags |= JOB_TRACED;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-20 15:23:25 +04:00
|
|
|
|
if ((cp = Check_Cwd_Cmd(cmd)) != NULL) {
|
2001-10-16 22:06:29 +04:00
|
|
|
|
DBPRINTF("test -d %s && ", cp);
|
2005-02-01 01:41:43 +03:00
|
|
|
|
DBPRINTF("cd %s\n", cp);
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
DBPRINTF(cmdTemplate, cmd);
|
1998-11-01 06:07:33 +03:00
|
|
|
|
free(cmdStart);
|
2003-12-20 03:18:22 +03:00
|
|
|
|
if (escCmd)
|
|
|
|
|
free(escCmd);
|
1993-03-21 12:45:37 +03: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...
|
|
|
|
|
*/
|
|
|
|
|
if (!shutUp && !(job->flags & JOB_SILENT) && commandShell->hasEchoCtl){
|
1995-11-03 02:54:35 +03:00
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOff);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
shutUp = TRUE;
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
DBPRINTF("%s\n", commandShell->errCheck);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2003-12-20 03:18:22 +03:00
|
|
|
|
if (shutUp && commandShell->hasEchoCtl) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
DBPRINTF("%s\n", commandShell->echoOn);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2005-02-01 01:41:43 +03:00
|
|
|
|
if (cp != NULL) {
|
|
|
|
|
DBPRINTF("test -d %s && ", cp);
|
|
|
|
|
DBPRINTF("cd %s\n", Var_Value(".OBJDIR", VAR_GLOBAL, &tmp));
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03: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-06-15 22:24:55 +04:00
|
|
|
|
JobSaveCommand(ClientData cmd, ClientData gn)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
cmd = (ClientData) Var_Subst(NULL, (char *) cmd, (GNode *) gn, FALSE);
|
|
|
|
|
(void) Lst_AtEnd(postCommands->commands, cmd);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* 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-06-15 22:24:55 +04:00
|
|
|
|
JobClose(Job *job)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
{
|
2000-12-04 20:45:17 +03:00
|
|
|
|
if (usePipes && (job->flags & JOB_FIRST)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef RMT_WILL_WATCH
|
|
|
|
|
Rmt_Ignore(job->inPipe);
|
2000-12-03 05:19:32 +03:00
|
|
|
|
#else
|
2000-12-04 20:45:17 +03:00
|
|
|
|
clearfd(job);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
|
|
|
|
if (job->outPipe != job->inPipe) {
|
|
|
|
|
(void) close(job->outPipe);
|
|
|
|
|
}
|
|
|
|
|
JobDoOutput(job, TRUE);
|
|
|
|
|
(void) close(job->inPipe);
|
|
|
|
|
} else {
|
|
|
|
|
(void) close(job->outFd);
|
|
|
|
|
JobDoOutput(job, TRUE);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* job job to finish
|
|
|
|
|
* status sub-why job went away
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* None
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* Final commands for the job are placed on postCommands.
|
|
|
|
|
*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* If we got an error and are aborting (aborting == ABORT_ERROR) and
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* the job list is now empty, we are done for the day.
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* If we recognized an error (errors !=0), we set the aborting flag
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* to ABORT_ERROR so no more jobs will be started.
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
/*ARGSUSED*/
|
1994-03-05 03:34:29 +03:00
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobFinish(Job *job, int *status)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-22 20:39:53 +03:00
|
|
|
|
Boolean done;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if ((WIFEXITED(*status) &&
|
|
|
|
|
(((WEXITSTATUS(*status) != 0) && !(job->flags & JOB_IGNERR)))) ||
|
1999-07-16 09:38:20 +04:00
|
|
|
|
WIFSIGNALED(*status))
|
1993-03-21 12:45:37 +03: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...
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
KILL(job->pid, SIGCONT);
|
|
|
|
|
#endif
|
|
|
|
|
JobClose(job);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fclose(job->cmdFILE);
|
2000-12-03 04:27:03 +03:00
|
|
|
|
job->cmdFILE = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
done = TRUE;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
if (job->flags & JOB_REMOTE)
|
|
|
|
|
Rmt_Done(job->rmtID, job->node);
|
|
|
|
|
#endif
|
|
|
|
|
} else if (WIFEXITED(*status)) {
|
1993-03-21 12:45:37 +03: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
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* TRUE if in -B mode and the job exited non-zero.
|
|
|
|
|
*/
|
|
|
|
|
done = WEXITSTATUS(*status) != 0;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
/*
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* Old comment said: "Note we don't
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* want to close down any of the streams until we know we're at the
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* end."
|
|
|
|
|
* But we do. Otherwise when are we going to print the rest of the
|
|
|
|
|
* stuff?
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobClose(job);
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
if (job->flags & JOB_REMOTE)
|
|
|
|
|
Rmt_Done(job->rmtID, job->node);
|
|
|
|
|
#endif /* REMOTE */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* No need to close things down or anything.
|
|
|
|
|
*/
|
|
|
|
|
done = FALSE;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (done ||
|
1995-11-03 02:54:35 +03:00
|
|
|
|
WIFSTOPPED(*status) ||
|
1999-07-16 09:38:20 +04:00
|
|
|
|
(WIFSIGNALED(*status) && (WTERMSIG(*status) == SIGCONT)))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
FILE *out;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (compatMake && !usePipes && (job->flags & JOB_IGNERR)) {
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
out = fdopen(job->outFd, "w");
|
2000-12-03 04:27:03 +03:00
|
|
|
|
if (out == NULL)
|
|
|
|
|
Punt("Cannot fdopen");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
out = stdout;
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (WIFEXITED(*status)) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(stdout, "Process %d [%s] exited.\n",
|
|
|
|
|
job->pid, job->node->name);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
if (WEXITSTATUS(*status) != 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (usePipes && job->node != lastNode) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
MESSAGE(out, job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
lastNode = job->node;
|
|
|
|
|
}
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(out, "*** [%s] Error code %d%s\n",
|
|
|
|
|
job->node->name,
|
1995-11-03 02:54:35 +03:00
|
|
|
|
WEXITSTATUS(*status),
|
|
|
|
|
(job->flags & JOB_IGNERR) ? "(ignored)" : "");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
if (job->flags & JOB_IGNERR) {
|
1995-11-22 20:39:53 +03:00
|
|
|
|
*status = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
} else if (DEBUG(JOB)) {
|
|
|
|
|
if (usePipes && job->node != lastNode) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
MESSAGE(out, job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
lastNode = job->node;
|
|
|
|
|
}
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(out, "*** [%s] Completed successfully\n",
|
|
|
|
|
job->node->name);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
}
|
1999-07-16 09:38:20 +04:00
|
|
|
|
} else if (WIFSTOPPED(*status) && WSTOPSIG(*status) != SIGCONT) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(stdout, "Process %d (%s) stopped.\n",
|
|
|
|
|
job->pid, job->node->name);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
if (usePipes && job->node != lastNode) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
MESSAGE(out, job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
lastNode = job->node;
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!(job->flags & JOB_REMIGRATE)) {
|
1999-07-16 09:38:20 +04:00
|
|
|
|
switch (WSTOPSIG(*status)) {
|
|
|
|
|
case SIGTSTP:
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(out, "*** [%s] Suspended\n",
|
|
|
|
|
job->node->name);
|
1999-07-16 09:38:20 +04:00
|
|
|
|
break;
|
|
|
|
|
case SIGSTOP:
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(out, "*** [%s] Stopped\n",
|
|
|
|
|
job->node->name);
|
1999-07-16 09:38:20 +04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(out, "*** [%s] Stopped -- signal %d\n",
|
|
|
|
|
job->node->name, WSTOPSIG(*status));
|
1999-07-16 09:38:20 +04:00
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
job->flags |= JOB_RESUME;
|
|
|
|
|
(void)Lst_AtEnd(stoppedJobs, (ClientData)job);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
if (job->flags & JOB_REMIGRATE)
|
|
|
|
|
JobRestart(job);
|
|
|
|
|
#endif
|
|
|
|
|
(void) fflush(out);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
return;
|
1999-07-16 09:38:20 +04:00
|
|
|
|
} else if (WIFSTOPPED(*status) && WSTOPSIG(*status) == SIGCONT) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* If the beastie has continued, shift the Job from the stopped
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* list to the running one (or re-stop it if concurrency is
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* exceeded) and go and get another child.
|
|
|
|
|
*/
|
|
|
|
|
if (job->flags & (JOB_RESUME|JOB_REMIGRATE|JOB_RESTART)) {
|
|
|
|
|
if (usePipes && job->node != lastNode) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
MESSAGE(out, job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
lastNode = job->node;
|
|
|
|
|
}
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(out, "*** [%s] Continued\n", job->node->name);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!(job->flags & JOB_CONTINUING)) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
2002-03-13 20:43:31 +03:00
|
|
|
|
"Warning: process %d [%s] was not continuing.\n",
|
|
|
|
|
job->pid, job->node->name);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03: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
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
job->flags &= ~JOB_CONTINUING;
|
|
|
|
|
Lst_AtEnd(jobs, (ClientData)job);
|
|
|
|
|
nJobs += 1;
|
|
|
|
|
if (!(job->flags & JOB_REMOTE)) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
|
|
|
|
"Process %d is continuing locally.\n",
|
|
|
|
|
job->pid);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
nLocal += 1;
|
|
|
|
|
}
|
|
|
|
|
(void) fflush(out);
|
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
if (usePipes && job->node != lastNode) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
MESSAGE(out, job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
lastNode = job->node;
|
|
|
|
|
}
|
2002-03-13 20:43:31 +03:00
|
|
|
|
(void) fprintf(out, "*** [%s] Signal %d\n",
|
|
|
|
|
job->node->name, WTERMSIG(*status));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(out);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03: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;
|
1999-07-16 09:38:20 +04:00
|
|
|
|
*status = W_EXITCODE(1, 0);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
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;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
done = TRUE;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2000-12-30 17:21:22 +03:00
|
|
|
|
if (done) {
|
|
|
|
|
Trace_Log(JOBEND, job);
|
2000-12-30 18:58:34 +03:00
|
|
|
|
if (!compatMake && !(job->flags & JOB_SPECIAL)) {
|
2000-12-30 17:21:22 +03:00
|
|
|
|
if ((*status != 0) ||
|
|
|
|
|
(aborting == ABORT_ERROR) ||
|
|
|
|
|
(aborting == ABORT_INTERRUPT))
|
|
|
|
|
Job_TokenReturn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
if (done &&
|
|
|
|
|
(aborting != ABORT_ERROR) &&
|
|
|
|
|
(aborting != ABORT_INTERRUPT) &&
|
1995-11-22 20:39:53 +03:00
|
|
|
|
(*status == 0))
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
|
|
|
|
if (job->tailCmds != NILLNODE) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Lst_ForEachFrom(job->node->commands, job->tailCmds,
|
1993-03-21 12:45:37 +03:00
|
|
|
|
JobSaveCommand,
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(ClientData)job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
job->node->made = MADE;
|
2000-12-30 18:58:34 +03:00
|
|
|
|
if (!(job->flags & JOB_SPECIAL))
|
|
|
|
|
Job_TokenReturn();
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Make_Update(job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
free((Address)job);
|
1996-05-29 19:28:05 +04:00
|
|
|
|
} else if (*status != 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
errors += 1;
|
|
|
|
|
free((Address)job);
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobRestartJobs();
|
1993-03-21 12:45:37 +03: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;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if ((aborting == ABORT_ERROR) && Job_Empty()) {
|
|
|
|
|
/*
|
|
|
|
|
* If we are aborting and the job table is now empty, we finish.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Finish(errors);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_Touch --
|
|
|
|
|
* Touch the given target. Called by JobStart when the -t flag was
|
|
|
|
|
* given
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* gn the node of the file to touch
|
|
|
|
|
* silent TRUE if should not print message
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03: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-06-15 22:24:55 +04:00
|
|
|
|
Job_Touch(GNode *gn, Boolean silent)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
int streamID; /* ID of stream opened to do the touch */
|
1996-02-05 01:20:27 +03:00
|
|
|
|
struct utimbuf times; /* Times for utime() call */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
2001-07-03 22:08:50 +04:00
|
|
|
|
if (gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC|OP_OPTIONAL|OP_PHONY)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* .JOIN, .USE, .ZEROTIME and .OPTIONAL targets are "virtual" targets
|
|
|
|
|
* and, as such, shouldn't really be created.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2001-01-01 18:47:37 +03:00
|
|
|
|
if (!silent || NoExecute(gn)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "touch %s\n", gn->name);
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-01 18:47:37 +03:00
|
|
|
|
if (NoExecute(gn)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gn->type & OP_ARCHV) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Arch_Touch(gn);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else if (gn->type & OP_LIB) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Arch_TouchLib(gn);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
char *file = gn->path ? gn->path : gn->name;
|
|
|
|
|
|
1996-02-05 01:20:27 +03:00
|
|
|
|
times.actime = times.modtime = now;
|
|
|
|
|
if (utime(file, ×) < 0){
|
1995-11-03 02:54:35 +03:00
|
|
|
|
streamID = open(file, O_RDWR | O_CREAT, 0666);
|
1993-03-21 12:45:37 +03: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) {
|
1997-08-25 23:31:43 +04:00
|
|
|
|
(void) lseek(streamID, (off_t)0, SEEK_SET);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) write(streamID, &c, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) close(streamID);
|
|
|
|
|
} else {
|
|
|
|
|
(void) fprintf(stdout, "*** couldn't touch %s: %s",
|
|
|
|
|
file, strerror(errno));
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_CheckCommands --
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* Make sure the given node has all the commands it needs.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* gn The target whose commands need verifying
|
|
|
|
|
* abortProc Function to abort with message
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03: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
|
2003-07-14 22:19:11 +04:00
|
|
|
|
Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (OP_NOP(gn->type) && Lst_IsEmpty(gn->commands) &&
|
2003-04-08 21:46:59 +04:00
|
|
|
|
((gn->type & OP_LIB) == 0 || Lst_IsEmpty(gn->children))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* No commands. Look for .DEFAULT rule from which we might infer
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* commands
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
2005-06-29 23:59:42 +04:00
|
|
|
|
if ((DEFAULT != NILGNODE) && !Lst_IsEmpty(DEFAULT->commands) &&
|
|
|
|
|
(gn->type & OP_SPECIAL) == 0) {
|
1994-06-07 02:45:17 +04:00
|
|
|
|
char *p1;
|
1993-03-21 12:45:37 +03: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);
|
2001-06-13 03:36:17 +04:00
|
|
|
|
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn, 0);
|
1994-06-07 02:45:17 +04:00
|
|
|
|
if (p1)
|
|
|
|
|
free(p1);
|
2005-05-08 08:19:12 +04:00
|
|
|
|
} else if (Dir_MTime(gn) == 0 && (gn->type & OP_SPECIAL) == 0) {
|
1993-03-21 12:45:37 +03: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
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* this node's parents so they never get examined.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
2001-01-10 18:54:00 +03:00
|
|
|
|
static const char msg[] = ": don't know how to make";
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (gn->type & OP_OPTIONAL) {
|
2001-01-10 18:54:00 +03:00
|
|
|
|
(void) fprintf(stdout, "%s%s %s(ignored)\n", progname,
|
|
|
|
|
msg, gn->name);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else if (keepgoing) {
|
2001-01-10 18:54:00 +03:00
|
|
|
|
(void) fprintf(stdout, "%s%s %s(continuing)\n", progname,
|
|
|
|
|
msg, gn->name);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
return FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
2001-01-10 18:54:00 +03:00
|
|
|
|
(*abortProc)("%s%s %s. Stop", progname, msg, gn->name);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
return FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
return TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
#ifdef RMT_WILL_WATCH
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobLocalInput --
|
|
|
|
|
* Handle a pipe becoming readable. Callback function for Rmt_Watch
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* stream Stream that's ready (ignored)
|
|
|
|
|
* job Job to which the stream belongs
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* None
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* JobDoOutput is called.
|
1996-11-06 20:58:58 +03:00
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobLocalInput(int stream, Job *job)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
JobDoOutput(job, FALSE);
|
|
|
|
|
}
|
|
|
|
|
#endif /* RMT_WILL_WATCH */
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobExec --
|
|
|
|
|
* Execute the shell for the given job. Called from JobStart and
|
|
|
|
|
* JobRestart.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* job Job to execute
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* A shell is executed, outputs is altered and the Job structure added
|
|
|
|
|
* to the job table.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobExec(Job *job, char **argv)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
int cpid; /* ID of new child */
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigset_t mask;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2001-06-02 00:33:37 +04:00
|
|
|
|
job->flags &= ~JOB_TRACED;
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
int i;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "Running %s %sly\n", job->node->name,
|
|
|
|
|
job->flags&JOB_REMOTE?"remote":"local");
|
|
|
|
|
(void) fprintf(stdout, "\tCommand: ");
|
|
|
|
|
for (i = 0; argv[i] != NULL; i++) {
|
|
|
|
|
(void) fprintf(stdout, "%s ", argv[i]);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "\n");
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Some jobs produce no output and it's disconcerting to have
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* no feedback of their running (since they produce no output, the
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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) &&
|
1995-11-03 02:54:35 +03:00
|
|
|
|
!(job->flags & JOB_SILENT)) {
|
|
|
|
|
MESSAGE(stdout, job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
lastNode = job->node;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifdef RMT_NO_EXEC
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
|
|
|
|
goto jobExecFinish;
|
|
|
|
|
}
|
|
|
|
|
#endif /* RMT_NO_EXEC */
|
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
/* No interruptions until this job is on the `jobs' list */
|
|
|
|
|
JobSigLock(&mask);
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if ((cpid = vfork()) == -1) {
|
2001-07-24 09:06:40 +04:00
|
|
|
|
Punt("Cannot vfork: %s", strerror(errno));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else if (cpid == 0) {
|
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
/*
|
|
|
|
|
* Reset all signal handlers; this is necessary because we also
|
|
|
|
|
* need to unblock signals before we exec(2).
|
|
|
|
|
*/
|
|
|
|
|
JobSigReset();
|
|
|
|
|
|
|
|
|
|
/* Now unblock signals */
|
2002-12-09 04:23:53 +03:00
|
|
|
|
sigemptyset(&mask);
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigUnlock(&mask);
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Must duplicate the input stream down to the child's input and
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* reset it to the beginning (again). Since the stream was marked
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* close-on-exec, we must clear that bit in the new input.
|
|
|
|
|
*/
|
2002-03-14 19:08:37 +03:00
|
|
|
|
if (dup2(FILENO(job->cmdFILE), 0) == -1) {
|
|
|
|
|
execError("dup2", "job->cmdFILE");
|
|
|
|
|
_exit(1);
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fcntl(0, F_SETFD, 0);
|
1997-08-25 23:31:43 +04:00
|
|
|
|
(void) lseek(0, (off_t)0, SEEK_SET);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
|
if (job->node->type & OP_MAKE) {
|
|
|
|
|
/*
|
|
|
|
|
* Pass job token pipe to submakes.
|
|
|
|
|
*/
|
|
|
|
|
fcntl(job_pipe[0], F_SETFD, 0);
|
|
|
|
|
fcntl(job_pipe[1], F_SETFD, 0);
|
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (usePipes) {
|
|
|
|
|
/*
|
|
|
|
|
* Set up the child's output to be routed through the pipe
|
|
|
|
|
* we've created for it.
|
|
|
|
|
*/
|
2002-03-14 19:08:37 +03:00
|
|
|
|
if (dup2(job->outPipe, 1) == -1) {
|
|
|
|
|
execError("dup2", "job->outPipe");
|
|
|
|
|
_exit(1);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* We're capturing output in a file, so we duplicate the
|
|
|
|
|
* descriptor to the temporary file into the standard
|
|
|
|
|
* output.
|
|
|
|
|
*/
|
2002-03-14 19:08:37 +03:00
|
|
|
|
if (dup2(job->outFd, 1) == -1) {
|
|
|
|
|
execError("dup2", "job->outFd");
|
|
|
|
|
_exit(1);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* The output channels are marked close on exec. This bit was
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* duplicated by the dup2 (on some systems), so we have to clear
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* it before routing the shell's error output to the same place as
|
|
|
|
|
* its standard output.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fcntl(1, F_SETFD, 0);
|
2002-03-14 19:08:37 +03:00
|
|
|
|
if (dup2(1, 2) == -1) {
|
|
|
|
|
execError("dup2", "1, 2");
|
|
|
|
|
_exit(1);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
# if defined(SYSV)
|
|
|
|
|
(void) setsid();
|
|
|
|
|
# else
|
|
|
|
|
(void) setpgid(0, getpid());
|
|
|
|
|
# endif
|
|
|
|
|
#endif /* USE_PGRP */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
|
|
|
|
Rmt_Exec(shellPath, argv, FALSE);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
} else
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif /* REMOTE */
|
2001-05-29 21:37:51 +04:00
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) execv(shellPath, argv);
|
2002-03-14 19:08:37 +03:00
|
|
|
|
execError("exec", shellPath);
|
2001-05-29 21:37:51 +04:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
_exit(1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
job->pid = cpid;
|
|
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
|
Trace_Log(JOBSTART, job);
|
|
|
|
|
|
2000-12-04 20:45:17 +03:00
|
|
|
|
if (usePipes && (job->flags & JOB_FIRST)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
job->curPos = 0;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifdef RMT_WILL_WATCH
|
|
|
|
|
Rmt_Watch(job->inPipe, JobLocalInput, job);
|
2000-12-03 05:19:32 +03:00
|
|
|
|
#else
|
2000-12-04 20:45:17 +03:00
|
|
|
|
watchfd(job);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#endif /* RMT_WILL_WATCH */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifndef REMOTE
|
1994-03-05 03:34:29 +03:00
|
|
|
|
job->rmtID = 0;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#else
|
|
|
|
|
job->rmtID = Rmt_LastID(job->pid);
|
|
|
|
|
#endif /* REMOTE */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
nLocal += 1;
|
|
|
|
|
/*
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* XXX: Used to not happen if REMOTE. Why?
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (job->cmdFILE != NULL && job->cmdFILE != stdout) {
|
|
|
|
|
(void) fclose(job->cmdFILE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
job->cmdFILE = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#ifdef RMT_NO_EXEC
|
1996-11-06 20:58:58 +03:00
|
|
|
|
jobExecFinish:
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Now the job is actually running, add it to the table.
|
|
|
|
|
*/
|
2002-03-18 16:28:25 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
printf("JobExec(%s): pid %d added to jobs table\n",
|
|
|
|
|
job->node->name, job->pid);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
nJobs += 1;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) Lst_AtEnd(jobs, (ClientData)job);
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigUnlock(&mask);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobMakeArgv --
|
|
|
|
|
* Create the argv needed to execute the shell for a given job.
|
1996-11-06 20:58:58 +03:00
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
* Results:
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobMakeArgv(Job *job, char **argv)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
int argc;
|
2003-07-14 22:19:11 +04:00
|
|
|
|
static char args[10]; /* For merged arguments */
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2003-07-14 22:19:11 +04:00
|
|
|
|
argv[0] = UNCONST(shellName);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
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.
|
|
|
|
|
*/
|
1999-09-04 08:21:28 +04:00
|
|
|
|
(void)snprintf(args, sizeof(args), "-%s%s",
|
1993-03-21 12:45:37 +03: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) {
|
2003-07-14 22:19:11 +04:00
|
|
|
|
argv[argc] = UNCONST(commandShell->exit);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
argc++;
|
|
|
|
|
}
|
|
|
|
|
if (!(job->flags & JOB_SILENT) && commandShell->echo) {
|
2003-07-14 22:19:11 +04:00
|
|
|
|
argv[argc] = UNCONST(commandShell->echo);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
argc++;
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
argv[argc] = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobRestart --
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* Restart a job that stopped for some reason.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* job Job to restart
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
2002-02-08 20:44:23 +03:00
|
|
|
|
* 1 if max number of running jobs has been reached, 0 otherwise.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
2002-02-08 20:44:23 +03:00
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobRestart(Job *job)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
int host;
|
|
|
|
|
#endif
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (job->flags & JOB_REMIGRATE) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
verboseRemigrates ||
|
|
|
|
|
#endif
|
|
|
|
|
DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "*** remigrating %x(%s)\n",
|
|
|
|
|
job->pid, job->node->name);
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
if (!Rmt_ReExport(job->pid, job->node, &host)) {
|
|
|
|
|
if (verboseRemigrates || DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "*** couldn't migrate...\n");
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (nLocal != maxLocal) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Job cannot be remigrated, but there's room on the local
|
|
|
|
|
* machine, so resume the job and note that another
|
|
|
|
|
* local job has started.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
verboseRemigrates ||
|
|
|
|
|
#endif
|
|
|
|
|
DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "*** resuming on local machine\n");
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
KILL(job->pid, SIGCONT);
|
|
|
|
|
nLocal +=1;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
job->flags &= ~(JOB_REMIGRATE|JOB_RESUME|JOB_REMOTE);
|
|
|
|
|
job->flags |= JOB_CONTINUING;
|
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
|
job->flags &= ~(JOB_REMIGRATE|JOB_RESUME);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
2002-03-18 16:32:36 +03:00
|
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Job cannot be restarted. Mark the table as full and
|
|
|
|
|
* place the job back on the list of stopped jobs.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
verboseRemigrates ||
|
|
|
|
|
#endif
|
|
|
|
|
DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "*** holding\n");
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
(void)Lst_AtFront(stoppedJobs, (ClientData)job);
|
2002-02-08 20:44:23 +03:00
|
|
|
|
return 1;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Clear out the remigrate and resume flags. Set the continuing
|
|
|
|
|
* flag so we know later on that the process isn't exiting just
|
|
|
|
|
* because of a signal.
|
|
|
|
|
*/
|
|
|
|
|
job->flags &= ~(JOB_REMIGRATE|JOB_RESUME);
|
|
|
|
|
job->flags |= JOB_CONTINUING;
|
|
|
|
|
job->rmtID = host;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
(void)Lst_AtEnd(jobs, (ClientData)job);
|
|
|
|
|
nJobs += 1;
|
|
|
|
|
} else if (job->flags & JOB_RESTART) {
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* as soon as it starts processing commands.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1999-09-04 08:21:28 +04:00
|
|
|
|
char *argv[10];
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
JobMakeArgv(job, argv);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "Restarting %s...", job->node->name);
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
2002-03-18 16:32:36 +03:00
|
|
|
|
if ((job->node->type & OP_NOEXPORT) ||
|
1996-11-06 20:58:58 +03:00
|
|
|
|
(nLocal < maxLocal && runLocalFirst)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
# ifdef RMT_NO_EXEC
|
|
|
|
|
|| !Rmt_Export(shellPath, argv, job)
|
|
|
|
|
# else
|
|
|
|
|
|| !Rmt_Begin(shellPath, argv, job->node)
|
|
|
|
|
# endif
|
2002-03-18 16:32:36 +03:00
|
|
|
|
)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
if (((nLocal >= maxLocal) && !(job->flags & JOB_SPECIAL))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Can't be exported and not allowed to run locally -- put it
|
|
|
|
|
* back on the hold queue and mark the table full
|
|
|
|
|
*/
|
|
|
|
|
if (DEBUG(JOB)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "holding\n");
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
(void)Lst_AtFront(stoppedJobs, (ClientData)job);
|
2002-02-08 20:44:23 +03:00
|
|
|
|
return 1;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Job may be run locally.
|
|
|
|
|
*/
|
|
|
|
|
if (DEBUG(JOB)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "running locally\n");
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
job->flags &= ~JOB_REMOTE;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
else {
|
|
|
|
|
/*
|
|
|
|
|
* Can be exported. Hooray!
|
|
|
|
|
*/
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "exporting\n");
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
job->flags |= JOB_REMOTE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
JobExec(job, argv);
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* The job has stopped and needs to be restarted. Why it stopped,
|
|
|
|
|
* we don't know...
|
|
|
|
|
*/
|
|
|
|
|
if (DEBUG(JOB)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "Resuming %s...", job->node->name);
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2002-03-18 16:32:36 +03:00
|
|
|
|
if ((nJobs != maxJobs) &&
|
|
|
|
|
((job->flags & JOB_REMOTE) ||
|
|
|
|
|
(nLocal < maxLocal) ||
|
|
|
|
|
((maxLocal == 0) &&
|
|
|
|
|
((job->flags & JOB_SPECIAL)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
2002-03-18 16:32:36 +03:00
|
|
|
|
&& (job->node->type & OP_NOEXPORT)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
2002-03-18 16:32:36 +03:00
|
|
|
|
))))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* If the job is remote, it's ok to resume it as long as the
|
|
|
|
|
* maximum concurrency won't be exceeded. If it's local and
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* we haven't reached the local concurrency limit already (or the
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* job must be run locally and maxLocal is 0), it's also ok to
|
|
|
|
|
* resume it.
|
|
|
|
|
*/
|
|
|
|
|
Boolean error;
|
1995-11-22 20:39:53 +03:00
|
|
|
|
int status;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifdef RMT_WANTS_SIGNALS
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
|
|
|
|
error = !Rmt_Signal(job, SIGCONT);
|
|
|
|
|
} else
|
|
|
|
|
#endif /* RMT_WANTS_SIGNALS */
|
|
|
|
|
error = (KILL(job->pid, SIGCONT) != 0);
|
|
|
|
|
|
|
|
|
|
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;
|
1999-07-16 09:38:20 +04:00
|
|
|
|
status = W_STOPCODE(SIGCONT);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobFinish(job, &status);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
job->flags &= ~(JOB_RESUME|JOB_CONTINUING);
|
|
|
|
|
if (DEBUG(JOB)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "done\n");
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Error("couldn't resume %s: %s",
|
|
|
|
|
job->node->name, strerror(errno));
|
1999-07-16 09:38:20 +04:00
|
|
|
|
status = W_EXITCODE(1, 0);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobFinish(job, &status);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Job cannot be restarted. Mark the table as full and
|
|
|
|
|
* place the job back on the list of stopped jobs.
|
|
|
|
|
*/
|
|
|
|
|
if (DEBUG(JOB)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "table full\n");
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) Lst_AtFront(stoppedJobs, (ClientData)job);
|
2002-02-08 20:44:23 +03:00
|
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-08 20:44:23 +03:00
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobStart --
|
|
|
|
|
* Start a target-creation process going for the target described
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* by the graph node gn.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* gn target to create
|
|
|
|
|
* flags flags for the job to override normal ones.
|
|
|
|
|
* e.g. JOB_SPECIAL or JOB_IGNDOTS
|
|
|
|
|
* previous The previous Job structure for this node, if any.
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03: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-06-15 22:24:55 +04:00
|
|
|
|
JobStart(GNode *gn, int flags, Job *previous)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job *job; /* new job descriptor */
|
1999-09-04 08:21:28 +04:00
|
|
|
|
char *argv[10]; /* Argument vector to shell */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Boolean cmdsOK; /* true if the nodes commands were all right */
|
|
|
|
|
Boolean local; /* Set true if the job was run locally */
|
|
|
|
|
Boolean noExec; /* Set true if we decide not to run the job */
|
2000-01-20 02:39:37 +03:00
|
|
|
|
int tfd; /* File descriptor to the temp file */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (previous != NULL) {
|
|
|
|
|
previous->flags &= ~(JOB_FIRST|JOB_IGNERR|JOB_SILENT|JOB_REMOTE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
job = previous;
|
|
|
|
|
} else {
|
2005-02-16 18:11:52 +03:00
|
|
|
|
job = emalloc(sizeof(Job));
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (job == NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Punt("JobStart out of memory");
|
|
|
|
|
}
|
|
|
|
|
flags |= JOB_FIRST;
|
|
|
|
|
}
|
2005-05-08 04:38:47 +04:00
|
|
|
|
if (gn->type & OP_SPECIAL)
|
|
|
|
|
flags |= JOB_SPECIAL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
job->node = gn;
|
|
|
|
|
job->tailCmds = NILLNODE;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (Targ_Ignore(gn)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
job->flags |= JOB_IGNERR;
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (Targ_Silent(gn)) {
|
1993-03-21 12:45:37 +03: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
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!compatMake && job->flags & JOB_FIRST) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
cmdsOK = Job_CheckCommands(gn, Error);
|
|
|
|
|
} else {
|
|
|
|
|
cmdsOK = TRUE;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2000-12-04 20:45:17 +03:00
|
|
|
|
#ifndef RMT_WILL_WATCH
|
|
|
|
|
job->inPollfd = NULL;
|
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* If the -n flag wasn't given, we open up OUR (not the child's)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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?
|
|
|
|
|
*/
|
2001-01-01 18:47:37 +03:00
|
|
|
|
if (((gn->type & OP_MAKE) && !(noRecursiveExecute)) ||
|
|
|
|
|
(!noExecute && !touchFlag)) {
|
2000-12-03 04:27:03 +03:00
|
|
|
|
/*
|
|
|
|
|
* tfile is the name of a file into which all shell commands are
|
|
|
|
|
* put. It is used over by removing it before the child shell is
|
|
|
|
|
* executed. The XXXXXX in the string are replaced by the pid of
|
|
|
|
|
* the make process in a 6-character field with leading zeroes.
|
|
|
|
|
*/
|
|
|
|
|
char tfile[sizeof(TMPPAT)];
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigset_t mask;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* We're serious here, but if the commands were bogus, we're
|
|
|
|
|
* also dead...
|
|
|
|
|
*/
|
|
|
|
|
if (!cmdsOK) {
|
|
|
|
|
DieHorribly();
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigLock(&mask);
|
2003-07-16 11:16:24 +04:00
|
|
|
|
(void)strcpy(tfile, TMPPAT);
|
2000-01-20 02:39:37 +03:00
|
|
|
|
if ((tfd = mkstemp(tfile)) == -1)
|
|
|
|
|
Punt("Could not create temporary file %s", strerror(errno));
|
2005-06-17 23:25:20 +04:00
|
|
|
|
if (!DEBUG(SCRIPT))
|
|
|
|
|
(void) eunlink(tfile);
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigUnlock(&mask);
|
2000-01-20 02:39:37 +03:00
|
|
|
|
|
|
|
|
|
job->cmdFILE = fdopen(tfd, "w+");
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (job->cmdFILE == NULL) {
|
2000-01-20 02:39:37 +03:00
|
|
|
|
Punt("Could not fdopen %s", tfile);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fcntl(FILENO(job->cmdFILE), F_SETFD, 1);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
|
if (compatMake) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* 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 {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
LstNode ln = Lst_Next(gn->commands);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if ((ln == NILLNODE) ||
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobPrintCommand((ClientData) Lst_Datum(ln),
|
|
|
|
|
(ClientData) job))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
noExec = TRUE;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Lst_Close(gn->commands);
|
1993-03-21 12:45:37 +03: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...
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobClose(job);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* We can do all the commands at once. hooray for sanity
|
|
|
|
|
*/
|
|
|
|
|
numCommands = 0;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Lst_ForEach(gn->commands, JobPrintCommand, (ClientData)job);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-01 18:47:37 +03:00
|
|
|
|
} else if (NoExecute(gn)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* 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) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
MESSAGE(stdout, gn);
|
1993-03-21 12:45:37 +03: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) {
|
|
|
|
|
Lst_ForEach(gn->commands, JobPrintCommand, (ClientData)job);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* 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;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Job_Touch(gn, job->flags&JOB_SILENT);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
noExec = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* If we're not supposed to execute a shell, don't.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
|
|
|
|
if (noExec) {
|
|
|
|
|
/*
|
|
|
|
|
* Unlink and close the command file if we opened one
|
|
|
|
|
*/
|
|
|
|
|
if (job->cmdFILE != stdout) {
|
2000-12-03 04:27:03 +03:00
|
|
|
|
if (job->cmdFILE != NULL) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fclose(job->cmdFILE);
|
2000-12-03 04:27:03 +03:00
|
|
|
|
job->cmdFILE = NULL;
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03: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) {
|
|
|
|
|
if (job->tailCmds != NILLNODE) {
|
|
|
|
|
Lst_ForEachFrom(job->node->commands, job->tailCmds,
|
|
|
|
|
JobSaveCommand,
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(ClientData)job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2000-12-30 18:58:34 +03:00
|
|
|
|
if (!(job->flags & JOB_SPECIAL))
|
|
|
|
|
Job_TokenReturn();
|
2002-02-08 20:31:38 +03:00
|
|
|
|
job->node->made = MADE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Make_Update(job->node);
|
|
|
|
|
}
|
|
|
|
|
free((Address)job);
|
|
|
|
|
return(JOB_FINISHED);
|
|
|
|
|
} else {
|
|
|
|
|
free((Address)job);
|
|
|
|
|
return(JOB_ERROR);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(job->cmdFILE);
|
1993-03-21 12:45:37 +03: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
|
2000-01-20 02:39:37 +03:00
|
|
|
|
* starting a job and then set up its temporary-file name.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!compatMake || (job->flags & JOB_FIRST)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (usePipes) {
|
|
|
|
|
int fd[2];
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (pipe(fd) == -1)
|
|
|
|
|
Punt("Cannot create pipe: %s", strerror(errno));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
job->inPipe = fd[0];
|
|
|
|
|
job->outPipe = fd[1];
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fcntl(job->inPipe, F_SETFD, 1);
|
|
|
|
|
(void) fcntl(job->outPipe, F_SETFD, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "Remaking `%s'\n", gn->name);
|
|
|
|
|
(void) fflush(stdout);
|
2003-07-16 11:16:24 +04:00
|
|
|
|
(void) strcpy(job->outFile, TMPPAT);
|
2000-01-20 02:39:37 +03:00
|
|
|
|
job->outFd = mkstemp(job->outFile);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fcntl(job->outFd, F_SETFD, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
if (!(gn->type & OP_NOEXPORT) && !(runLocalFirst && nLocal < maxLocal)) {
|
|
|
|
|
#ifdef RMT_NO_EXEC
|
|
|
|
|
local = !Rmt_Export(shellPath, argv, job);
|
|
|
|
|
#else
|
|
|
|
|
local = !Rmt_Begin(shellPath, argv, job->node);
|
|
|
|
|
#endif /* RMT_NO_EXEC */
|
|
|
|
|
if (!local) {
|
|
|
|
|
job->flags |= JOB_REMOTE;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
local = TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
if (local && (((nLocal >= maxLocal) &&
|
1995-11-03 02:54:35 +03:00
|
|
|
|
!(job->flags & JOB_SPECIAL) &&
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
(!(gn->type & OP_NOEXPORT) || (maxLocal != 0))
|
|
|
|
|
#else
|
|
|
|
|
(maxLocal != 0)
|
|
|
|
|
#endif
|
|
|
|
|
)))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* The job can only be run locally, but we've hit the limit of
|
|
|
|
|
* local concurrency, so put the job on hold until some other job
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* finishes. Note that the special jobs (.BEGIN, .INTERRUPT and .END)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* may be run locally even when the local limit has been reached
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* (e.g. when maxLocal == 0), though they will be exported if at
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* all possible. In addition, any target marked with .NOEXPORT will
|
|
|
|
|
* be run locally if maxLocal is 0.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
|
|
|
|
job->flags |= JOB_RESTART;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) Lst_AtEnd(stoppedJobs, (ClientData)job);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
JobExec(job, argv);
|
|
|
|
|
}
|
|
|
|
|
return(JOB_RUNNING);
|
|
|
|
|
}
|
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
|
static char *
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobOutput(Job *job, char *cp, char *endp, int msg)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
{
|
2002-06-15 22:24:55 +04:00
|
|
|
|
char *ecp;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
|
|
|
|
if (commandShell->noPrint) {
|
|
|
|
|
ecp = Str_FindSubstring(cp, commandShell->noPrint);
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
(void) fprintf(stdout, "%s", cp);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
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++;
|
|
|
|
|
}
|
|
|
|
|
ecp = Str_FindSubstring(cp, commandShell->noPrint);
|
|
|
|
|
} else {
|
|
|
|
|
return cp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cp;
|
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03: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
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* alone on the line (the character after it is not \0 or \n), we
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* do print whatever follows it.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* job the job whose output needs printing
|
|
|
|
|
* finish TRUE if this is the last time we'll be called
|
|
|
|
|
* for this job
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* None
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* curPos may be shifted as may the contents of outBuf.
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
STATIC void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobDoOutput(Job *job, Boolean finish)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
Boolean gotNL = FALSE; /* true if got a newline */
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Boolean fbuf; /* true if our buffer filled up */
|
2002-06-15 22:24:55 +04:00
|
|
|
|
int nr; /* number of bytes read */
|
|
|
|
|
int i; /* auxiliary index into outBuf */
|
|
|
|
|
int max; /* limit for i (end of current data) */
|
1996-11-06 20:58:58 +03:00
|
|
|
|
int nRead; /* (Temporary) number of bytes read */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
FILE *oFILE; /* Stream pointer to shell's output file */
|
|
|
|
|
char inLine[132];
|
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (usePipes) {
|
|
|
|
|
/*
|
|
|
|
|
* Read as many bytes as will fit in the buffer.
|
|
|
|
|
*/
|
|
|
|
|
end_loop:
|
1995-11-03 02:54:35 +03:00
|
|
|
|
gotNL = FALSE;
|
|
|
|
|
fbuf = FALSE;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
nRead = read(job->inPipe, &job->outBuf[job->curPos],
|
1993-03-21 12:45:37 +03:00
|
|
|
|
JOB_BUFSIZE - job->curPos);
|
|
|
|
|
if (nRead < 0) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
perror("JobDoOutput(piperead)");
|
|
|
|
|
}
|
|
|
|
|
nr = 0;
|
|
|
|
|
} else {
|
|
|
|
|
nr = nRead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* If we hit the end-of-file (the job is dead), we must flush its
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03: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
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* TRUE.
|
1993-03-21 12:45:37 +03: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] = ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (!gotNL) {
|
|
|
|
|
job->curPos += nr;
|
|
|
|
|
if (job->curPos == JOB_BUFSIZE) {
|
|
|
|
|
/*
|
|
|
|
|
* If we've run out of buffer space, we have no choice
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* but to print the stuff. sigh.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
fbuf = TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
i = job->curPos;
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (gotNL || fbuf) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Need to send the output to the screen. Null terminate it
|
|
|
|
|
* first, overwriting the newline character if there was one.
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* So long as the line isn't one we should filter (according
|
2001-08-20 16:00:46 +04:00
|
|
|
|
* to the shell description), we print the line, preceded
|
1993-03-21 12:45:37 +03: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
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* to the start of the buffer and curPos is set accordingly.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
|
|
|
|
job->outBuf[i] = '\0';
|
|
|
|
|
if (i >= job->curPos) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
char *cp;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
|
|
|
|
cp = JobOutput(job, job->outBuf, &job->outBuf[i], FALSE);
|
1993-03-21 12:45:37 +03: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) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
MESSAGE(stdout, job->node);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
lastNode = job->node;
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "%s%s", cp, gotNL ? "\n" : "");
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i < max - 1) {
|
1994-03-05 03:34:29 +03:00
|
|
|
|
/* shift the remaining characters down */
|
1996-11-06 20:58:58 +03:00
|
|
|
|
(void) memcpy(job->outBuf, &job->outBuf[i + 1], max - (i + 1));
|
|
|
|
|
job->curPos = max - (i + 1);
|
|
|
|
|
|
1993-03-21 12:45:37 +03: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-11-06 20:58:58 +03: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.
|
1993-03-21 12:45:37 +03: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..."
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
oFILE = fopen(job->outFile, "r");
|
|
|
|
|
if (oFILE != NULL) {
|
|
|
|
|
(void) fprintf(stdout, "Results of making %s:\n", job->node->name);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
while (fgets(inLine, sizeof(inLine), oFILE) != NULL) {
|
2002-06-15 22:24:55 +04:00
|
|
|
|
char *cp, *endp, *oendp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
cp = inLine;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
oendp = endp = inLine + strlen(inLine);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (endp[-1] == '\n') {
|
|
|
|
|
*--endp = '\0';
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
cp = JobOutput(job, inLine, endp, FALSE);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fprintf(stdout, "%s", cp);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
if (endp != oendp) {
|
|
|
|
|
(void) fprintf(stdout, "\n");
|
|
|
|
|
(void) fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fclose(oFILE);
|
|
|
|
|
(void) eunlink(job->outFile);
|
2000-12-03 04:27:03 +03:00
|
|
|
|
} else {
|
|
|
|
|
Punt("Cannot open `%s'", job->outFile);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-08 04:38:47 +04:00
|
|
|
|
static void
|
|
|
|
|
JobRun(GNode *targ)
|
|
|
|
|
{
|
|
|
|
|
#ifdef notyet
|
|
|
|
|
/*
|
|
|
|
|
* Unfortunately it is too complicated to run .BEGIN, .END,
|
|
|
|
|
* and .INTERRUPT job in the parallel job module. This has
|
|
|
|
|
* the nice side effect that it avoids a lot of other problems.
|
|
|
|
|
*/
|
|
|
|
|
Lst lst = Lst_Init(FALSE);
|
|
|
|
|
Lst_AtEnd(lst, targ);
|
|
|
|
|
(void)Make_Run(lst);
|
|
|
|
|
Lst_Destroy(lst, NOFREE);
|
|
|
|
|
JobStart(targ, JOB_SPECIAL, (Job *)0);
|
|
|
|
|
while (nJobs) {
|
|
|
|
|
Job_CatchOutput();
|
|
|
|
|
#ifndef RMT_WILL_WATCH
|
|
|
|
|
Job_CatchChildren(!usePipes);
|
|
|
|
|
#endif /* RMT_WILL_WATCH */
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
Compat_Make(targ, targ);
|
|
|
|
|
if (targ->made == ERROR) {
|
|
|
|
|
PrintOnError("\n\nStop.");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_CatchChildren --
|
|
|
|
|
* Handle the exit of a child. Called from Make_Make.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* block TRUE if should block on the wait
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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-06-15 22:24:55 +04:00
|
|
|
|
Job_CatchChildren(Boolean block)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
int pid; /* pid of dead child */
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job *job; /* job descriptor for dead child */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
LstNode jnode; /* list element for finding job */
|
1995-11-22 20:39:53 +03:00
|
|
|
|
int status; /* Exit/termination status */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Don't even bother if we know there's no one around.
|
|
|
|
|
*/
|
|
|
|
|
if (nLocal == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-22 20:39:53 +03:00
|
|
|
|
while ((pid = waitpid((pid_t) -1, &status,
|
|
|
|
|
(block?0:WNOHANG)|WUNTRACED)) > 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
1999-07-16 09:38:20 +04:00
|
|
|
|
(void) fprintf(stdout, "Process %d exited or stopped %x.\n", pid,
|
|
|
|
|
status);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
jnode = Lst_Find(jobs, (ClientData)&pid, JobCmpPid);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (jnode == NILLNODE) {
|
1999-07-16 09:38:20 +04:00
|
|
|
|
if (WIFSTOPPED(status) && (WSTOPSIG(status) == SIGCONT)) {
|
1994-06-07 02:45:17 +04:00
|
|
|
|
jnode = Lst_Find(stoppedJobs, (ClientData) &pid, JobCmpPid);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (jnode == NILLNODE) {
|
1996-11-06 20:58:58 +03:00
|
|
|
|
Error("Resumed child (%d) not in table", pid);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
job = (Job *)Lst_Datum(jnode);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) Lst_Remove(stoppedJobs, jnode);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
1996-11-06 20:58:58 +03:00
|
|
|
|
Error("Child (%d) not in table?", pid);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
job = (Job *) Lst_Datum(jnode);
|
|
|
|
|
(void) Lst_Remove(jobs, jnode);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
nJobs -= 1;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
if (!(job->flags & JOB_REMOTE)) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
2002-03-18 16:28:25 +03:00
|
|
|
|
"Job queue has one fewer local process.\n");
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
nLocal -= 1;
|
|
|
|
|
}
|
|
|
|
|
#else
|
1993-03-21 12:45:37 +03:00
|
|
|
|
nLocal -= 1;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobFinish(job, &status);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_CatchOutput --
|
|
|
|
|
* Catch the output from our children, if we're using
|
|
|
|
|
* pipes do so. Otherwise just block time until we get a
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* signal (most likely a SIGCHLD) since there's no point in
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* just spinning when there's nothing to do and the reaping
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* of a child can wait for a while.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
* Results:
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* None
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* Output is read from pipes if we're piping.
|
|
|
|
|
* -----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job_CatchOutput(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
2000-12-03 05:19:32 +03:00
|
|
|
|
int nready;
|
2002-06-15 22:24:55 +04:00
|
|
|
|
LstNode ln;
|
|
|
|
|
Job *job;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#ifdef RMT_WILL_WATCH
|
1993-03-21 12:45:37 +03:00
|
|
|
|
int pnJobs; /* Previous nJobs */
|
1994-03-05 03:34:29 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
2000-12-30 17:21:22 +03:00
|
|
|
|
Job_TokenFlush();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifdef RMT_WILL_WATCH
|
|
|
|
|
pnJobs = nJobs;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* It is possible for us to be called with nJobs equal to 0. This happens
|
|
|
|
|
* if all the jobs finish and a job that is stopped cannot be run
|
|
|
|
|
* locally (eg if maxLocal is 0) and cannot be exported. The job will
|
|
|
|
|
* be placed back on the stoppedJobs queue, Job_Empty() will return false,
|
|
|
|
|
* Make_Run will call us again when there's nothing for which to wait.
|
|
|
|
|
* nJobs never changes, so we loop forever. Hence the check. It could
|
|
|
|
|
* be argued that we should sleep for a bit so as not to swamp the
|
|
|
|
|
* exportation system with requests. Perhaps we should.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: IT IS THE RESPONSIBILITY OF Rmt_Wait TO CALL Job_CatchChildren
|
|
|
|
|
* IN A TIMELY FASHION TO CATCH ANY LOCALLY RUNNING JOBS THAT EXIT.
|
|
|
|
|
* It may use the variable nLocal to determine if it needs to call
|
2005-02-16 18:11:52 +03:00
|
|
|
|
* Job_CatchChildren(if nLocal is 0, there's nothing for which to
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* wait...)
|
|
|
|
|
*/
|
|
|
|
|
while (nJobs != 0 && pnJobs == nJobs) {
|
|
|
|
|
Rmt_Wait();
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (usePipes) {
|
2000-12-30 05:05:20 +03:00
|
|
|
|
if ((nready = poll((wantToken ? fds : (fds + 1)),
|
2002-11-17 01:22:23 +03:00
|
|
|
|
(wantToken ? nfds : (nfds - 1)), POLL_MSEC)) <= 0) {
|
2000-12-03 05:19:32 +03:00
|
|
|
|
return;
|
2002-11-17 01:22:23 +03:00
|
|
|
|
} else {
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigset_t mask;
|
|
|
|
|
JobSigLock(&mask);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (Lst_Open(jobs) == FAILURE) {
|
|
|
|
|
Punt("Cannot open job table");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2002-11-17 01:22:23 +03:00
|
|
|
|
|
|
|
|
|
if (readyfd(&childExitJob)) {
|
|
|
|
|
char token;
|
|
|
|
|
(void) read(childExitJob.inPipe, &token, 1);
|
|
|
|
|
nready -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-03 05:19:32 +03:00
|
|
|
|
while (nready && (ln = Lst_Next(jobs)) != NILLNODE) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
job = (Job *) Lst_Datum(ln);
|
2002-11-17 01:22:23 +03:00
|
|
|
|
if (readyfd(job)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobDoOutput(job, FALSE);
|
2000-12-03 05:19:32 +03:00
|
|
|
|
nready -= 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Lst_Close(jobs);
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigUnlock(&mask);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* RMT_WILL_WATCH */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* 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-06-15 22:24:55 +04:00
|
|
|
|
Job_Make(GNode *gn)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) JobStart(gn, 0, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-01 04:39:52 +04:00
|
|
|
|
void
|
|
|
|
|
Shell_Init()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
if (commandShell->exit == NULL) {
|
|
|
|
|
commandShell->exit = "";
|
|
|
|
|
}
|
|
|
|
|
if (commandShell->echo == NULL) {
|
|
|
|
|
commandShell->echo = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_Init --
|
|
|
|
|
* Initialize the process module
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* maxproc the greatest number of jobs which may be running
|
|
|
|
|
* at one time
|
|
|
|
|
* maxlocal the greatest number of jobs which may be running
|
|
|
|
|
* at once
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* none
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* lists and counters are initialized
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job_Init(int maxproc, int maxlocal)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
GNode *begin; /* node for commands to do at the very start */
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
jobs = Lst_Init(FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
stoppedJobs = Lst_Init(FALSE);
|
|
|
|
|
maxJobs = maxproc;
|
|
|
|
|
maxLocal = maxlocal;
|
|
|
|
|
nJobs = 0;
|
|
|
|
|
nLocal = 0;
|
2000-12-30 05:05:20 +03:00
|
|
|
|
wantToken = FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
aborting = 0;
|
|
|
|
|
errors = 0;
|
|
|
|
|
|
|
|
|
|
lastNode = NILGNODE;
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (maxJobs == 1
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
|| noMessages
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* If only one job can run at a time, there's no need for a banner,
|
2000-12-30 05:05:20 +03:00
|
|
|
|
* is there?
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
|
|
|
|
targFmt = "";
|
|
|
|
|
} else {
|
|
|
|
|
targFmt = TARG_FMT;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
2003-08-01 04:39:52 +04:00
|
|
|
|
Shell_Init();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
2002-11-17 01:22:23 +03:00
|
|
|
|
if (pipe(exit_pipe) < 0)
|
|
|
|
|
Fatal("error in pipe: %s", strerror(errno));
|
2002-11-26 08:30:01 +03:00
|
|
|
|
fcntl(exit_pipe[0], F_SETFD, 1);
|
|
|
|
|
fcntl(exit_pipe[1], F_SETFD, 1);
|
2002-11-17 01:22:23 +03:00
|
|
|
|
|
|
|
|
|
childExitJob.inPipe = exit_pipe[0];
|
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigemptyset(&caught_signals);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
2002-11-17 01:22:23 +03:00
|
|
|
|
* Install a SIGCHLD handler.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
2002-11-17 01:22:23 +03:00
|
|
|
|
(void)signal(SIGCHLD, JobChildSig);
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigaddset(&caught_signals, SIGCHLD);
|
|
|
|
|
|
|
|
|
|
#define ADDSIG(s,h) \
|
|
|
|
|
if (signal(s, SIG_IGN) != SIG_IGN) { \
|
|
|
|
|
sigaddset(&caught_signals, s); \
|
|
|
|
|
(void) signal(s, h); \
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2002-03-18 16:28:25 +03:00
|
|
|
|
|
2000-12-05 18:20:10 +03:00
|
|
|
|
/*
|
2002-03-18 16:28:25 +03:00
|
|
|
|
* Catch the four signals that POSIX specifies if they aren't ignored.
|
|
|
|
|
* JobPassSig will take care of calling JobInterrupt if appropriate.
|
2000-12-05 18:20:10 +03:00
|
|
|
|
*/
|
2002-03-18 16:28:25 +03:00
|
|
|
|
ADDSIG(SIGINT, JobPassSig)
|
|
|
|
|
ADDSIG(SIGHUP, JobPassSig)
|
|
|
|
|
ADDSIG(SIGTERM, JobPassSig)
|
|
|
|
|
ADDSIG(SIGQUIT, JobPassSig)
|
|
|
|
|
|
1993-03-21 12:45:37 +03: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
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* we're giving each job its own process group (since then it won't get
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* signals from the terminal driver as we own the terminal)
|
|
|
|
|
*/
|
|
|
|
|
#if defined(RMT_WANTS_SIGNALS) || defined(USE_PGRP)
|
2002-03-18 16:28:25 +03:00
|
|
|
|
ADDSIG(SIGTSTP, JobPassSig)
|
|
|
|
|
ADDSIG(SIGTTOU, JobPassSig)
|
|
|
|
|
ADDSIG(SIGTTIN, JobPassSig)
|
|
|
|
|
ADDSIG(SIGWINCH, JobPassSig)
|
|
|
|
|
ADDSIG(SIGCONT, JobContinueSig)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#endif
|
2002-03-18 16:28:25 +03:00
|
|
|
|
#undef ADDSIG
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
begin = Targ_FindNode(".BEGIN", TARG_NOCREATE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
if (begin != NILGNODE) {
|
2005-05-08 04:38:47 +04:00
|
|
|
|
JobRun(begin);
|
|
|
|
|
if (begin->made == ERROR) {
|
|
|
|
|
PrintOnError("\n\nStop.");
|
|
|
|
|
exit(1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
postCommands = Targ_FindNode(".END", TARG_CREATE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
|
static void JobSigReset(void)
|
2002-03-18 16:28:25 +03:00
|
|
|
|
{
|
|
|
|
|
#define DELSIG(s) \
|
|
|
|
|
if (sigismember(&caught_signals, s)) { \
|
|
|
|
|
(void) signal(SIGINT, SIG_DFL); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DELSIG(SIGINT)
|
|
|
|
|
DELSIG(SIGHUP)
|
|
|
|
|
DELSIG(SIGQUIT)
|
|
|
|
|
DELSIG(SIGTERM)
|
|
|
|
|
#if defined(RMT_WANTS_SIGNALS) || defined(USE_PGRP)
|
|
|
|
|
DELSIG(SIGTSTP)
|
|
|
|
|
DELSIG(SIGTTOU)
|
|
|
|
|
DELSIG(SIGTTIN)
|
|
|
|
|
DELSIG(SIGWINCH)
|
|
|
|
|
DELSIG(SIGCONT)
|
|
|
|
|
#endif
|
|
|
|
|
#undef DELSIG
|
|
|
|
|
(void)signal(SIGCHLD, SIG_DFL);
|
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03: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-06-15 22:24:55 +04:00
|
|
|
|
Job_Empty(void)
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobRestartJobs();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
return(FALSE);
|
|
|
|
|
} else {
|
|
|
|
|
return(TRUE);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobMatchShell --
|
2002-03-18 10:54:33 +03:00
|
|
|
|
* Find a shell in 'shells' given its name.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
* Results:
|
|
|
|
|
* A pointer to the Shell structure.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static Shell *
|
2003-07-14 22:19:11 +04:00
|
|
|
|
JobMatchShell(const char *name)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
2002-03-18 10:54:33 +03:00
|
|
|
|
Shell *sh;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
for (sh = shells; sh->name != NULL; sh++) {
|
2002-03-18 10:54:33 +03:00
|
|
|
|
if (strcmp(name, sh->name) == 0)
|
|
|
|
|
return (sh);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2002-03-18 10:54:33 +03:00
|
|
|
|
return (NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_ParseShell --
|
|
|
|
|
* Parse a shell specification and set up commandShell, shellPath
|
|
|
|
|
* and shellName appropriately.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* line The shell spec
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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.
|
2002-03-18 10:54:33 +03:00
|
|
|
|
* path Location of shell.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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-06-15 22:24:55 +04:00
|
|
|
|
Job_ParseShell(char *line)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
2002-03-15 18:54:41 +03:00
|
|
|
|
char **words;
|
|
|
|
|
char **argv;
|
|
|
|
|
int argc;
|
|
|
|
|
char *path;
|
|
|
|
|
Shell newShell;
|
|
|
|
|
Boolean fullSpec = FALSE;
|
2002-03-18 10:54:33 +03:00
|
|
|
|
Shell *sh;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
1998-11-07 02:31:09 +03:00
|
|
|
|
while (isspace((unsigned char)*line)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
line++;
|
|
|
|
|
}
|
1998-03-26 22:20:36 +03:00
|
|
|
|
|
|
|
|
|
if (shellArgv)
|
2003-07-14 22:19:11 +04:00
|
|
|
|
free(UNCONST(shellArgv));
|
1998-03-26 22:20:36 +03:00
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
memset((Address)&newShell, 0, sizeof(newShell));
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Parse the specification by keyword
|
|
|
|
|
*/
|
2003-07-14 22:19:11 +04:00
|
|
|
|
words = brk_string(line, &argc, TRUE, &path);
|
|
|
|
|
shellArgv = path;
|
2002-03-15 18:54:41 +03:00
|
|
|
|
|
|
|
|
|
for (path = NULL, argv = words; argc != 0; argc--, argv++) {
|
1998-03-26 22:20:36 +03:00
|
|
|
|
if (strncmp(*argv, "path=", 5) == 0) {
|
|
|
|
|
path = &argv[0][5];
|
|
|
|
|
} else if (strncmp(*argv, "name=", 5) == 0) {
|
|
|
|
|
newShell.name = &argv[0][5];
|
|
|
|
|
} else {
|
|
|
|
|
if (strncmp(*argv, "quiet=", 6) == 0) {
|
|
|
|
|
newShell.echoOff = &argv[0][6];
|
|
|
|
|
} else if (strncmp(*argv, "echo=", 5) == 0) {
|
|
|
|
|
newShell.echoOn = &argv[0][5];
|
|
|
|
|
} else if (strncmp(*argv, "filter=", 7) == 0) {
|
|
|
|
|
newShell.noPrint = &argv[0][7];
|
|
|
|
|
newShell.noPLen = strlen(newShell.noPrint);
|
|
|
|
|
} else if (strncmp(*argv, "echoFlag=", 9) == 0) {
|
|
|
|
|
newShell.echo = &argv[0][9];
|
|
|
|
|
} else if (strncmp(*argv, "errFlag=", 8) == 0) {
|
|
|
|
|
newShell.exit = &argv[0][8];
|
|
|
|
|
} else if (strncmp(*argv, "hasErrCtl=", 10) == 0) {
|
|
|
|
|
char c = argv[0][10];
|
|
|
|
|
newShell.hasErrCtl = !((c != 'Y') && (c != 'y') &&
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(c != 'T') && (c != 't'));
|
1998-03-26 22:20:36 +03:00
|
|
|
|
} else if (strncmp(*argv, "check=", 6) == 0) {
|
|
|
|
|
newShell.errCheck = &argv[0][6];
|
|
|
|
|
} else if (strncmp(*argv, "ignore=", 7) == 0) {
|
|
|
|
|
newShell.ignErr = &argv[0][7];
|
2003-12-20 03:18:22 +03:00
|
|
|
|
} else if (strncmp(*argv, "errout=", 7) == 0) {
|
|
|
|
|
newShell.errOut = &argv[0][7];
|
|
|
|
|
} else if (strncmp(*argv, "comment=", 8) == 0) {
|
|
|
|
|
newShell.commentChar = argv[0][8];
|
1998-03-26 22:20:36 +03:00
|
|
|
|
} else {
|
|
|
|
|
Parse_Error(PARSE_FATAL, "Unknown keyword \"%s\"",
|
|
|
|
|
*argv);
|
|
|
|
|
free(words);
|
|
|
|
|
return(FAILURE);
|
|
|
|
|
}
|
|
|
|
|
fullSpec = TRUE;
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (path == NULL) {
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (newShell.name == NULL) {
|
|
|
|
|
Parse_Error(PARSE_FATAL, "Neither path nor name specified");
|
2002-03-18 10:54:33 +03:00
|
|
|
|
free(words);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
return(FAILURE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
2002-03-18 10:54:33 +03:00
|
|
|
|
if ((sh = JobMatchShell(newShell.name)) == NULL) {
|
|
|
|
|
Parse_Error(PARSE_WARNING, "%s: No matching shell",
|
|
|
|
|
newShell.name);
|
|
|
|
|
free(words);
|
|
|
|
|
return(FAILURE);
|
|
|
|
|
}
|
|
|
|
|
commandShell = sh;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
shellName = newShell.name;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* The user provided a path. If s/he gave nothing else (fullSpec is
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* FALSE), try and find a matching shell in the ones we know of.
|
|
|
|
|
* Else we just take the specification at its word and copy it
|
|
|
|
|
* to a new location. In either case, we need to record the
|
|
|
|
|
* path the user gave for the shell.
|
|
|
|
|
*/
|
|
|
|
|
shellPath = path;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
path = strrchr(path, '/');
|
|
|
|
|
if (path == NULL) {
|
2003-07-14 22:19:11 +04:00
|
|
|
|
path = UNCONST(shellPath);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
|
|
|
|
path += 1;
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (newShell.name != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
shellName = newShell.name;
|
|
|
|
|
} else {
|
|
|
|
|
shellName = path;
|
|
|
|
|
}
|
|
|
|
|
if (!fullSpec) {
|
2002-03-18 10:54:33 +03:00
|
|
|
|
if ((sh = JobMatchShell(shellName)) == NULL) {
|
|
|
|
|
Parse_Error(PARSE_WARNING, "%s: No matching shell",
|
|
|
|
|
shellName);
|
|
|
|
|
free(words);
|
|
|
|
|
return(FAILURE);
|
|
|
|
|
}
|
|
|
|
|
commandShell = sh;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
2005-02-16 18:11:52 +03:00
|
|
|
|
commandShell = emalloc(sizeof(Shell));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*commandShell = newShell;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandShell->echoOn && commandShell->echoOff) {
|
|
|
|
|
commandShell->hasEchoCtl = TRUE;
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (!commandShell->hasErrCtl) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (commandShell->errCheck == NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
commandShell->errCheck = "";
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (commandShell->ignErr == NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
commandShell->ignErr = "%s\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Do not free up the words themselves, since they might be in use by the
|
1998-03-26 22:20:36 +03:00
|
|
|
|
* shell specification.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
free(words);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobInterrupt --
|
|
|
|
|
* Handle the receipt of an interrupt.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* runINTERRUPT Non-zero if commands for the .INTERRUPT target
|
|
|
|
|
* should be executed
|
|
|
|
|
* signo signal received
|
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* None
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* All children are killed. Another job will be started if the
|
|
|
|
|
* .INTERRUPT target was given.
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobInterrupt(int runINTERRUPT, int signo)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
2002-03-18 16:28:25 +03:00
|
|
|
|
LstNode ln; /* element in job table */
|
|
|
|
|
Job *job; /* job descriptor in that element */
|
|
|
|
|
GNode *interrupt; /* the node describing the .INTERRUPT target */
|
|
|
|
|
sigset_t mask;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
aborting = ABORT_INTERRUPT;
|
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigLock(&mask);
|
|
|
|
|
|
|
|
|
|
(void) Lst_Open(jobs);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
while ((ln = Lst_Next(jobs)) != NILLNODE) {
|
2002-03-18 11:23:33 +03:00
|
|
|
|
GNode *gn;
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
job = (Job *) Lst_Datum(ln);
|
2002-03-18 11:23:33 +03:00
|
|
|
|
gn = job->node;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
2002-03-18 11:23:33 +03:00
|
|
|
|
if ((gn->type & (OP_JOIN|OP_PHONY)) == 0 && !Targ_Precious(gn)) {
|
|
|
|
|
char *file = (gn->path == NULL ? gn->name : gn->path);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!noExecute && eunlink(file) != -1) {
|
|
|
|
|
Error("*** %s removed", file);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef RMT_WANTS_SIGNALS
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
|
|
|
|
/*
|
|
|
|
|
* If job is remote, let the Rmt module do the killing.
|
|
|
|
|
*/
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (!Rmt_Signal(job, signo)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* If couldn't kill the thing, finish it out now with an
|
|
|
|
|
* error code, since no exit report will come in likely.
|
|
|
|
|
*/
|
1995-11-22 20:39:53 +03:00
|
|
|
|
int status;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
status.w_status = 0;
|
|
|
|
|
status.w_retcode = 1;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
JobFinish(job, &status);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
} else if (job->pid) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
KILL(job->pid, signo);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (job->pid) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
2002-03-18 16:28:25 +03:00
|
|
|
|
"JobInterrupt passing signal %d to child %d.\n",
|
|
|
|
|
signo, job->pid);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
KILL(job->pid, signo);
|
|
|
|
|
}
|
|
|
|
|
#endif /* RMT_WANTS_SIGNALS */
|
|
|
|
|
}
|
2002-03-13 20:46:03 +03:00
|
|
|
|
Lst_Close(jobs);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
(void)Lst_Open(stoppedJobs);
|
|
|
|
|
while ((ln = Lst_Next(stoppedJobs)) != NILLNODE) {
|
2002-03-18 11:23:33 +03:00
|
|
|
|
GNode *gn;
|
|
|
|
|
|
1995-11-03 02:54:35 +03:00
|
|
|
|
job = (Job *) Lst_Datum(ln);
|
2002-03-18 11:23:33 +03:00
|
|
|
|
gn = job->node;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
|
|
|
|
if (job->flags & JOB_RESTART) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "%s%s",
|
|
|
|
|
"JobInterrupt skipping job on stopped queue",
|
|
|
|
|
"-- it was waiting to be restarted.\n");
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2002-03-18 11:23:33 +03:00
|
|
|
|
if ((gn->type & (OP_JOIN|OP_PHONY)) == 0 && !Targ_Precious(gn)) {
|
|
|
|
|
char *file = (gn->path == NULL ? gn->name : gn->path);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (eunlink(file) == 0) {
|
|
|
|
|
Error("*** %s removed", file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Resume the thing so it will take the signal.
|
|
|
|
|
*/
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
1996-11-06 20:58:58 +03:00
|
|
|
|
"JobInterrupt passing CONT to stopped child %d.\n",
|
1995-11-03 02:54:35 +03:00
|
|
|
|
job->pid);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
KILL(job->pid, SIGCONT);
|
|
|
|
|
#ifdef RMT_WANTS_SIGNALS
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
|
|
|
|
/*
|
|
|
|
|
* If job is remote, let the Rmt module do the killing.
|
|
|
|
|
*/
|
|
|
|
|
if (!Rmt_Signal(job, SIGINT)) {
|
|
|
|
|
/*
|
|
|
|
|
* If couldn't kill the thing, finish it out now with an
|
|
|
|
|
* error code, since no exit report will come in likely.
|
|
|
|
|
*/
|
1995-11-22 20:39:53 +03:00
|
|
|
|
int status;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
status.w_status = 0;
|
|
|
|
|
status.w_retcode = 1;
|
|
|
|
|
JobFinish(job, &status);
|
|
|
|
|
}
|
|
|
|
|
} else if (job->pid) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
|
|
|
|
"JobInterrupt passing interrupt to stopped child %d.\n",
|
|
|
|
|
job->pid);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
KILL(job->pid, SIGINT);
|
|
|
|
|
}
|
|
|
|
|
#endif /* RMT_WANTS_SIGNALS */
|
|
|
|
|
}
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Lst_Close(stoppedJobs);
|
2002-03-13 20:46:03 +03:00
|
|
|
|
#endif /* REMOTE */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigUnlock(&mask);
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (runINTERRUPT && !touchFlag) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (interrupt != NILGNODE) {
|
|
|
|
|
ignoreErrors = FALSE;
|
2005-05-08 04:38:47 +04:00
|
|
|
|
JobRun(interrupt);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-30 05:05:20 +03:00
|
|
|
|
Trace_Log(MAKEINTR, 0);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
exit(signo);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*-----------------------------------------------------------------------
|
1998-03-26 22:20:36 +03:00
|
|
|
|
* Job_Finish --
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* Do final processing such as the running of the commands
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* attached to the .END target.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
* Results:
|
|
|
|
|
* Number of errors reported.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
2000-12-03 04:27:03 +03:00
|
|
|
|
* None.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job_Finish(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (postCommands != NILGNODE && !Lst_IsEmpty(postCommands->commands)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (errors) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
Error("Errors reported so .END ignored");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} else {
|
2005-05-08 04:38:47 +04:00
|
|
|
|
JobRun(postCommands);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-30 17:21:22 +03:00
|
|
|
|
Job_TokenFlush();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
return(errors);
|
|
|
|
|
}
|
|
|
|
|
|
1998-03-26 22:20:36 +03:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_End --
|
|
|
|
|
* Cleanup any memory used by the jobs module
|
|
|
|
|
*
|
|
|
|
|
* Results:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* Memory is freed
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job_End(void)
|
1998-03-26 22:20:36 +03:00
|
|
|
|
{
|
1999-09-15 12:43:21 +04:00
|
|
|
|
#ifdef CLEANUP
|
1998-03-26 22:20:36 +03:00
|
|
|
|
if (shellArgv)
|
|
|
|
|
free(shellArgv);
|
1999-09-15 12:43:21 +04:00
|
|
|
|
#endif
|
1998-03-26 22:20:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03: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-06-15 22:24:55 +04:00
|
|
|
|
Job_Wait(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
|
|
|
|
aborting = ABORT_WAIT;
|
|
|
|
|
while (nJobs != 0) {
|
|
|
|
|
Job_CatchOutput();
|
|
|
|
|
#ifndef RMT_WILL_WATCH
|
|
|
|
|
Job_CatchChildren(!usePipes);
|
|
|
|
|
#endif /* RMT_WILL_WATCH */
|
|
|
|
|
}
|
2000-12-30 17:21:22 +03:00
|
|
|
|
Job_TokenFlush();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
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-06-15 22:24:55 +04:00
|
|
|
|
Job_AbortAll(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
2002-03-14 11:07:55 +03:00
|
|
|
|
LstNode ln; /* element in job table */
|
|
|
|
|
Job *job; /* the job descriptor in that element */
|
|
|
|
|
int foo;
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigset_t mask;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
aborting = ABORT_ERROR;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (nJobs) {
|
|
|
|
|
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigLock(&mask);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) Lst_Open(jobs);
|
|
|
|
|
while ((ln = Lst_Next(jobs)) != NILLNODE) {
|
|
|
|
|
job = (Job *) Lst_Datum(ln);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* kill the child process with increasingly drastic signals to make
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* darn sure it's dead.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
|
|
|
|
#ifdef RMT_WANTS_SIGNALS
|
|
|
|
|
if (job->flags & JOB_REMOTE) {
|
|
|
|
|
Rmt_Signal(job, SIGINT);
|
|
|
|
|
Rmt_Signal(job, SIGKILL);
|
|
|
|
|
} else {
|
|
|
|
|
KILL(job->pid, SIGINT);
|
|
|
|
|
KILL(job->pid, SIGKILL);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
KILL(job->pid, SIGINT);
|
|
|
|
|
KILL(job->pid, SIGKILL);
|
|
|
|
|
#endif /* RMT_WANTS_SIGNALS */
|
|
|
|
|
}
|
2002-03-14 11:07:55 +03:00
|
|
|
|
Lst_Close(jobs);
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigUnlock(&mask);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Catch as many children as want to report in at first, then give up
|
|
|
|
|
*/
|
1995-11-22 20:39:53 +03:00
|
|
|
|
while (waitpid((pid_t) -1, &foo, WNOHANG) > 0)
|
1994-03-05 03:34:29 +03:00
|
|
|
|
continue;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef REMOTE
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobFlagForMigration --
|
|
|
|
|
* Handle the eviction of a child. Called from RmtStatusChange.
|
|
|
|
|
* Flags the child as remigratable and then suspends it.
|
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
|
* Input:
|
|
|
|
|
* hostID ID of host we used, for matching children
|
|
|
|
|
*
|
1995-11-03 02:54:35 +03:00
|
|
|
|
* Results:
|
|
|
|
|
* none.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* The job descriptor is flagged for remigration.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobFlagForMigration(int hostID)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
{
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job *job; /* job descriptor for dead child */
|
1995-11-03 02:54:35 +03:00
|
|
|
|
LstNode jnode; /* list element for finding job */
|
|
|
|
|
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout, "JobFlagForMigration(%d) called.\n", hostID);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
2002-03-18 16:32:36 +03:00
|
|
|
|
jnode = Lst_Find(jobs, (ClientData)&hostID, JobCmpRmtID);
|
1995-11-03 02:54:35 +03:00
|
|
|
|
|
|
|
|
|
if (jnode == NILLNODE) {
|
|
|
|
|
jnode = Lst_Find(stoppedJobs, (ClientData)hostID, JobCmpRmtID);
|
|
|
|
|
if (jnode == NILLNODE) {
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
Error("Evicting host(%d) not in table", hostID);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
job = (Job *) Lst_Datum(jnode);
|
|
|
|
|
|
|
|
|
|
if (DEBUG(JOB)) {
|
|
|
|
|
(void) fprintf(stdout,
|
|
|
|
|
"JobFlagForMigration(%d) found job '%s'.\n", hostID,
|
|
|
|
|
job->node->name);
|
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KILL(job->pid, SIGSTOP);
|
|
|
|
|
|
|
|
|
|
job->flags |= JOB_REMIGRATE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* 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-06-15 22:24:55 +04:00
|
|
|
|
JobRestartJobs(void)
|
1995-11-03 02:54:35 +03:00
|
|
|
|
{
|
2002-03-18 16:28:25 +03:00
|
|
|
|
sigset_t mask;
|
|
|
|
|
|
|
|
|
|
JobSigLock(&mask);
|
2000-12-30 05:05:20 +03:00
|
|
|
|
while (!Lst_IsEmpty(stoppedJobs)) {
|
1995-11-03 02:54:35 +03:00
|
|
|
|
if (DEBUG(JOB)) {
|
2000-12-30 05:05:20 +03:00
|
|
|
|
(void) fprintf(stdout, "Restarting a stopped job.\n");
|
1995-11-03 02:54:35 +03:00
|
|
|
|
(void) fflush(stdout);
|
|
|
|
|
}
|
2002-02-10 15:01:59 +03:00
|
|
|
|
if (JobRestart((Job *)Lst_DeQueue(stoppedJobs)) != 0)
|
2002-02-08 20:44:23 +03:00
|
|
|
|
break;
|
1995-11-03 02:54:35 +03:00
|
|
|
|
}
|
2002-03-18 16:28:25 +03:00
|
|
|
|
JobSigUnlock(&mask);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
2000-12-03 05:19:32 +03:00
|
|
|
|
|
|
|
|
|
#ifndef RMT_WILL_WATCH
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
watchfd(Job *job)
|
2000-12-03 05:19:32 +03:00
|
|
|
|
{
|
2000-12-06 00:57:20 +03:00
|
|
|
|
int i;
|
2000-12-04 20:45:17 +03:00
|
|
|
|
if (job->inPollfd != NULL)
|
|
|
|
|
Punt("Watching watched job");
|
|
|
|
|
if (fds == NULL) {
|
|
|
|
|
maxfds = JBSTART;
|
|
|
|
|
fds = emalloc(sizeof(struct pollfd) * maxfds);
|
|
|
|
|
jobfds = emalloc(sizeof(Job **) * maxfds);
|
2000-12-30 05:05:20 +03:00
|
|
|
|
|
|
|
|
|
fds[0].fd = job_pipe[0];
|
|
|
|
|
fds[0].events = POLLIN;
|
|
|
|
|
jobfds[0] = &tokenWaitJob;
|
|
|
|
|
tokenWaitJob.inPollfd = &fds[0];
|
|
|
|
|
nfds++;
|
2002-11-17 01:22:23 +03:00
|
|
|
|
|
|
|
|
|
fds[1].fd = exit_pipe[0];
|
|
|
|
|
fds[1].events = POLLIN;
|
|
|
|
|
jobfds[1] = &childExitJob;
|
|
|
|
|
childExitJob.inPollfd = &fds[1];
|
|
|
|
|
nfds++;
|
2000-12-04 20:45:17 +03:00
|
|
|
|
} else if (nfds == maxfds) {
|
2000-12-06 00:57:20 +03:00
|
|
|
|
maxfds *= JBFACTOR;
|
|
|
|
|
fds = erealloc(fds, sizeof(struct pollfd) * maxfds);
|
2000-12-04 20:45:17 +03:00
|
|
|
|
jobfds = erealloc(jobfds, sizeof(Job **) * maxfds);
|
2000-12-06 00:57:20 +03:00
|
|
|
|
for (i = 0; i < nfds; i++)
|
|
|
|
|
jobfds[i]->inPollfd = &fds[i];
|
2000-12-04 20:45:17 +03:00
|
|
|
|
}
|
2000-12-03 05:19:32 +03:00
|
|
|
|
|
2000-12-04 20:45:17 +03:00
|
|
|
|
fds[nfds].fd = job->inPipe;
|
2000-12-06 00:57:20 +03:00
|
|
|
|
fds[nfds].events = POLLIN;
|
2000-12-04 20:45:17 +03:00
|
|
|
|
jobfds[nfds] = job;
|
2000-12-06 00:57:20 +03:00
|
|
|
|
job->inPollfd = &fds[nfds];
|
|
|
|
|
nfds++;
|
2000-12-03 05:19:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
clearfd(Job *job)
|
2000-12-03 05:19:32 +03:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2000-12-04 20:45:17 +03:00
|
|
|
|
if (job->inPollfd == NULL)
|
|
|
|
|
Punt("Unwatching unwatched job");
|
|
|
|
|
i = job->inPollfd - fds;
|
|
|
|
|
nfds--;
|
2000-12-05 18:28:55 +03:00
|
|
|
|
/*
|
|
|
|
|
* Move last job in table into hole made by dead job.
|
|
|
|
|
*/
|
2000-12-04 20:45:17 +03:00
|
|
|
|
if (nfds != i) {
|
2000-12-05 18:28:55 +03:00
|
|
|
|
fds[i] = fds[nfds];
|
|
|
|
|
jobfds[i] = jobfds[nfds];
|
|
|
|
|
jobfds[i]->inPollfd = &fds[i];
|
2000-12-04 20:45:17 +03:00
|
|
|
|
}
|
|
|
|
|
job->inPollfd = NULL;
|
2000-12-03 05:19:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
|
readyfd(Job *job)
|
2000-12-03 05:19:32 +03:00
|
|
|
|
{
|
2000-12-04 20:45:17 +03:00
|
|
|
|
if (job->inPollfd == NULL)
|
|
|
|
|
Punt("Polling unwatched job");
|
|
|
|
|
return (job->inPollfd->revents & POLLIN) != 0;
|
2000-12-03 05:19:32 +03:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-12-30 05:05:20 +03:00
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* JobTokenAdd --
|
|
|
|
|
* Put a token into the job pipe so that some make process can start
|
|
|
|
|
* another job.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* Allows more build jobs to be spawned somewhere.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
JobTokenAdd(void)
|
2000-12-30 05:05:20 +03:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (DEBUG(JOB))
|
|
|
|
|
printf("deposit token\n");
|
|
|
|
|
write(job_pipe[1], "+", 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_ServerStartTokenAdd --
|
|
|
|
|
* Prep the job token pipe in the root make process.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
|
void
|
|
|
|
|
Job_ServerStart(int maxproc)
|
2000-12-30 05:05:20 +03:00
|
|
|
|
{
|
|
|
|
|
int i, flags;
|
|
|
|
|
char jobarg[64];
|
|
|
|
|
|
|
|
|
|
if (pipe(job_pipe) < 0)
|
2005-02-16 18:11:52 +03:00
|
|
|
|
Fatal("error in pipe: %s", strerror(errno));
|
2000-12-30 05:05:20 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We mark the input side of the pipe non-blocking; we poll(2) the
|
|
|
|
|
* pipe when we're waiting for a job token, but we might lose the
|
|
|
|
|
* race for the token when a new one becomes available, so the read
|
|
|
|
|
* from the pipe should not block.
|
|
|
|
|
*/
|
|
|
|
|
flags = fcntl(job_pipe[0], F_GETFL, 0);
|
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
|
fcntl(job_pipe[0], F_SETFL, flags);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Mark job pipes as close-on-exec.
|
|
|
|
|
* Note that we will clear this when executing submakes.
|
|
|
|
|
*/
|
|
|
|
|
fcntl(job_pipe[0], F_SETFD, 1);
|
|
|
|
|
fcntl(job_pipe[1], F_SETFD, 1);
|
|
|
|
|
|
|
|
|
|
snprintf(jobarg, sizeof(jobarg), "%d,%d", job_pipe[0], job_pipe[1]);
|
|
|
|
|
|
|
|
|
|
Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
|
|
|
|
|
Var_Append(MAKEFLAGS, jobarg, VAR_GLOBAL);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Preload job_pipe with one token per job, save the one
|
|
|
|
|
* "extra" token for the primary job.
|
|
|
|
|
*
|
|
|
|
|
* XXX should clip maxJobs against PIPE_BUF -- if maxJobs is
|
|
|
|
|
* larger than the write buffer size of the pipe, we will
|
|
|
|
|
* deadlock here.
|
|
|
|
|
*/
|
|
|
|
|
for (i=1; i < maxproc; i++)
|
|
|
|
|
JobTokenAdd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* this tracks the number of tokens currently "out" to build jobs.
|
|
|
|
|
*/
|
2000-12-30 19:38:22 +03:00
|
|
|
|
int jobTokensRunning = 0;
|
|
|
|
|
int jobTokensFree = 0;
|
2000-12-30 05:05:20 +03:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_TokenReturn --
|
|
|
|
|
* Return a withdrawn token to the pool.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job_TokenReturn(void)
|
2000-12-30 05:05:20 +03:00
|
|
|
|
{
|
2000-12-30 19:38:22 +03:00
|
|
|
|
jobTokensRunning--;
|
|
|
|
|
if (jobTokensRunning < 0)
|
2000-12-30 05:05:20 +03:00
|
|
|
|
Punt("token botch");
|
2000-12-30 19:38:22 +03:00
|
|
|
|
if (jobTokensRunning)
|
|
|
|
|
jobTokensFree++;
|
2000-12-30 05:05:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Job_TokenWithdraw --
|
|
|
|
|
* Attempt to withdraw a token from the pool.
|
|
|
|
|
*
|
|
|
|
|
* Results:
|
|
|
|
|
* Returns TRUE if a token was withdrawn, and FALSE if the pool
|
|
|
|
|
* is currently empty.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* If pool is empty, set wantToken so that we wake up
|
|
|
|
|
* when a token is released.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Boolean
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job_TokenWithdraw(void)
|
2000-12-30 05:05:20 +03:00
|
|
|
|
{
|
|
|
|
|
char tok;
|
|
|
|
|
int count;
|
|
|
|
|
|
2002-03-04 03:34:35 +03:00
|
|
|
|
wantToken = FALSE;
|
|
|
|
|
|
2000-12-30 05:05:20 +03:00
|
|
|
|
if (aborting)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2000-12-30 19:38:22 +03:00
|
|
|
|
if (jobTokensRunning == 0) {
|
2000-12-30 05:05:20 +03:00
|
|
|
|
if (DEBUG(JOB))
|
|
|
|
|
printf("first one's free\n");
|
2000-12-30 19:38:22 +03:00
|
|
|
|
jobTokensRunning++;
|
2000-12-30 05:05:20 +03:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2000-12-30 19:38:22 +03:00
|
|
|
|
if (jobTokensFree > 0) {
|
|
|
|
|
jobTokensFree--;
|
|
|
|
|
jobTokensRunning++;
|
2000-12-30 05:51:21 +03:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2000-12-30 05:05:20 +03:00
|
|
|
|
count = read(job_pipe[0], &tok, 1);
|
|
|
|
|
if (count == 0)
|
|
|
|
|
Fatal("eof on job pipe!");
|
|
|
|
|
else if (count < 0) {
|
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
|
Fatal("job pipe read: %s", strerror(errno));
|
|
|
|
|
}
|
|
|
|
|
if (DEBUG(JOB))
|
|
|
|
|
printf("blocked for token\n");
|
|
|
|
|
wantToken = TRUE;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2000-12-30 19:38:22 +03:00
|
|
|
|
jobTokensRunning++;
|
2000-12-30 05:05:20 +03:00
|
|
|
|
if (DEBUG(JOB))
|
|
|
|
|
printf("withdrew token\n");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-30 05:51:21 +03:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
2000-12-30 17:21:22 +03:00
|
|
|
|
* Job_TokenFlush --
|
2000-12-30 05:51:21 +03:00
|
|
|
|
* Return free tokens to the pool.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Job_TokenFlush(void)
|
2000-12-30 05:51:21 +03:00
|
|
|
|
{
|
|
|
|
|
if (compatMake) return;
|
|
|
|
|
|
2000-12-30 19:38:22 +03:00
|
|
|
|
while (jobTokensFree > 0) {
|
2000-12-30 05:51:21 +03:00
|
|
|
|
JobTokenAdd();
|
2000-12-30 19:38:22 +03:00
|
|
|
|
jobTokensFree--;
|
2000-12-30 05:51:21 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-17 01:22:23 +03:00
|
|
|
|
#ifdef USE_SELECT
|
|
|
|
|
int
|
|
|
|
|
emul_poll(struct pollfd *fd, int nfd, int timeout)
|
|
|
|
|
{
|
|
|
|
|
fd_set rfds, wfds;
|
|
|
|
|
int i, maxfd, nselect, npoll;
|
|
|
|
|
struct timeval tv, *tvp;
|
|
|
|
|
long usecs;
|
|
|
|
|
|
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
|
FD_ZERO(&wfds);
|
|
|
|
|
|
|
|
|
|
maxfd = -1;
|
|
|
|
|
for (i = 0; i < nfd; i++) {
|
|
|
|
|
fd[i].revents = 0;
|
|
|
|
|
|
|
|
|
|
if (fd[i].events & POLLIN)
|
|
|
|
|
FD_SET(fd[i].fd, &rfds);
|
|
|
|
|
|
|
|
|
|
if (fd[i].events & POLLOUT)
|
|
|
|
|
FD_SET(fd[i].fd, &wfds);
|
|
|
|
|
|
|
|
|
|
if (fd[i].fd > maxfd)
|
|
|
|
|
maxfd = fd[i].fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maxfd >= FD_SETSIZE) {
|
|
|
|
|
Punt("Ran out of fd_set slots; "
|
|
|
|
|
"recompile with a larger FD_SETSIZE.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timeout < 0) {
|
|
|
|
|
tvp = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
usecs = timeout * 1000;
|
|
|
|
|
tv.tv_sec = usecs / 1000000;
|
|
|
|
|
tv.tv_usec = usecs % 1000000;
|
|
|
|
|
tvp = &tv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nselect = select(maxfd + 1, &rfds, &wfds, 0, tvp);
|
|
|
|
|
|
|
|
|
|
if (nselect <= 0)
|
|
|
|
|
return nselect;
|
|
|
|
|
|
|
|
|
|
npoll = 0;
|
|
|
|
|
for (i = 0; i < nfd; i++) {
|
|
|
|
|
if (FD_ISSET(fd[i].fd, &rfds))
|
|
|
|
|
fd[i].revents |= POLLIN;
|
|
|
|
|
|
|
|
|
|
if (FD_ISSET(fd[i].fd, &wfds))
|
|
|
|
|
fd[i].revents |= POLLOUT;
|
|
|
|
|
|
|
|
|
|
if (fd[i].revents)
|
|
|
|
|
npoll++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return npoll;
|
|
|
|
|
}
|
|
|
|
|
#endif /* USE_SELECT */
|