date and time created 90/06/01 17:06:29 by bostic
[unix-history] / usr / src / usr.bin / make / job.h
CommitLineData
9320ab9e
KB
1/*
2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
ab950546
KB
3 * Copyright (c) 1988, 1989 by Adam de Boor
4 * Copyright (c) 1989 by Berkeley Softworks
9320ab9e
KB
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
ab950546 9 *
9320ab9e
KB
10 * Redistribution and use in source and binary forms are permitted
11 * provided that the above copyright notice and this paragraph are
12 * duplicated in all such forms and that any documentation,
13 * advertising materials, and other materials related to such
14 * distribution and use acknowledge that the software was developed
15 * by the University of California, Berkeley. The name of the
16 * University may not be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
ab950546 21 *
9320ab9e
KB
22 * @(#)job.h 5.2 (Berkeley) %G%
23 */
24
25/*-
26 * job.h --
27 * Definitions pertaining to the running of jobs in parallel mode.
28 * Exported from job.c for the use of remote-execution modules.
ab950546
KB
29 */
30#ifndef _JOB_H_
31#define _JOB_H_
32
33#define TMPPAT "/tmp/makeXXXXX"
34
35/*
36 * The SEL_ constants determine the maximum amount of time spent in select
37 * before coming out to see if a child has finished. SEL_SEC is the number of
38 * seconds and SEL_USEC is the number of micro-seconds
39 */
40#define SEL_SEC 0
41#define SEL_USEC 500000
42
43\f
44/*-
45 * Job Table definitions.
46 *
47 * Each job has several things associated with it:
48 * 1) The process id of the child shell
49 * 2) The graph node describing the target being made by this job
50 * 3) A LstNode for the first command to be saved after the job
51 * completes. This is NILLNODE if there was no "..." in the job's
52 * commands.
53 * 4) An FILE* for writing out the commands. This is only
54 * used before the job is actually started.
55 * 5) A union of things used for handling the shell's output. Different
56 * parts of the union are used based on the value of the usePipes
57 * flag. If it is true, the output is being caught via a pipe and
58 * the descriptors of our pipe, an array in which output is line
59 * buffered and the current position in that buffer are all
60 * maintained for each job. If, on the other hand, usePipes is false,
61 * the output is routed to a temporary file and all that is kept
62 * is the name of the file and the descriptor open to the file.
63 * 6) An identifier provided by and for the exclusive use of the
64 * Rmt module.
65 * 7) A word of flags which determine how the module handles errors,
66 * echoing, etc. for the job
67 *
68 * The job "table" is kept as a linked Lst in 'jobs', with the number of
69 * active jobs maintained in the 'nJobs' variable. At no time will this
70 * exceed the value of 'maxJobs', initialized by the Job_Init function.
71 *
72 * When a job is finished, the Make_Update function is called on each of the
73 * parents of the node which was just remade. This takes care of the upward
74 * traversal of the dependency graph.
75 */
76#define JOB_BUFSIZE 1024
77typedef struct Job {
78 int pid; /* The child's process ID */
79 GNode *node; /* The target the child is making */
80 LstNode tailCmds; /* The node of the first command to be
81 * saved when the job has been run */
82 FILE *cmdFILE; /* When creating the shell script, this is
83 * where the commands go */
84 char *rmtID; /* ID returned from Rmt module */
85 short flags; /* Flags to control treatment of job */
86#define JOB_IGNERR 0x001 /* Ignore non-zero exits */
87#define JOB_SILENT 0x002 /* no output */
88#define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
89 * if we can't export it and maxLocal is 0 */
90#define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing
91 * commands */
92#define JOB_REMOTE 0x010 /* Job is running remotely */
93#define JOB_FIRST 0x020 /* Job is first job for the node */
94#define JOB_REMIGRATE 0x040 /* Job needs to be remigrated */
95#define JOB_RESTART 0x080 /* Job needs to be completely restarted */
96#define JOB_RESUME 0x100 /* Job needs to be resumed b/c it stopped,
97 * for some reason */
98#define JOB_CONTINUING 0x200 /* We are in the process of resuming this job.
99 * Used to avoid infinite recursion between
100 * JobFinish and JobRestart */
101 union {
102 struct {
103 int op_inPipe; /* Input side of pipe associated
104 * with job's output channel */
105 int op_outPipe; /* Output side of pipe associated with
106 * job's output channel */
107 char op_outBuf[JOB_BUFSIZE + 1];
108 /* Buffer for storing the output of the
109 * job, line by line */
110 int op_curPos; /* Current position in op_outBuf */
111 } o_pipe; /* data used when catching the output via
112 * a pipe */
113 struct {
114 char of_outFile[sizeof(TMPPAT)+2];
115 /* Name of file to which shell output
116 * was rerouted */
117 int of_outFd; /* Stream open to the output
118 * file. Used to funnel all
119 * from a single job to one file
120 * while still allowing
121 * multiple shell invocations */
122 } o_file; /* Data used when catching the output in
123 * a temporary file */
124 } output; /* Data for tracking a shell's output */
125} Job;
126
127#define outPipe output.o_pipe.op_outPipe
128#define inPipe output.o_pipe.op_inPipe
129#define outBuf output.o_pipe.op_outBuf
130#define curPos output.o_pipe.op_curPos
131#define outFile output.o_file.of_outFile
132#define outFd output.o_file.of_outFd
133
134\f
135/*-
136 * Shell Specifications:
137 * Each shell type has associated with it the following information:
138 * 1) The string which must match the last character of the shell name
139 * for the shell to be considered of this type. The longest match
140 * wins.
141 * 2) A command to issue to turn off echoing of command lines
142 * 3) A command to issue to turn echoing back on again
143 * 4) What the shell prints, and its length, when given the echo-off
144 * command. This line will not be printed when received from the shell
145 * 5) A boolean to tell if the shell has the ability to control
146 * error checking for individual commands.
147 * 6) The string to turn this checking on.
148 * 7) The string to turn it off.
149 * 8) The command-flag to give to cause the shell to start echoing
150 * commands right away.
151 * 9) The command-flag to cause the shell to Lib_Exit when an error is
152 * detected in one of the commands.
153 *
154 * Some special stuff goes on if a shell doesn't have error control. In such
155 * a case, errCheck becomes a printf template for echoing the command,
156 * should echoing be on and ignErr becomes another printf template for
157 * executing the command while ignoring the return status. If either of these
158 * strings is empty when hasErrCtl is FALSE, the command will be executed
159 * anyway as is and if it causes an error, so be it.
160 */
161typedef struct Shell {
162 char *name; /* the name of the shell. For Bourne and C
163 * shells, this is used only to find the
164 * shell description when used as the single
165 * source of a .SHELL target. For user-defined
166 * shells, this is the full path of the shell.
167 */
168 Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */
169 char *echoOff; /* command to turn off echo */
170 char *echoOn; /* command to turn it back on again */
171 char *noPrint; /* command to skip when printing output from
172 * shell. This is usually the command which
173 * was executed to turn off echoing */
174 int noPLen; /* length of noPrint command */
175 Boolean hasErrCtl; /* set if can control error checking for
176 * individual commands */
177 char *errCheck; /* string to turn error checking on */
178 char *ignErr; /* string to turn off error checking */
179 /*
180 * command-line flags
181 */
182 char *echo; /* echo commands */
183 char *exit; /* exit on error */
184} Shell;
185
186
187extern char *targFmt; /* Format string for banner that separates
188 * output from multiple jobs. Contains a
189 * single %s where the name of the node being
190 * made should be put. */
191extern GNode *lastNode; /* Last node for which a banner was printed.
192 * If Rmt module finds it necessary to print
193 * a banner, it should set this to the node
194 * for which the banner was printed */
195extern int nJobs; /* Number of jobs running (local and remote) */
196extern int nLocal; /* Number of jobs running locally */
197extern Lst jobs; /* List of active job descriptors */
198extern Lst stoppedJobs; /* List of jobs that are stopped or didn't
199 * quite get started */
200extern Boolean jobFull; /* Non-zero if no more jobs should/will start*/
201
202/*
203 * These functions should be used only by an intelligent Rmt module, hence
204 * their names do *not* include an underscore as they are not fully exported,
205 * if you see what I mean.
206 */
207extern void JobDoOutput(/* job, final? */); /* Funnel output from
208 * job->outPipe to the screen,
209 * filtering out echo-off
210 * strings etc. */
211extern void JobFinish(/* job, status */); /* Finish out a job. If
212 * status indicates job has
213 * just stopped, not finished,
214 * the descriptor is placed on
215 * the stoppedJobs list. */
216#endif /* _JOB_H_ */