4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1988, 1989 by Adam de Boor
7 * Copyright (c) 1989 by Berkeley Softworks
10 * This code is derived from software contributed to Berkeley by
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * from: @(#)job.h 8.1 (Berkeley) 6/6/93
42 * $FreeBSD: src/usr.bin/make/job.h,v 1.11 2000/01/17 06:43:41 kris Exp $
43 * $DragonFly: src/usr.bin/make/job.h,v 1.18 2005/01/06 10:53:00 okumoto Exp $
48 * Definitions pertaining to the running of jobs in parallel mode.
49 * Exported from job.c for the use of remote-execution modules.
59 #define TMPPAT "/tmp/makeXXXXXXXXXX"
63 * The SEL_ constants determine the maximum amount of time spent in select
64 * before coming out to see if a child has finished. SEL_SEC is the number of
65 * seconds and SEL_USEC is the number of micro-seconds
69 #endif /* !USE_KQUEUE */
72 * Job Table definitions.
74 * Each job has several things associated with it:
75 * 1) The process id of the child shell
76 * 2) The graph node describing the target being made by this job
77 * 3) A LstNode for the first command to be saved after the job
78 * completes. This is NULL if there was no "..." in the job's
80 * 4) An FILE* for writing out the commands. This is only
81 * used before the job is actually started.
82 * 5) A union of things used for handling the shell's output. Different
83 * parts of the union are used based on the value of the usePipes
84 * flag. If it is true, the output is being caught via a pipe and
85 * the descriptors of our pipe, an array in which output is line
86 * buffered and the current position in that buffer are all
87 * maintained for each job. If, on the other hand, usePipes is false,
88 * the output is routed to a temporary file and all that is kept
89 * is the name of the file and the descriptor open to the file.
90 * 6) A word of flags which determine how the module handles errors,
91 * echoing, etc. for the job
93 * The job "table" is kept as a linked Lst in 'jobs', with the number of
94 * active jobs maintained in the 'nJobs' variable. At no time will this
95 * exceed the value of 'maxJobs', initialized by the Job_Init function.
97 * When a job is finished, the Make_Update function is called on each of the
98 * parents of the node which was just remade. This takes care of the upward
99 * traversal of the dependency graph.
101 #define JOB_BUFSIZE 1024
103 int pid; /* The child's process ID */
104 char tfile[sizeof(TMPPAT)];
105 /* Temporary file to use for job */
106 struct GNode *node; /* The target the child is making */
107 struct LstNode *tailCmds; /* The node of the first command to be
108 * saved when the job has been run */
109 FILE *cmdFILE; /* When creating the shell script, this is
110 * where the commands go */
111 short flags; /* Flags to control treatment of job */
112 #define JOB_IGNERR 0x001 /* Ignore non-zero exits */
113 #define JOB_SILENT 0x002 /* no output */
114 #define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
115 * if we can't export it and maxLocal is 0 */
116 #define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing
118 #define JOB_FIRST 0x020 /* Job is first job for the node */
119 #define JOB_RESTART 0x080 /* Job needs to be completely restarted */
120 #define JOB_RESUME 0x100 /* Job needs to be resumed b/c it stopped,
122 #define JOB_CONTINUING 0x200 /* We are in the process of resuming this job.
123 * Used to avoid infinite recursion between
124 * JobFinish and JobRestart */
127 int op_inPipe; /* Input side of pipe associated
128 * with job's output channel */
129 int op_outPipe; /* Output side of pipe associated with
130 * job's output channel */
131 char op_outBuf[JOB_BUFSIZE + 1];
132 /* Buffer for storing the output of the
133 * job, line by line */
134 int op_curPos; /* Current position in op_outBuf */
135 } o_pipe; /* data used when catching the output via
138 char of_outFile[sizeof(TMPPAT)];
139 /* Name of file to which shell output
141 int of_outFd; /* Stream open to the output
142 * file. Used to funnel all
143 * from a single job to one file
144 * while still allowing
145 * multiple shell invocations */
146 } o_file; /* Data used when catching the output in
147 * a temporary file */
148 } output; /* Data for tracking a shell's output */
151 #define outPipe output.o_pipe.op_outPipe
152 #define inPipe output.o_pipe.op_inPipe
153 #define outBuf output.o_pipe.op_outBuf
154 #define curPos output.o_pipe.op_curPos
155 #define outFile output.o_file.of_outFile
156 #define outFd output.o_file.of_outFd
159 * Shell Specifications:
160 * Each shell type has associated with it the following information:
161 * 1) The string which must match the last character of the shell name
162 * for the shell to be considered of this type. The longest match
164 * 2) A command to issue to turn off echoing of command lines
165 * 3) A command to issue to turn echoing back on again
166 * 4) What the shell prints, and its length, when given the echo-off
167 * command. This line will not be printed when received from the shell
168 * 5) A boolean to tell if the shell has the ability to control
169 * error checking for individual commands.
170 * 6) The string to turn this checking on.
171 * 7) The string to turn it off.
172 * 8) The command-flag to give to cause the shell to start echoing
173 * commands right away.
174 * 9) The command-flag to cause the shell to Lib_Exit when an error is
175 * detected in one of the commands.
177 * Some special stuff goes on if a shell doesn't have error control. In such
178 * a case, errCheck becomes a printf template for echoing the command,
179 * should echoing be on and ignErr becomes another printf template for
180 * executing the command while ignoring the return status. If either of these
181 * strings is empty when hasErrCtl is FALSE, the command will be executed
182 * anyway as is and if it causes an error, so be it.
184 #define DEF_SHELL_STRUCT(TAG, CONST) \
186 CONST char *name; /* the name of the shell. For Bourne and C \
187 * shells, this is used only to find the \
188 * shell description when used as the single \
189 * source of a .SHELL target. For user-defined \
190 * shells, this is the full path of the shell. \
192 Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */ \
193 CONST char *echoOff; /* command to turn off echo */ \
194 CONST char *echoOn; /* command to turn it back on again */ \
195 CONST char *noPrint; /* command to skip when printing output from \
196 * shell. This is usually the command which \
197 * was executed to turn off echoing */ \
198 int noPLen; /* length of noPrint command */ \
199 Boolean hasErrCtl; /* set if can control error checking for \
200 * individual commands */ \
201 CONST char *errCheck; /* string to turn error checking on */ \
202 CONST char *ignErr; /* string to turn off error checking */ \
204 * command-line flags \
206 CONST char *echo; /* echo commands */ \
207 CONST char *exit; /* exit on error */ \
210 typedef DEF_SHELL_STRUCT(Shell,) Shell;
212 extern char *shellPath;
213 extern char *shellName;
214 extern int maxJobs; /* Number of jobs that may run */
217 void Shell_Init(void);
218 void Job_Touch(struct GNode *, Boolean);
219 Boolean Job_CheckCommands(struct GNode *, void (*abortProc)(const char *, ...));
220 void Job_CatchChildren(Boolean);
221 void Job_CatchOutput(int flag);
222 void Job_Make(struct GNode *);
224 Boolean Job_Full(void);
225 Boolean Job_Empty(void);
226 ReturnStatus Job_ParseShell(char *);
227 int Job_Finish(void);
229 void Job_AbortAll(void);
231 #endif /* job_h_4678dfd1 */