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