source: trunk/src/kmk/job.h@ 22

Last change on this file since 22 was 9, checked in by bird, 23 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/*
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1988, 1989 by Adam de Boor
5 * Copyright (c) 1989 by Berkeley Softworks
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Adam de Boor.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)job.h 8.1 (Berkeley) 6/6/93
40 * $FreeBSD: src/usr.bin/make/job.h,v 1.20 2002/10/09 01:56:02 jmallett Exp $
41 */
42
43/*-
44 * job.h --
45 * Definitions pertaining to the running of jobs in parallel mode.
46 * Exported from job.c for the use of remote-execution modules.
47 */
48#ifndef _JOB_H_
49#define _JOB_H_
50
51#define TMPPAT "/tmp/makeXXXXXXXXXX"
52
53#ifndef USE_KQUEUE
54/*
55 * The SEL_ constants determine the maximum amount of time spent in select
56 * before coming out to see if a child has finished. SEL_SEC is the number of
57 * seconds and SEL_USEC is the number of micro-seconds
58 */
59#define SEL_SEC 0
60#define SEL_USEC 100000
61#endif /* !USE_KQUEUE */
62
63
64
65/*-
66 * Job Table definitions.
67 *
68 * Each job has several things associated with it:
69 * 1) The process id of the child shell
70 * 2) The graph node describing the target being made by this job
71 * 3) A LstNode for the first command to be saved after the job
72 * completes. This is NULL if there was no "..." in the job's
73 * commands.
74 * 4) An FILE* for writing out the commands. This is only
75 * used before the job is actually started.
76 * 5) A union of things used for handling the shell's output. Different
77 * parts of the union are used based on the value of the usePipes
78 * flag. If it is true, the output is being caught via a pipe and
79 * the descriptors of our pipe, an array in which output is line
80 * buffered and the current position in that buffer are all
81 * maintained for each job. If, on the other hand, usePipes is false,
82 * the output is routed to a temporary file and all that is kept
83 * is the name of the file and the descriptor open to the file.
84 * 6) An identifier provided by and for the exclusive use of the
85 * Rmt module.
86 * 7) A word of flags which determine how the module handles errors,
87 * echoing, etc. for the job
88 *
89 * The job "table" is kept as a linked Lst in 'jobs', with the number of
90 * active jobs maintained in the 'nJobs' variable. At no time will this
91 * exceed the value of 'maxJobs', initialized by the Job_Init function.
92 *
93 * When a job is finished, the Make_Update function is called on each of the
94 * parents of the node which was just remade. This takes care of the upward
95 * traversal of the dependency graph.
96 */
97#define JOB_BUFSIZE 1024
98typedef struct Job {
99 int pid; /* The child's process ID */
100 char tfile[sizeof(TMPPAT)];
101 /* Temporary file to use for job */
102 GNode *node; /* The target the child is making */
103 LstNode tailCmds; /* The node of the first command to be
104 * saved when the job has been run */
105 FILE *cmdFILE; /* When creating the shell script, this is
106 * where the commands go */
107 int rmtID; /* ID returned from Rmt module */
108 short flags; /* Flags to control treatment of job */
109#define JOB_IGNERR 0x001 /* Ignore non-zero exits */
110#define JOB_SILENT 0x002 /* no output */
111#define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
112 * if we can't export it and maxLocal is 0 */
113#define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing
114 * commands */
115#define JOB_REMOTE 0x010 /* Job is running remotely */
116#define JOB_FIRST 0x020 /* Job is first job for the node */
117#define JOB_REMIGRATE 0x040 /* Job needs to be remigrated */
118#define JOB_RESTART 0x080 /* Job needs to be completely restarted */
119#define JOB_RESUME 0x100 /* Job needs to be resumed b/c it stopped,
120 * for some reason */
121#define JOB_CONTINUING 0x200 /* We are in the process of resuming this job.
122 * Used to avoid infinite recursion between
123 * JobFinish and JobRestart */
124 union {
125 struct {
126 int op_inPipe; /* Input side of pipe associated
127 * with job's output channel */
128 int op_outPipe; /* Output side of pipe associated with
129 * job's output channel */
130 char op_outBuf[JOB_BUFSIZE + 1];
131 /* Buffer for storing the output of the
132 * job, line by line */
133 int op_curPos; /* Current position in op_outBuf */
134 } o_pipe; /* data used when catching the output via
135 * a pipe */
136 struct {
137 char of_outFile[sizeof(TMPPAT)];
138 /* Name of file to which shell output
139 * was rerouted */
140 int of_outFd; /* Stream open to the output
141 * file. Used to funnel all
142 * from a single job to one file
143 * while still allowing
144 * multiple shell invocations */
145 } o_file; /* Data used when catching the output in
146 * a temporary file */
147 } output; /* Data for tracking a shell's output */
148} Job;
149
150#define outPipe output.o_pipe.op_outPipe
151#define inPipe output.o_pipe.op_inPipe
152#define outBuf output.o_pipe.op_outBuf
153#define curPos output.o_pipe.op_curPos
154#define outFile output.o_file.of_outFile
155#define outFd output.o_file.of_outFd
156
157
158
159/*-
160 * Shell Specifications:
161 * Each shell type has associated with it the following information:
162 * 1) The string which must match the last character of the shell name
163 * for the shell to be considered of this type. The longest match
164 * wins.
165 * 2) A command to issue to turn off echoing of command lines
166 * 3) A command to issue to turn echoing back on again
167 * 4) What the shell prints, and its length, when given the echo-off
168 * command. This line will not be printed when received from the shell
169 * 5) A boolean to tell if the shell has the ability to control
170 * error checking for individual commands.
171 * 6) The string to turn this checking on.
172 * 7) The string to turn it off.
173 * 8) The command-flag to give to cause the shell to start echoing
174 * commands right away.
175 * 9) The command-flag to cause the shell to Lib_Exit when an error is
176 * detected in one of the commands.
177 *
178 * Some special stuff goes on if a shell doesn't have error control. In such
179 * a case, errCheck becomes a printf template for echoing the command,
180 * should echoing be on and ignErr becomes another printf template for
181 * executing the command while ignoring the return status. If either of these
182 * strings is empty when hasErrCtl is FALSE, the command will be executed
183 * anyway as is and if it causes an error, so be it.
184 */
185typedef struct Shell {
186 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.
191 */
192 Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */
193 char *echoOff; /* command to turn off echo */
194 char *echoOn; /* command to turn it back on again */
195 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 char *errCheck; /* string to turn error checking on */
202 char *ignErr; /* string to turn off error checking */
203 /*
204 * command-line flags
205 */
206 char *echo; /* echo commands */
207 char *exit; /* exit on error */
208} Shell;
209
210/*
211 * If REMOTE is defined then these things need exposed, otherwise they are
212 * static to job.c!
213 */
214#ifdef REMOTE
215extern char *targFmt; /* Format string for banner that separates
216 * output from multiple jobs. Contains a
217 * single %s where the name of the node being
218 * made should be put. */
219extern GNode *lastNode; /* Last node for which a banner was printed.
220 * If Rmt module finds it necessary to print
221 * a banner, it should set this to the node
222 * for which the banner was printed */
223extern int nJobs; /* Number of jobs running (local and remote) */
224extern int nLocal; /* Number of jobs running locally */
225extern Lst jobs; /* List of active job descriptors */
226extern Lst stoppedJobs; /* List of jobs that are stopped or didn't
227 * quite get started */
228extern Boolean jobFull; /* Non-zero if no more jobs should/will start*/
229#endif
230
231extern int maxJobs; /* Number of jobs that may run */
232
233
234void Job_Touch(GNode *, Boolean);
235Boolean Job_CheckCommands(GNode *, void (*abortProc)(const char *, ...));
236void Job_CatchChildren(Boolean);
237void Job_CatchOutput(void);
238void Job_Make(GNode *);
239void Job_Init(int, int);
240Boolean Job_Full(void);
241Boolean Job_Empty(void);
242ReturnStatus Job_ParseShell(char *);
243int Job_Finish(void);
244void Job_Wait(void);
245void Job_AbortAll(void);
246void JobFlagForMigration(int);
247
248#endif /* _JOB_H_ */
Note: See TracBrowser for help on using the repository browser.