Annotation of src/usr.bin/make/job.h, Revision 1.10
1.10 ! espie 1: #ifndef _JOB_H_
! 2: #define _JOB_H_
! 3:
1.9 espie 4: /* $OpenPackages$ */
5: /* $OpenBSD: job.h,v 1.5 1998/12/05 00:06:28 espie Exp $ */
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 */
1.3 millert 112: #define JOB_REMOTE 0x010 /* Job is running remotely */
1.1 deraadt 113: #define JOB_FIRST 0x020 /* Job is first job for the node */
114: #define JOB_REMIGRATE 0x040 /* Job needs to be remigrated */
115: #define JOB_RESTART 0x080 /* Job needs to be completely restarted */
116: #define JOB_RESUME 0x100 /* Job needs to be resumed b/c it stopped,
117: * for some reason */
118: #define JOB_CONTINUING 0x200 /* We are in the process of resuming this job.
119: * Used to avoid infinite recursion between
120: * JobFinish and JobRestart */
121: union {
122: struct {
1.9 espie 123: int op_inPipe; /* Input side of pipe associated
1.1 deraadt 124: * with job's output channel */
1.9 espie 125: int op_outPipe; /* Output side of pipe associated with
1.1 deraadt 126: * job's output channel */
1.9 espie 127: char op_outBuf[JOB_BUFSIZE + 1];
128: /* Buffer for storing the output of the
1.1 deraadt 129: * job, line by line */
1.9 espie 130: int op_curPos; /* Current position in op_outBuf */
131: } o_pipe; /* data used when catching the output via
1.1 deraadt 132: * a pipe */
133: struct {
1.9 espie 134: char of_outFile[sizeof(TMPPAT)];
135: /* Name of file to which shell output
1.1 deraadt 136: * was rerouted */
1.9 espie 137: int of_outFd; /* Stream open to the output
1.1 deraadt 138: * file. Used to funnel all
139: * from a single job to one file
140: * while still allowing
141: * multiple shell invocations */
1.9 espie 142: } o_file; /* Data used when catching the output in
1.1 deraadt 143: * a temporary file */
1.9 espie 144: } output; /* Data for tracking a shell's output */
1.1 deraadt 145: } Job;
146:
1.9 espie 147: #define outPipe output.o_pipe.op_outPipe
148: #define inPipe output.o_pipe.op_inPipe
1.1 deraadt 149: #define outBuf output.o_pipe.op_outBuf
150: #define curPos output.o_pipe.op_curPos
1.9 espie 151: #define outFile output.o_file.of_outFile
152: #define outFd output.o_file.of_outFd
153:
1.1 deraadt 154:
155: /*-
156: * Shell Specifications:
157: * Each shell type has associated with it the following information:
158: * 1) The string which must match the last character of the shell name
159: * for the shell to be considered of this type. The longest match
160: * wins.
161: * 2) A command to issue to turn off echoing of command lines
162: * 3) A command to issue to turn echoing back on again
163: * 4) What the shell prints, and its length, when given the echo-off
164: * command. This line will not be printed when received from the shell
165: * 5) A boolean to tell if the shell has the ability to control
166: * error checking for individual commands.
167: * 6) The string to turn this checking on.
168: * 7) The string to turn it off.
169: * 8) The command-flag to give to cause the shell to start echoing
170: * commands right away.
171: * 9) The command-flag to cause the shell to Lib_Exit when an error is
172: * detected in one of the commands.
173: *
174: * Some special stuff goes on if a shell doesn't have error control. In such
175: * a case, errCheck becomes a printf template for echoing the command,
176: * should echoing be on and ignErr becomes another printf template for
177: * executing the command while ignoring the return status. If either of these
1.10 ! espie 178: * strings is empty when hasErrCtl is false, the command will be executed
1.1 deraadt 179: * anyway as is and if it causes an error, so be it.
180: */
1.9 espie 181: typedef struct Shell_ {
1.1 deraadt 182: char *name; /* the name of the shell. For Bourne and C
183: * shells, this is used only to find the
184: * shell description when used as the single
185: * source of a .SHELL target. For user-defined
186: * shells, this is the full path of the shell.
187: */
1.10 ! espie 188: bool hasEchoCtl; /* True if both echoOff and echoOn defined */
1.9 espie 189: char *echoOff; /* command to turn off echo */
190: char *echoOn; /* command to turn it back on again */
191: char *noPrint; /* command to skip when printing output from
1.1 deraadt 192: * shell. This is usually the command which
193: * was executed to turn off echoing */
1.9 espie 194: int noPLen; /* length of noPrint command */
1.10 ! espie 195: bool hasErrCtl; /* set if can control error checking for
1.1 deraadt 196: * individual commands */
197: char *errCheck; /* string to turn error checking on */
198: char *ignErr; /* string to turn off error checking */
199: /*
1.3 millert 200: * command-line flags
1.1 deraadt 201: */
1.9 espie 202: char *echo; /* echo commands */
203: char *exit; /* exit on error */
204: } Shell;
1.1 deraadt 205:
206:
1.9 espie 207: #ifdef REMOTE
208: extern char *targFmt; /* Format string for banner that separates
1.1 deraadt 209: * output from multiple jobs. Contains a
210: * single %s where the name of the node being
211: * made should be put. */
1.9 espie 212: extern GNode *lastNode; /* Last node for which a banner was printed.
1.1 deraadt 213: * If Rmt module finds it necessary to print
214: * a banner, it should set this to the node
215: * for which the banner was printed */
1.9 espie 216: extern int nJobs; /* Number of jobs running (local and remote) */
217: extern int nLocal; /* Number of jobs running locally */
218: extern LIST jobs; /* List of active job descriptors */
1.10 ! espie 219: extern bool jobFull; /* Non-zero if no more jobs should/will start*/
1.9 espie 220: extern LIST stoppedJobs; /* List of jobs that are stopped or didn't
1.1 deraadt 221: * quite get started */
1.9 espie 222: #endif
1.1 deraadt 223:
224:
1.10 ! espie 225: extern void Job_Touch(GNode *, bool);
! 226: extern bool Job_CheckCommands(GNode *,
1.9 espie 227: void (*abortProc )(char *, ...));
1.10 ! espie 228: extern void Job_CatchChildren(bool);
1.9 espie 229: extern void Job_CatchOutput(void);
230: extern void Job_Make(GNode *);
231: extern void Job_Init(int, int);
1.10 ! espie 232: extern bool Job_Full(void);
! 233: extern bool Job_Empty(void);
! 234: extern bool Job_ParseShell(char *);
1.9 espie 235: extern int Job_Finish(void);
1.10 ! espie 236: #ifdef CLEANUP
1.9 espie 237: extern void Job_End(void);
1.10 ! espie 238: #else
! 239: #define Job_End()
! 240: #endif
1.9 espie 241: extern void Job_Wait(void);
242: extern void Job_AbortAll(void);
243: extern void JobFlagForMigration(int);
1.1 deraadt 244:
245: #endif /* _JOB_H_ */