job.h revision 1.18
11.18Schristos/* $NetBSD: job.h,v 1.18 2003/07/14 18:19:12 christos Exp $ */ 21.4Schristos 31.1Scgd/* 41.1Scgd * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 51.1Scgd * Copyright (c) 1988, 1989 by Adam de Boor 61.1Scgd * Copyright (c) 1989 by Berkeley Softworks 71.1Scgd * All rights reserved. 81.1Scgd * 91.1Scgd * This code is derived from software contributed to Berkeley by 101.1Scgd * Adam de Boor. 111.1Scgd * 121.1Scgd * Redistribution and use in source and binary forms, with or without 131.1Scgd * modification, are permitted provided that the following conditions 141.1Scgd * are met: 151.1Scgd * 1. Redistributions of source code must retain the above copyright 161.1Scgd * notice, this list of conditions and the following disclaimer. 171.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 181.1Scgd * notice, this list of conditions and the following disclaimer in the 191.1Scgd * documentation and/or other materials provided with the distribution. 201.1Scgd * 3. All advertising materials mentioning features or use of this software 211.1Scgd * must display the following acknowledgement: 221.1Scgd * This product includes software developed by the University of 231.1Scgd * California, Berkeley and its contributors. 241.1Scgd * 4. Neither the name of the University nor the names of its contributors 251.1Scgd * may be used to endorse or promote products derived from this software 261.1Scgd * without specific prior written permission. 271.1Scgd * 281.1Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 291.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 301.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 311.1Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 321.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 331.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 341.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 351.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 361.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 371.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 381.1Scgd * SUCH DAMAGE. 391.1Scgd * 401.5Schristos * from: @(#)job.h 8.1 (Berkeley) 6/6/93 411.1Scgd */ 421.1Scgd 431.1Scgd/*- 441.1Scgd * job.h -- 451.1Scgd * Definitions pertaining to the running of jobs in parallel mode. 461.1Scgd * Exported from job.c for the use of remote-execution modules. 471.1Scgd */ 481.1Scgd#ifndef _JOB_H_ 491.1Scgd#define _JOB_H_ 501.1Scgd 511.8Schristos#define TMPPAT "/tmp/makeXXXXXX" 521.1Scgd 531.10Ssommerfe#ifdef USE_SELECT 541.1Scgd/* 551.17Sgson * Emulate poll() in terms of select(). This is not a complete 561.17Sgson * emulation but it is sufficient for make's purposes. 571.1Scgd */ 581.17Sgson 591.17Sgson#define poll emul_poll 601.17Sgson#define pollfd emul_pollfd 611.17Sgson 621.17Sgsonstruct emul_pollfd { 631.17Sgson int fd; 641.17Sgson short events; 651.17Sgson short revents; 661.17Sgson}; 671.17Sgson 681.17Sgson#define POLLIN 0x0001 691.17Sgson#define POLLOUT 0x0004 701.17Sgson 711.17Sgsonint 721.17Sgsonemul_poll(struct pollfd *fd, int nfd, int timeout); 731.17Sgson#endif 741.17Sgson 751.10Ssommerfe/* 761.10Ssommerfe * The POLL_MSEC constant determines the maximum number of milliseconds spent 771.10Ssommerfe * in poll before coming out to see if a child has finished. 781.10Ssommerfe */ 791.10Ssommerfe#define POLL_MSEC 5000 801.1Scgd 811.1Scgd 821.1Scgd/*- 831.5Schristos * Job Table definitions. 841.1Scgd * 851.1Scgd * Each job has several things associated with it: 861.1Scgd * 1) The process id of the child shell 871.1Scgd * 2) The graph node describing the target being made by this job 881.1Scgd * 3) A LstNode for the first command to be saved after the job 891.1Scgd * completes. This is NILLNODE if there was no "..." in the job's 901.1Scgd * commands. 911.1Scgd * 4) An FILE* for writing out the commands. This is only 921.1Scgd * used before the job is actually started. 931.1Scgd * 5) A union of things used for handling the shell's output. Different 941.1Scgd * parts of the union are used based on the value of the usePipes 951.1Scgd * flag. If it is true, the output is being caught via a pipe and 961.1Scgd * the descriptors of our pipe, an array in which output is line 971.1Scgd * buffered and the current position in that buffer are all 981.1Scgd * maintained for each job. If, on the other hand, usePipes is false, 991.1Scgd * the output is routed to a temporary file and all that is kept 1001.1Scgd * is the name of the file and the descriptor open to the file. 1011.1Scgd * 6) An identifier provided by and for the exclusive use of the 1021.1Scgd * Rmt module. 1031.1Scgd * 7) A word of flags which determine how the module handles errors, 1041.5Schristos * echoing, etc. for the job 1051.1Scgd * 1061.1Scgd * The job "table" is kept as a linked Lst in 'jobs', with the number of 1071.1Scgd * active jobs maintained in the 'nJobs' variable. At no time will this 1081.5Schristos * exceed the value of 'maxJobs', initialized by the Job_Init function. 1091.1Scgd * 1101.1Scgd * When a job is finished, the Make_Update function is called on each of the 1111.1Scgd * parents of the node which was just remade. This takes care of the upward 1121.1Scgd * traversal of the dependency graph. 1131.1Scgd */ 1141.9Schristos#ifndef RMT_WILL_WATCH 1151.9Schristosstruct pollfd; 1161.9Schristos#endif 1171.9Schristos 1181.1Scgd#define JOB_BUFSIZE 1024 1191.1Scgdtypedef struct Job { 1201.1Scgd int pid; /* The child's process ID */ 1211.1Scgd GNode *node; /* The target the child is making */ 1221.1Scgd LstNode tailCmds; /* The node of the first command to be 1231.1Scgd * saved when the job has been run */ 1241.1Scgd FILE *cmdFILE; /* When creating the shell script, this is 1251.1Scgd * where the commands go */ 1261.3Scgd int rmtID; /* ID returned from Rmt module */ 1271.1Scgd short flags; /* Flags to control treatment of job */ 1281.1Scgd#define JOB_IGNERR 0x001 /* Ignore non-zero exits */ 1291.1Scgd#define JOB_SILENT 0x002 /* no output */ 1301.1Scgd#define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally 1311.1Scgd * if we can't export it and maxLocal is 0 */ 1321.1Scgd#define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing 1331.1Scgd * commands */ 1341.5Schristos#define JOB_REMOTE 0x010 /* Job is running remotely */ 1351.1Scgd#define JOB_FIRST 0x020 /* Job is first job for the node */ 1361.1Scgd#define JOB_REMIGRATE 0x040 /* Job needs to be remigrated */ 1371.1Scgd#define JOB_RESTART 0x080 /* Job needs to be completely restarted */ 1381.1Scgd#define JOB_RESUME 0x100 /* Job needs to be resumed b/c it stopped, 1391.1Scgd * for some reason */ 1401.1Scgd#define JOB_CONTINUING 0x200 /* We are in the process of resuming this job. 1411.1Scgd * Used to avoid infinite recursion between 1421.1Scgd * JobFinish and JobRestart */ 1431.15Ssjg#define JOB_TRACED 0x400 /* we've sent 'set -x' */ 1441.15Ssjg 1451.1Scgd union { 1461.1Scgd struct { 1471.1Scgd int op_inPipe; /* Input side of pipe associated 1481.1Scgd * with job's output channel */ 1491.9Schristos#ifndef RMT_WILL_WATCH 1501.9Schristos struct pollfd *op_inPollfd; /* pollfd associated with inPipe */ 1511.9Schristos#endif 1521.1Scgd int op_outPipe; /* Output side of pipe associated with 1531.1Scgd * job's output channel */ 1541.1Scgd char op_outBuf[JOB_BUFSIZE + 1]; 1551.1Scgd /* Buffer for storing the output of the 1561.1Scgd * job, line by line */ 1571.1Scgd int op_curPos; /* Current position in op_outBuf */ 1581.1Scgd } o_pipe; /* data used when catching the output via 1591.1Scgd * a pipe */ 1601.1Scgd struct { 1611.1Scgd char of_outFile[sizeof(TMPPAT)+2]; 1621.1Scgd /* Name of file to which shell output 1631.1Scgd * was rerouted */ 1641.1Scgd int of_outFd; /* Stream open to the output 1651.1Scgd * file. Used to funnel all 1661.1Scgd * from a single job to one file 1671.1Scgd * while still allowing 1681.1Scgd * multiple shell invocations */ 1691.1Scgd } o_file; /* Data used when catching the output in 1701.1Scgd * a temporary file */ 1711.1Scgd } output; /* Data for tracking a shell's output */ 1721.1Scgd} Job; 1731.1Scgd 1741.1Scgd#define outPipe output.o_pipe.op_outPipe 1751.1Scgd#define inPipe output.o_pipe.op_inPipe 1761.9Schristos#define inPollfd output.o_pipe.op_inPollfd 1771.1Scgd#define outBuf output.o_pipe.op_outBuf 1781.1Scgd#define curPos output.o_pipe.op_curPos 1791.1Scgd#define outFile output.o_file.of_outFile 1801.1Scgd#define outFd output.o_file.of_outFd 1811.1Scgd 1821.1Scgd 1831.1Scgd/*- 1841.1Scgd * Shell Specifications: 1851.1Scgd * Each shell type has associated with it the following information: 1861.1Scgd * 1) The string which must match the last character of the shell name 1871.1Scgd * for the shell to be considered of this type. The longest match 1881.1Scgd * wins. 1891.1Scgd * 2) A command to issue to turn off echoing of command lines 1901.1Scgd * 3) A command to issue to turn echoing back on again 1911.1Scgd * 4) What the shell prints, and its length, when given the echo-off 1921.1Scgd * command. This line will not be printed when received from the shell 1931.1Scgd * 5) A boolean to tell if the shell has the ability to control 1941.1Scgd * error checking for individual commands. 1951.1Scgd * 6) The string to turn this checking on. 1961.1Scgd * 7) The string to turn it off. 1971.1Scgd * 8) The command-flag to give to cause the shell to start echoing 1981.1Scgd * commands right away. 1991.1Scgd * 9) The command-flag to cause the shell to Lib_Exit when an error is 2001.1Scgd * detected in one of the commands. 2011.1Scgd * 2021.1Scgd * Some special stuff goes on if a shell doesn't have error control. In such 2031.1Scgd * a case, errCheck becomes a printf template for echoing the command, 2041.1Scgd * should echoing be on and ignErr becomes another printf template for 2051.1Scgd * executing the command while ignoring the return status. If either of these 2061.1Scgd * strings is empty when hasErrCtl is FALSE, the command will be executed 2071.1Scgd * anyway as is and if it causes an error, so be it. 2081.1Scgd */ 2091.1Scgdtypedef struct Shell { 2101.18Schristos const char *name; /* the name of the shell. For Bourne and C 2111.1Scgd * shells, this is used only to find the 2121.1Scgd * shell description when used as the single 2131.1Scgd * source of a .SHELL target. For user-defined 2141.1Scgd * shells, this is the full path of the shell. 2151.1Scgd */ 2161.1Scgd Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */ 2171.18Schristos const char *echoOff; /* command to turn off echo */ 2181.18Schristos const char *echoOn; /* command to turn it back on again */ 2191.18Schristos const char *noPrint; /* command to skip when printing output from 2201.1Scgd * shell. This is usually the command which 2211.1Scgd * was executed to turn off echoing */ 2221.1Scgd int noPLen; /* length of noPrint command */ 2231.1Scgd Boolean hasErrCtl; /* set if can control error checking for 2241.1Scgd * individual commands */ 2251.18Schristos const char *errCheck; /* string to turn error checking on */ 2261.18Schristos const char *ignErr; /* string to turn off error checking */ 2271.1Scgd /* 2281.5Schristos * command-line flags 2291.1Scgd */ 2301.18Schristos const char *echo; /* echo commands */ 2311.18Schristos const char *exit; /* exit on error */ 2321.1Scgd} Shell; 2331.1Scgd 2341.11Ssommerfeextern int job_pipe[2]; /* token pipe for jobs. */ 2351.14Ssommerfeextern int jobTokensRunning; /* tokens currently "out" */ 2361.14Ssommerfeextern int jobTokensFree; /* tokens free but not yet released to pipe */ 2371.11Ssommerfe 2381.7Sdrochner#ifdef REMOTE 2391.1Scgdextern char *targFmt; /* Format string for banner that separates 2401.1Scgd * output from multiple jobs. Contains a 2411.1Scgd * single %s where the name of the node being 2421.1Scgd * made should be put. */ 2431.1Scgdextern GNode *lastNode; /* Last node for which a banner was printed. 2441.1Scgd * If Rmt module finds it necessary to print 2451.1Scgd * a banner, it should set this to the node 2461.1Scgd * for which the banner was printed */ 2471.1Scgdextern int nJobs; /* Number of jobs running (local and remote) */ 2481.1Scgdextern int nLocal; /* Number of jobs running locally */ 2491.1Scgdextern Lst jobs; /* List of active job descriptors */ 2501.1Scgdextern Lst stoppedJobs; /* List of jobs that are stopped or didn't 2511.1Scgd * quite get started */ 2521.7Sdrochner#endif 2531.3Scgd 2541.16Swizvoid Job_Touch(GNode *, Boolean); 2551.18SchristosBoolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...)); 2561.16Swizvoid Job_CatchChildren(Boolean); 2571.16Swizvoid Job_CatchOutput(void); 2581.16Swizvoid Job_Make(GNode *); 2591.16Swizvoid Job_Init(int, int); 2601.16SwizBoolean Job_Full(void); 2611.16SwizBoolean Job_Empty(void); 2621.16SwizReturnStatus Job_ParseShell(char *); 2631.16Swizint Job_Finish(void); 2641.16Swizvoid Job_End(void); 2651.16Swizvoid Job_Wait(void); 2661.16Swizvoid Job_AbortAll(void); 2671.16Swizvoid JobFlagForMigration(int); 2681.16Swizvoid Job_TokenReturn(void); 2691.16Swizvoid Job_TokenFlush(void); 2701.16SwizBoolean Job_TokenWithdraw(void); 2711.16Swizvoid Job_ServerStart(int); 2721.3Scgd 2731.1Scgd#endif /* _JOB_H_ */ 274