job.h revision 1.60
11.60Srillig/* $NetBSD: job.h,v 1.60 2020/11/07 21:24:33 rillig Exp $ */ 21.4Schristos 31.1Scgd/* 41.1Scgd * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 51.20Sagc * All rights reserved. 61.20Sagc * 71.20Sagc * This code is derived from software contributed to Berkeley by 81.20Sagc * Adam de Boor. 91.20Sagc * 101.20Sagc * Redistribution and use in source and binary forms, with or without 111.20Sagc * modification, are permitted provided that the following conditions 121.20Sagc * are met: 131.20Sagc * 1. Redistributions of source code must retain the above copyright 141.20Sagc * notice, this list of conditions and the following disclaimer. 151.20Sagc * 2. Redistributions in binary form must reproduce the above copyright 161.20Sagc * notice, this list of conditions and the following disclaimer in the 171.20Sagc * documentation and/or other materials provided with the distribution. 181.20Sagc * 3. Neither the name of the University nor the names of its contributors 191.20Sagc * may be used to endorse or promote products derived from this software 201.20Sagc * without specific prior written permission. 211.20Sagc * 221.20Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231.20Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.20Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.20Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.20Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.20Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.20Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.20Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.20Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.20Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.20Sagc * SUCH DAMAGE. 331.20Sagc * 341.20Sagc * from: @(#)job.h 8.1 (Berkeley) 6/6/93 351.20Sagc */ 361.20Sagc 371.20Sagc/* 381.1Scgd * Copyright (c) 1988, 1989 by Adam de Boor 391.1Scgd * Copyright (c) 1989 by Berkeley Softworks 401.1Scgd * All rights reserved. 411.1Scgd * 421.1Scgd * This code is derived from software contributed to Berkeley by 431.1Scgd * Adam de Boor. 441.1Scgd * 451.1Scgd * Redistribution and use in source and binary forms, with or without 461.1Scgd * modification, are permitted provided that the following conditions 471.1Scgd * are met: 481.1Scgd * 1. Redistributions of source code must retain the above copyright 491.1Scgd * notice, this list of conditions and the following disclaimer. 501.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 511.1Scgd * notice, this list of conditions and the following disclaimer in the 521.1Scgd * documentation and/or other materials provided with the distribution. 531.1Scgd * 3. All advertising materials mentioning features or use of this software 541.1Scgd * must display the following acknowledgement: 551.1Scgd * This product includes software developed by the University of 561.1Scgd * California, Berkeley and its contributors. 571.1Scgd * 4. Neither the name of the University nor the names of its contributors 581.1Scgd * may be used to endorse or promote products derived from this software 591.1Scgd * without specific prior written permission. 601.1Scgd * 611.1Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 621.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 631.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 641.1Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 651.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 661.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 671.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 681.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 691.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 701.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 711.1Scgd * SUCH DAMAGE. 721.1Scgd * 731.5Schristos * from: @(#)job.h 8.1 (Berkeley) 6/6/93 741.1Scgd */ 751.1Scgd 761.52Srillig/* 771.52Srillig * Running of jobs in parallel mode. 781.1Scgd */ 791.52Srillig 801.44Srillig#ifndef MAKE_JOB_H 811.44Srillig#define MAKE_JOB_H 821.1Scgd 831.39Sapb#define TMPPAT "makeXXXXXX" /* relative to tmpdir */ 841.1Scgd 851.10Ssommerfe#ifdef USE_SELECT 861.1Scgd/* 871.17Sgson * Emulate poll() in terms of select(). This is not a complete 881.17Sgson * emulation but it is sufficient for make's purposes. 891.1Scgd */ 901.17Sgson 911.17Sgson#define poll emul_poll 921.17Sgson#define pollfd emul_pollfd 931.17Sgson 941.17Sgsonstruct emul_pollfd { 951.17Sgson int fd; 961.17Sgson short events; 971.17Sgson short revents; 981.17Sgson}; 991.17Sgson 1001.17Sgson#define POLLIN 0x0001 1011.17Sgson#define POLLOUT 0x0004 1021.17Sgson 1031.17Sgsonint 1041.17Sgsonemul_poll(struct pollfd *fd, int nfd, int timeout); 1051.17Sgson#endif 1061.17Sgson 1071.10Ssommerfe/* 1081.10Ssommerfe * The POLL_MSEC constant determines the maximum number of milliseconds spent 1091.43Srillig * in poll before coming out to see if a child has finished. 1101.10Ssommerfe */ 1111.10Ssommerfe#define POLL_MSEC 5000 1121.1Scgd 1131.9Schristosstruct pollfd; 1141.9Schristos 1151.40Ssjg 1161.40Ssjg#ifdef USE_META 1171.40Ssjg# include "meta.h" 1181.40Ssjg#endif 1191.40Ssjg 1201.57Srilligtypedef enum JobState { 1211.57Srillig JOB_ST_FREE = 0, /* Job is available */ 1221.57Srillig JOB_ST_SETUP = 1, /* Job is allocated but otherwise invalid */ 1231.60Srillig /* XXX: What about the 2? */ 1241.57Srillig JOB_ST_RUNNING = 3, /* Job is running, pid valid */ 1251.57Srillig JOB_ST_FINISHED = 4 /* Job is done (ie after SIGCHILD) */ 1261.57Srillig} JobState; 1271.57Srillig 1281.57Srilligtypedef enum JobFlags { 1291.59Srillig JOB_NONE = 0, 1301.57Srillig /* Ignore non-zero exits */ 1311.59Srillig JOB_IGNERR = 1 << 0, 1321.57Srillig /* no output */ 1331.59Srillig JOB_SILENT = 1 << 1, 1341.57Srillig /* Target is a special one. i.e. run it locally 1351.57Srillig * if we can't export it and maxLocal is 0 */ 1361.59Srillig JOB_SPECIAL = 1 << 2, 1371.57Srillig /* Ignore "..." lines when processing commands */ 1381.59Srillig JOB_IGNDOTS = 1 << 3, 1391.57Srillig /* we've sent 'set -x' */ 1401.59Srillig JOB_TRACED = 1 << 10 1411.57Srillig} JobFlags; 1421.57Srillig 1431.52Srillig/* A Job manages the shell commands that are run to create a single target. 1441.52Srillig * Each job is run in a separate subprocess by a shell. Several jobs can run 1451.52Srillig * in parallel. 1461.52Srillig * 1471.52Srillig * The shell commands for the target are written to a temporary file, 1481.52Srillig * then the shell is run with the temporary file as stdin, and the output 1491.52Srillig * of that shell is captured via a pipe. 1501.52Srillig * 1511.52Srillig * When a job is finished, Make_Update updates all parents of the node 1521.52Srillig * that was just remade, marking them as ready to be made next if all 1531.52Srillig * other dependencies are finished as well. */ 1541.1Scgdtypedef struct Job { 1551.52Srillig /* The process ID of the shell running the commands */ 1561.52Srillig int pid; 1571.52Srillig 1581.52Srillig /* The target the child is making */ 1591.52Srillig GNode *node; 1601.52Srillig 1611.52Srillig /* If one of the shell commands is "...", all following commands are 1621.52Srillig * delayed until the .END node is made. This list node points to the 1631.52Srillig * first of these commands, if any. */ 1641.52Srillig StringListNode *tailCmds; 1651.52Srillig 1661.52Srillig /* When creating the shell script, this is where the commands go. 1671.52Srillig * This is only used before the job is actually started. */ 1681.52Srillig FILE *cmdFILE; 1691.52Srillig 1701.51Srillig int exit_status; /* from wait4() in signal handler */ 1711.52Srillig 1721.57Srillig JobState job_state; /* status of the job entry */ 1731.52Srillig 1741.60Srillig Boolean suspended; 1751.52Srillig 1761.57Srillig JobFlags flags; /* Flags to control treatment of job */ 1771.15Ssjg 1781.53Srillig int inPipe; /* Pipe for reading output from job */ 1791.53Srillig int outPipe; /* Pipe for writing control commands */ 1801.32Sdsl struct pollfd *inPollfd; /* pollfd associated with inPipe */ 1811.52Srillig 1821.52Srillig#define JOB_BUFSIZE 1024 1831.52Srillig /* Buffer for storing the output of the job, line by line. */ 1841.51Srillig char outBuf[JOB_BUFSIZE + 1]; 1851.55Srillig size_t curPos; /* Current position in outBuf. */ 1861.40Ssjg 1871.40Ssjg#ifdef USE_META 1881.54Srillig struct BuildMon bm; 1891.40Ssjg#endif 1901.1Scgd} Job; 1911.1Scgd 1921.19Ssjgextern const char *shellPath; 1931.19Ssjgextern const char *shellName; 1941.42Ssjgextern char *shellErrFlag; 1951.19Ssjg 1961.54Srilligextern int jobTokensRunning; /* tokens currently "out" */ 1971.11Ssommerfe 1981.19Ssjgvoid Shell_Init(void); 1991.28Srilligconst char *Shell_GetNewline(void); 2001.16Swizvoid Job_Touch(GNode *, Boolean); 2011.54SrilligBoolean Job_CheckCommands(GNode *, void (*abortProc)(const char *, ...)); 2021.32Sdslvoid Job_CatchChildren(void); 2031.16Swizvoid Job_CatchOutput(void); 2041.16Swizvoid Job_Make(GNode *); 2051.27Sdslvoid Job_Init(void); 2061.47SrilligBoolean Job_ParseShell(char *); 2071.16Swizint Job_Finish(void); 2081.16Swizvoid Job_End(void); 2091.16Swizvoid Job_Wait(void); 2101.16Swizvoid Job_AbortAll(void); 2111.16Swizvoid Job_TokenReturn(void); 2121.16SwizBoolean Job_TokenWithdraw(void); 2131.33Sdslvoid Job_ServerStart(int, int, int); 2141.34Ssjgvoid Job_SetPrefix(void); 2151.41SchristosBoolean Job_RunTarget(const char *, const char *); 2161.3Scgd 2171.44Srillig#endif /* MAKE_JOB_H */ 218