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