Create SFFS library out of HGFS
[minix.git] / commands / make / job.h
blob326aa3e5c7bc9598c3145aa8253976be2954639d
1 /* $NetBSD: job.h,v 1.39 2009/04/11 09:41:18 apb Exp $ */
3 /*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * from: @(#)job.h 8.1 (Berkeley) 6/6/93
38 * Copyright (c) 1988, 1989 by Adam de Boor
39 * Copyright (c) 1989 by Berkeley Softworks
40 * All rights reserved.
42 * This code is derived from software contributed to Berkeley by
43 * Adam de Boor.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Berkeley and its contributors.
57 * 4. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * SUCH DAMAGE.
73 * from: @(#)job.h 8.1 (Berkeley) 6/6/93
76 /*-
77 * job.h --
78 * Definitions pertaining to the running of jobs in parallel mode.
80 #ifndef _JOB_H_
81 #define _JOB_H_
83 #define TMPPAT "makeXXXXXX" /* relative to tmpdir */
85 #ifdef USE_SELECT
87 * Emulate poll() in terms of select(). This is not a complete
88 * emulation but it is sufficient for make's purposes.
91 #define poll emul_poll
92 #define pollfd emul_pollfd
94 struct emul_pollfd {
95 int fd;
96 short events;
97 short revents;
100 #define POLLIN 0x0001
101 #define POLLOUT 0x0004
104 emul_poll(struct pollfd *fd, int nfd, int timeout);
105 #endif
108 * The POLL_MSEC constant determines the maximum number of milliseconds spent
109 * in poll before coming out to see if a child has finished.
111 #define POLL_MSEC 5000
115 * Job Table definitions.
117 * Each job has several things associated with it:
118 * 1) The process id of the child shell
119 * 2) The graph node describing the target being made by this job
120 * 3) A LstNode for the first command to be saved after the job
121 * completes. This is NULL if there was no "..." in the job's
122 * commands.
123 * 4) An FILE* for writing out the commands. This is only
124 * used before the job is actually started.
125 * 5) The output is being caught via a pipe and
126 * the descriptors of our pipe, an array in which output is line
127 * buffered and the current position in that buffer are all
128 * maintained for each job.
129 * 6) A word of flags which determine how the module handles errors,
130 * echoing, etc. for the job
132 * When a job is finished, the Make_Update function is called on each of the
133 * parents of the node which was just remade. This takes care of the upward
134 * traversal of the dependency graph.
136 struct pollfd;
138 #define JOB_BUFSIZE 1024
139 typedef struct Job {
140 int pid; /* The child's process ID */
141 GNode *node; /* The target the child is making */
142 LstNode tailCmds; /* The node of the first command to be
143 * saved when the job has been run */
144 FILE *cmdFILE; /* When creating the shell script, this is
145 * where the commands go */
146 int exit_status; /* from wait4() in signal handler */
147 char job_state; /* status of the job entry */
148 #define JOB_ST_FREE 0 /* Job is available */
149 #define JOB_ST_SETUP 1 /* Job is allocated but otherwise invalid */
150 #define JOB_ST_RUNNING 3 /* Job is running, pid valid */
151 #define JOB_ST_FINISHED 4 /* Job is done (ie after SIGCHILD) */
152 char job_suspended;
153 short flags; /* Flags to control treatment of job */
154 #define JOB_IGNERR 0x001 /* Ignore non-zero exits */
155 #define JOB_SILENT 0x002 /* no output */
156 #define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
157 * if we can't export it and maxLocal is 0 */
158 #define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing
159 * commands */
160 #define JOB_TRACED 0x400 /* we've sent 'set -x' */
162 int jobPipe[2]; /* Pipe for readind output from job */
163 struct pollfd *inPollfd; /* pollfd associated with inPipe */
164 char outBuf[JOB_BUFSIZE + 1];
165 /* Buffer for storing the output of the
166 * job, line by line */
167 int curPos; /* Current position in op_outBuf */
168 } Job;
170 #define inPipe jobPipe[0]
171 #define outPipe jobPipe[1]
175 * Shell Specifications:
176 * Each shell type has associated with it the following information:
177 * 1) The string which must match the last character of the shell name
178 * for the shell to be considered of this type. The longest match
179 * wins.
180 * 2) A command to issue to turn off echoing of command lines
181 * 3) A command to issue to turn echoing back on again
182 * 4) What the shell prints, and its length, when given the echo-off
183 * command. This line will not be printed when received from the shell
184 * 5) A boolean to tell if the shell has the ability to control
185 * error checking for individual commands.
186 * 6) The string to turn this checking on.
187 * 7) The string to turn it off.
188 * 8) The command-flag to give to cause the shell to start echoing
189 * commands right away.
190 * 9) The command-flag to cause the shell to Lib_Exit when an error is
191 * detected in one of the commands.
193 * Some special stuff goes on if a shell doesn't have error control. In such
194 * a case, errCheck becomes a printf template for echoing the command,
195 * should echoing be on and ignErr becomes another printf template for
196 * executing the command while ignoring the return status. Finally errOut
197 * is a printf template for running the command and causing the shell to
198 * exit on error. If any of these strings are empty when hasErrCtl is FALSE,
199 * the command will be executed anyway as is and if it causes an error, so be
200 * it. Any templates setup to echo the command will escape any '$ ` \ "'i
201 * characters in the command string to avoid common problems with
202 * echo "%s\n" as a template.
204 typedef struct Shell {
205 const char *name; /* the name of the shell. For Bourne and C
206 * shells, this is used only to find the
207 * shell description when used as the single
208 * source of a .SHELL target. For user-defined
209 * shells, this is the full path of the shell.
211 Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */
212 const char *echoOff; /* command to turn off echo */
213 const char *echoOn; /* command to turn it back on again */
214 const char *noPrint; /* command to skip when printing output from
215 * shell. This is usually the command which
216 * was executed to turn off echoing */
217 int noPLen; /* length of noPrint command */
218 Boolean hasErrCtl; /* set if can control error checking for
219 * individual commands */
220 const char *errCheck; /* string to turn error checking on */
221 const char *ignErr; /* string to turn off error checking */
222 const char *errOut; /* string to use for testing exit code */
223 const char *newline; /* string literal that results in a newline
224 * character when it appears outside of any
225 * 'quote' or "quote" characters */
226 char commentChar; /* character used by shell for comment lines */
229 * command-line flags
231 const char *echo; /* echo commands */
232 const char *exit; /* exit on error */
233 } Shell;
235 extern const char *shellPath;
236 extern const char *shellName;
238 extern int jobTokensRunning; /* tokens currently "out" */
239 extern int maxJobs; /* Max jobs we can run */
241 void Shell_Init(void);
242 const char *Shell_GetNewline(void);
243 void Job_Touch(GNode *, Boolean);
244 Boolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...));
245 #define CATCH_BLOCK 1
246 void Job_CatchChildren(void);
247 void Job_CatchOutput(void);
248 void Job_Make(GNode *);
249 void Job_Init(void);
250 Boolean Job_Full(void);
251 Boolean Job_Empty(void);
252 ReturnStatus Job_ParseShell(char *);
253 int Job_Finish(void);
254 void Job_End(void);
255 void Job_Wait(void);
256 void Job_AbortAll(void);
257 void JobFlagForMigration(int);
258 void Job_TokenReturn(void);
259 Boolean Job_TokenWithdraw(void);
260 void Job_ServerStart(int, int, int);
261 void Job_SetPrefix(void);
263 #endif /* _JOB_H_ */