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