2008-12-13 18:19:29 +03:00
|
|
|
|
/* $NetBSD: job.h,v 1.38 2008/12/13 15:19:29 dsl 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.
|
|
|
|
|
*
|
|
|
|
|
* from: @(#)job.h 8.1 (Berkeley) 6/6/93
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
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.
|
|
|
|
|
*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* from: @(#)job.h 8.1 (Berkeley) 6/6/93
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
* job.h --
|
|
|
|
|
* Definitions pertaining to the running of jobs in parallel mode.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef _JOB_H_
|
|
|
|
|
#define _JOB_H_
|
|
|
|
|
|
2000-12-03 04:18:15 +03:00
|
|
|
|
#define TMPPAT "/tmp/makeXXXXXX"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
2000-12-05 18:20:10 +03:00
|
|
|
|
#ifdef USE_SELECT
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
2002-11-17 01:22:23 +03:00
|
|
|
|
* Emulate poll() in terms of select(). This is not a complete
|
|
|
|
|
* emulation but it is sufficient for make's purposes.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
2002-11-17 01:22:23 +03:00
|
|
|
|
|
|
|
|
|
#define poll emul_poll
|
|
|
|
|
#define pollfd emul_pollfd
|
|
|
|
|
|
|
|
|
|
struct emul_pollfd {
|
|
|
|
|
int fd;
|
|
|
|
|
short events;
|
|
|
|
|
short revents;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define POLLIN 0x0001
|
|
|
|
|
#define POLLOUT 0x0004
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
emul_poll(struct pollfd *fd, int nfd, int timeout);
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-12-05 18:20:10 +03:00
|
|
|
|
/*
|
|
|
|
|
* The POLL_MSEC constant determines the maximum number of milliseconds spent
|
|
|
|
|
* in poll before coming out to see if a child has finished.
|
|
|
|
|
*/
|
|
|
|
|
#define POLL_MSEC 5000
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* Job Table definitions.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
* Each job has several things associated with it:
|
|
|
|
|
* 1) The process id of the child shell
|
|
|
|
|
* 2) The graph node describing the target being made by this job
|
|
|
|
|
* 3) A LstNode for the first command to be saved after the job
|
2008-12-13 18:19:29 +03:00
|
|
|
|
* completes. This is NULL if there was no "..." in the job's
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* commands.
|
|
|
|
|
* 4) An FILE* for writing out the commands. This is only
|
|
|
|
|
* used before the job is actually started.
|
2006-10-09 18:36:41 +04:00
|
|
|
|
* 5) The output is being caught via a pipe and
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* the descriptors of our pipe, an array in which output is line
|
|
|
|
|
* buffered and the current position in that buffer are all
|
2006-10-09 18:36:41 +04:00
|
|
|
|
* maintained for each job.
|
2006-03-11 20:18:00 +03:00
|
|
|
|
* 6) A word of flags which determine how the module handles errors,
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* echoing, etc. for the job
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*
|
|
|
|
|
* When a job is finished, the Make_Update function is called on each of the
|
|
|
|
|
* parents of the node which was just remade. This takes care of the upward
|
|
|
|
|
* traversal of the dependency graph.
|
|
|
|
|
*/
|
2000-12-04 23:13:29 +03:00
|
|
|
|
struct pollfd;
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#define JOB_BUFSIZE 1024
|
|
|
|
|
typedef struct Job {
|
2008-02-16 00:29:50 +03:00
|
|
|
|
int pid; /* The child's process ID */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
GNode *node; /* The target the child is making */
|
|
|
|
|
LstNode tailCmds; /* The node of the first command to be
|
|
|
|
|
* saved when the job has been run */
|
|
|
|
|
FILE *cmdFILE; /* When creating the shell script, this is
|
|
|
|
|
* where the commands go */
|
2006-09-24 00:51:28 +04:00
|
|
|
|
int exit_status; /* from wait4() in signal handler */
|
|
|
|
|
char job_state; /* status of the job entry */
|
2006-09-22 23:07:09 +04:00
|
|
|
|
#define JOB_ST_FREE 0 /* Job is available */
|
|
|
|
|
#define JOB_ST_SETUP 1 /* Job is allocated but otherwise invalid */
|
2006-09-24 00:51:28 +04:00
|
|
|
|
#define JOB_ST_RUNNING 3 /* Job is running, pid valid */
|
2006-09-22 23:07:09 +04:00
|
|
|
|
#define JOB_ST_FINISHED 4 /* Job is done (ie after SIGCHILD) */
|
2006-09-24 00:51:28 +04:00
|
|
|
|
char job_suspended;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
short flags; /* Flags to control treatment of job */
|
|
|
|
|
#define JOB_IGNERR 0x001 /* Ignore non-zero exits */
|
|
|
|
|
#define JOB_SILENT 0x002 /* no output */
|
|
|
|
|
#define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
|
|
|
|
|
* if we can't export it and maxLocal is 0 */
|
|
|
|
|
#define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing
|
|
|
|
|
* commands */
|
2001-06-02 00:33:37 +04:00
|
|
|
|
#define JOB_TRACED 0x400 /* we've sent 'set -x' */
|
|
|
|
|
|
2008-02-16 00:29:50 +03:00
|
|
|
|
int jobPipe[2]; /* Pipe for readind output from job */
|
2006-10-09 18:36:41 +04:00
|
|
|
|
struct pollfd *inPollfd; /* pollfd associated with inPipe */
|
|
|
|
|
char outBuf[JOB_BUFSIZE + 1];
|
|
|
|
|
/* Buffer for storing the output of the
|
|
|
|
|
* job, line by line */
|
2008-02-16 00:29:50 +03:00
|
|
|
|
int curPos; /* Current position in op_outBuf */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} Job;
|
|
|
|
|
|
2006-10-11 11:01:44 +04:00
|
|
|
|
#define inPipe jobPipe[0]
|
|
|
|
|
#define outPipe jobPipe[1]
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
* Shell Specifications:
|
|
|
|
|
* Each shell type has associated with it the following information:
|
|
|
|
|
* 1) The string which must match the last character of the shell name
|
|
|
|
|
* for the shell to be considered of this type. The longest match
|
|
|
|
|
* wins.
|
|
|
|
|
* 2) A command to issue to turn off echoing of command lines
|
|
|
|
|
* 3) A command to issue to turn echoing back on again
|
|
|
|
|
* 4) What the shell prints, and its length, when given the echo-off
|
|
|
|
|
* command. This line will not be printed when received from the shell
|
|
|
|
|
* 5) A boolean to tell if the shell has the ability to control
|
|
|
|
|
* error checking for individual commands.
|
|
|
|
|
* 6) The string to turn this checking on.
|
|
|
|
|
* 7) The string to turn it off.
|
|
|
|
|
* 8) The command-flag to give to cause the shell to start echoing
|
|
|
|
|
* commands right away.
|
|
|
|
|
* 9) The command-flag to cause the shell to Lib_Exit when an error is
|
|
|
|
|
* detected in one of the commands.
|
|
|
|
|
*
|
|
|
|
|
* Some special stuff goes on if a shell doesn't have error control. In such
|
|
|
|
|
* a case, errCheck becomes a printf template for echoing the command,
|
|
|
|
|
* should echoing be on and ignErr becomes another printf template for
|
2003-12-20 03:18:22 +03:00
|
|
|
|
* executing the command while ignoring the return status. Finally errOut
|
|
|
|
|
* is a printf template for running the command and causing the shell to
|
|
|
|
|
* exit on error. If any of these strings are empty when hasErrCtl is FALSE,
|
|
|
|
|
* the command will be executed anyway as is and if it causes an error, so be
|
|
|
|
|
* it. Any templates setup to echo the command will escape any '$ ` \ "'i
|
|
|
|
|
* characters in the command string to avoid common problems with
|
|
|
|
|
* echo "%s\n" as a template.
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
|
|
|
|
typedef struct Shell {
|
2003-07-14 22:19:11 +04:00
|
|
|
|
const char *name; /* the name of the shell. For Bourne and C
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* shells, this is used only to find the
|
|
|
|
|
* shell description when used as the single
|
|
|
|
|
* source of a .SHELL target. For user-defined
|
|
|
|
|
* shells, this is the full path of the shell.
|
|
|
|
|
*/
|
|
|
|
|
Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */
|
2003-07-14 22:19:11 +04:00
|
|
|
|
const char *echoOff; /* command to turn off echo */
|
|
|
|
|
const char *echoOn; /* command to turn it back on again */
|
|
|
|
|
const char *noPrint; /* command to skip when printing output from
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* shell. This is usually the command which
|
|
|
|
|
* was executed to turn off echoing */
|
|
|
|
|
int noPLen; /* length of noPrint command */
|
|
|
|
|
Boolean hasErrCtl; /* set if can control error checking for
|
|
|
|
|
* individual commands */
|
2003-07-14 22:19:11 +04:00
|
|
|
|
const char *errCheck; /* string to turn error checking on */
|
|
|
|
|
const char *ignErr; /* string to turn off error checking */
|
2003-12-20 03:18:22 +03:00
|
|
|
|
const char *errOut; /* string to use for testing exit code */
|
2006-06-30 02:01:17 +04:00
|
|
|
|
const char *newline; /* string literal that results in a newline
|
|
|
|
|
* character when it appears outside of any
|
|
|
|
|
* 'quote' or "quote" characters */
|
2003-12-20 03:18:22 +03:00
|
|
|
|
char commentChar; /* character used by shell for comment lines */
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
|
* command-line flags
|
1993-03-21 12:45:37 +03:00
|
|
|
|
*/
|
2003-07-14 22:19:11 +04:00
|
|
|
|
const char *echo; /* echo commands */
|
|
|
|
|
const char *exit; /* exit on error */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
} Shell;
|
|
|
|
|
|
2003-08-01 04:39:52 +04:00
|
|
|
|
extern const char *shellPath;
|
|
|
|
|
extern const char *shellName;
|
|
|
|
|
|
2000-12-30 19:38:22 +03:00
|
|
|
|
extern int jobTokensRunning; /* tokens currently "out" */
|
2006-04-01 01:05:34 +04:00
|
|
|
|
extern int maxJobs; /* Max jobs we can run */
|
2000-12-30 05:05:20 +03:00
|
|
|
|
|
2003-08-01 04:39:52 +04:00
|
|
|
|
void Shell_Init(void);
|
2006-06-30 02:01:17 +04:00
|
|
|
|
const char *Shell_GetNewline(void);
|
2002-06-15 22:24:55 +04:00
|
|
|
|
void Job_Touch(GNode *, Boolean);
|
2003-07-14 22:19:11 +04:00
|
|
|
|
Boolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...));
|
2006-09-24 00:51:28 +04:00
|
|
|
|
#define CATCH_BLOCK 1
|
2006-10-09 18:36:41 +04:00
|
|
|
|
void Job_CatchChildren(void);
|
2002-06-15 22:24:55 +04:00
|
|
|
|
void Job_CatchOutput(void);
|
|
|
|
|
void Job_Make(GNode *);
|
2006-04-01 01:05:34 +04:00
|
|
|
|
void Job_Init(void);
|
2002-06-15 22:24:55 +04:00
|
|
|
|
Boolean Job_Full(void);
|
|
|
|
|
Boolean Job_Empty(void);
|
|
|
|
|
ReturnStatus Job_ParseShell(char *);
|
|
|
|
|
int Job_Finish(void);
|
|
|
|
|
void Job_End(void);
|
|
|
|
|
void Job_Wait(void);
|
|
|
|
|
void Job_AbortAll(void);
|
|
|
|
|
void JobFlagForMigration(int);
|
|
|
|
|
void Job_TokenReturn(void);
|
|
|
|
|
Boolean Job_TokenWithdraw(void);
|
2006-10-11 11:01:44 +04:00
|
|
|
|
void Job_ServerStart(int, int, int);
|
2007-10-02 02:14:09 +04:00
|
|
|
|
void Job_SetPrefix(void);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#endif /* _JOB_H_ */
|