Ignore:
Timestamp:
Nov 26, 2002, 10:24:54 PM (23 years ago)
Author:
bird
Message:

Import of RELENG_4_7_0_RELEASE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FREEBSD/src/kmk/job.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)job.c    8.2 (Berkeley) 3/19/94
    40  */
    41 
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/job.c,v 1.45 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)job.c       8.2 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/job.c,v 1.17.2.2 2001/02/13 03:13:57 will Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548#ifndef OLD_JOKE
    46 #define OLD_JOKE 0
     49#define OLD_JOKE 0
    4750#endif /* OLD_JOKE */
    4851
     
    8487 *                              FAILURE if the spec was incorrect.
    8588 *
    86  *      Job_Finish                      Perform any final processing which needs doing.
     89 *      Job_End                 Perform any final processing which needs doing.
    8790 *                              This includes the execution of any commands
    8891 *                              which have been/were attached to the .END
     
    107110#include <sys/file.h>
    108111#include <sys/time.h>
    109 #include <sys/event.h>
    110112#include <sys/wait.h>
    111 #include <err.h>
     113#include <fcntl.h>
    112114#include <errno.h>
    113 #include <fcntl.h>
     115#include <utime.h>
    114116#include <stdio.h>
    115117#include <string.h>
    116118#include <signal.h>
    117 #include <unistd.h>
    118 #include <utime.h>
    119119#include "make.h"
    120120#include "hash.h"
     
    134134static int      errors = 0;         /* number of errors reported */
    135135static int      aborting = 0;       /* why is the make aborting? */
    136 #define ABORT_ERROR     1           /* Because of an error */
    137 #define ABORT_INTERRUPT 2           /* Because it was interrupted */
    138 #define ABORT_WAIT      3           /* Waiting for jobs to finish */
     136#define ABORT_ERROR     1           /* Because of an error */
     137#define ABORT_INTERRUPT 2           /* Because it was interrupted */
     138#define ABORT_WAIT      3           /* Waiting for jobs to finish */
    139139
    140140/*
     
    142142 * is a char! So when we go above 127 we turn negative!
    143143 */
    144 #define FILENO(a) ((unsigned) fileno(a))
     144#define FILENO(a) ((unsigned) fileno(a))
    145145
    146146/*
     
    158158 * Return values from JobStart.
    159159 */
    160 #define JOB_RUNNING     0       /* Job is running */
    161 #define JOB_ERROR       1       /* Error in starting the job */
    162 #define JOB_FINISHED    2       /* The job is already finished */
    163 #define JOB_STOPPED     3       /* The job is stopped */
     160#define JOB_RUNNING     0       /* Job is running */
     161#define JOB_ERROR       1       /* Error in starting the job */
     162#define JOB_FINISHED    2       /* The job is already finished */
     163#define JOB_STOPPED     3       /* The job is stopped */
    164164
    165165/*
     
    196196    FALSE, "echo \"%s\"\n", "sh -c '%s || exit 0'\n",
    197197#endif
    198     "v", "e",
    199 },
    200     /*
    201      * KSH description. The Korn shell has a superset of
    202      * the Bourne shell's functionality.
    203      */
    204 {
    205     "ksh",
    206     TRUE, "set -", "set -v", "set -", 5,
    207     TRUE, "set -e", "set +e",
    208198    "v", "e",
    209199},
     
    239229                                 * nLocal equals maxLocal */
    240230#ifndef RMT_WILL_WATCH
    241 #ifdef USE_KQUEUE
    242 static int      kqfd;           /* File descriptor obtained by kqueue() */
    243 #else
    244231static fd_set   outputs;        /* Set of descriptors of pipes connected to
    245232                                 * the output channels of children */
    246 #endif
    247233#endif
    248234
     
    290276 * really ugly, use dramamine sparingly. You have been warned.
    291277 */
    292 #define W_SETMASKED(st, val, fun)                               \
     278#define W_SETMASKED(st, val, fun)                               \
    293279        {                                                       \
    294280                int sh = (int) ~0;                              \
     
    300286        }
    301287
    302 #define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
    303 #define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
    304 
    305 
    306 static int JobCondPassSig(void *, void *);
    307 static void JobPassSig(int);
    308 static int JobCmpPid(void *, void *);
    309 static int JobPrintCommand(void *, void *);
    310 static int JobSaveCommand(void *, void *);
    311 static void JobClose(Job *);
     288#define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
     289#define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
     290
     291
     292static int JobCondPassSig __P((ClientData, ClientData));
     293static void JobPassSig __P((int));
     294static int JobCmpPid __P((ClientData, ClientData));
     295static int JobPrintCommand __P((ClientData, ClientData));
     296static int JobSaveCommand __P((ClientData, ClientData));
     297static void JobClose __P((Job *));
    312298#ifdef REMOTE
    313 static int JobCmpRmtID(Job *, int);
     299static int JobCmpRmtID __P((Job *, int));
    314300# ifdef RMT_WILL_WATCH
    315 static void JobLocalInput(int, Job *);
     301static void JobLocalInput __P((int, Job *));
    316302# endif
    317303#else
    318 static void JobFinish(Job *, int *);
    319 static void JobExec(Job *, char **);
    320 #endif
    321 static void JobMakeArgv(Job *, char **);
    322 static void JobRestart(Job *);
    323 static int JobStart(GNode *, int, Job *);
    324 static char *JobOutput(Job *, char *, char *, int);
    325 static void JobDoOutput(Job *, Boolean);
    326 static Shell *JobMatchShell(char *);
    327 static void JobInterrupt(int, int);
    328 static void JobRestartJobs(void);
     304static void JobFinish __P((Job *, int *));
     305static void JobExec __P((Job *, char **));
     306#endif
     307static void JobMakeArgv __P((Job *, char **));
     308static void JobRestart __P((Job *));
     309static int JobStart __P((GNode *, int, Job *));
     310static char *JobOutput __P((Job *, char *, char *, int));
     311static void JobDoOutput __P((Job *, Boolean));
     312static Shell *JobMatchShell __P((char *));
     313static void JobInterrupt __P((int, int));
     314static void JobRestartJobs __P((void));
    329315
    330316/*-
     
    343329 */
    344330static int
    345 JobCondPassSig(void *jobp, void *signop)
     331JobCondPassSig(jobp, signop)
     332    ClientData          jobp;       /* Job to biff */
     333    ClientData          signop;     /* Signal to send it */
    346334{
    347335    Job *job = (Job *) jobp;
     
    358346     * job as well.
    359347     */
    360     DEBUGF(JOB, ("JobCondPassSig passing signal %d to child %d.\n", signo, job->pid));
     348    if (DEBUG(JOB)) {
     349        (void) fprintf(stdout,
     350                       "JobCondPassSig passing signal %d to child %d.\n",
     351                       signo, job->pid);
     352        (void) fflush(stdout);
     353    }
    361354    KILL(job->pid, signo);
    362355#endif
     
    379372 */
    380373static void
    381 JobPassSig(int signo)
     374JobPassSig(signo)
     375    int     signo;      /* The signal number we've received */
    382376{
    383377    sigset_t nmask, omask;
    384378    struct sigaction act;
    385379
    386     DEBUGF(JOB, ("JobPassSig(%d) called.\n", signo));
    387     Lst_ForEach(jobs, JobCondPassSig, (void *) &signo);
     380    if (DEBUG(JOB)) {
     381        (void) fprintf(stdout, "JobPassSig(%d) called.\n", signo);
     382        (void) fflush(stdout);
     383    }
     384    Lst_ForEach(jobs, JobCondPassSig, (ClientData) &signo);
    388385
    389386    /*
     
    419416    sigaction(signo, &act, NULL);
    420417
    421     DEBUGF(JOB, ("JobPassSig passing signal to self, mask = %x.\n", ~0 & ~(1 << (signo-1))));
     418    if (DEBUG(JOB)) {
     419        (void) fprintf(stdout,
     420                       "JobPassSig passing signal to self, mask = %x.\n",
     421                       ~0 & ~(1 << (signo-1)));
     422        (void) fflush(stdout);
     423    }
    422424    (void) signal(signo, SIG_DFL);
    423425
     
    425427
    426428    signo = SIGCONT;
    427     Lst_ForEach(jobs, JobCondPassSig, (void *) &signo);
     429    Lst_ForEach(jobs, JobCondPassSig, (ClientData) &signo);
    428430
    429431    (void) sigprocmask(SIG_SETMASK, &omask, NULL);
     
    448450 */
    449451static int
    450 JobCmpPid(void *job, void *pid)
     452JobCmpPid(job, pid)
     453    ClientData        job;      /* job to examine */
     454    ClientData        pid;      /* process id desired */
    451455{
    452456    return *(int *) pid - ((Job *) job)->pid;
     
    468472 */
    469473static int
    470 JobCmpRmtID(void *job, void *rmtID)
     474JobCmpRmtID(job, rmtID)
     475    ClientData      job;        /* job to examine */
     476    ClientData      rmtID;      /* remote id desired */
    471477{
    472478    return(*(int *) rmtID - *(int *) job->rmtID);
     
    487493 *      made and return non-zero to signal that the end of the commands
    488494 *      was reached. These commands are later attached to the postCommands
    489  *      node and executed by Job_Finish when all things are done.
     495 *      node and executed by Job_End when all things are done.
    490496 *      This function is called from JobStart via Lst_ForEach.
    491497 *
     
    502508 */
    503509static int
    504 JobPrintCommand(void *cmdp, void *jobp)
     510JobPrintCommand(cmdp, jobp)
     511    ClientData    cmdp;             /* command string to print */
     512    ClientData    jobp;             /* job for which to print it */
    505513{
    506514    Boolean       noSpecials;       /* true if we shouldn't worry about
     
    525533        if ((job->flags & JOB_IGNDOTS) == 0) {
    526534            job->tailCmds = Lst_Succ(Lst_Member(job->node->commands,
    527                                                 (void *)cmd));
     535                                                (ClientData)cmd));
    528536            return 1;
    529537        }
     
    531539    }
    532540
    533 #define DBPRINTF(fmt, arg)                      \
    534    DEBUGF(JOB, (fmt, arg));                     \
     541#define DBPRINTF(fmt, arg) if (DEBUG(JOB)) {    \
     542        (void) fprintf(stdout, fmt, arg);       \
     543        (void) fflush(stdout);                  \
     544    }                                           \
    535545   (void) fprintf(job->cmdFILE, fmt, arg);      \
    536546   (void) fflush(job->cmdFILE);
     
    542552     * the variables in the command.
    543553     */
    544     cmdNode = Lst_Member(job->node->commands, (void *)cmd);
     554    cmdNode = Lst_Member(job->node->commands, (ClientData)cmd);
    545555    cmdStart = cmd = Var_Subst(NULL, cmd, job->node, FALSE);
    546     Lst_Replace(cmdNode, (void *)cmdStart);
     556    Lst_Replace(cmdNode, (ClientData)cmdStart);
    547557
    548558    cmdTemplate = "%s\n";
     
    659669 */
    660670static int
    661 JobSaveCommand(void *cmd, void *gn)
    662 {
    663     cmd = (void *) Var_Subst(NULL, (char *) cmd, (GNode *) gn, FALSE);
     671JobSaveCommand(cmd, gn)
     672    ClientData   cmd;
     673    ClientData   gn;
     674{
     675    cmd = (ClientData) Var_Subst(NULL, (char *) cmd, (GNode *) gn, FALSE);
    664676    (void) Lst_AtEnd(postCommands->commands, cmd);
    665677    return(0);
     
    681693 */
    682694static void
    683 JobClose(Job *job)
     695JobClose(job)
     696    Job *job;
    684697{
    685698    if (usePipes) {
    686699#ifdef RMT_WILL_WATCH
    687700        Rmt_Ignore(job->inPipe);
    688 #elif !defined(USE_KQUEUE)
     701#else
    689702        FD_CLR(job->inPipe, &outputs);
    690703#endif
     
    725738/*ARGSUSED*/
    726739static void
    727 JobFinish(Job *job, int *status)
     740JobFinish(job, status)
     741    Job         *job;             /* job to finish */
     742    int         *status;          /* sub-why job went away */
    728743{
    729744    Boolean      done;
     
    794809             */
    795810            out = fdopen(job->outFd, "w");
    796             if (out == NULL)
    797                 Punt("Cannot fdopen");
    798811        } else {
    799812            out = stdout;
     
    801814
    802815        if (WIFEXITED(*status)) {
    803             DEBUGF(JOB, ("Process %d exited.\n", job->pid));
     816            if (DEBUG(JOB)) {
     817                (void) fprintf(stdout, "Process %d exited.\n", job->pid);
     818                (void) fflush(stdout);
     819            }
    804820            if (WEXITSTATUS(*status) != 0) {
    805821                if (usePipes && job->node != lastNode) {
     
    822838            }
    823839        } else if (WIFSTOPPED(*status)) {
    824             DEBUGF(JOB, ("Process %d stopped.\n", job->pid));
     840            if (DEBUG(JOB)) {
     841                (void) fprintf(stdout, "Process %d stopped.\n", job->pid);
     842                (void) fflush(stdout);
     843            }
    825844            if (usePipes && job->node != lastNode) {
    826845                MESSAGE(out, job->node);
     
    832851            }
    833852            job->flags |= JOB_RESUME;
    834             (void)Lst_AtEnd(stoppedJobs, (void *)job);
     853            (void)Lst_AtEnd(stoppedJobs, (ClientData)job);
    835854#ifdef REMOTE
    836855            if (job->flags & JOB_REMIGRATE)
     
    853872            }
    854873            if (!(job->flags & JOB_CONTINUING)) {
    855                 DEBUGF(JOB, ("Warning: process %d was not continuing.\n", job->pid));
     874                if (DEBUG(JOB)) {
     875                    (void) fprintf(stdout,
     876                                   "Warning: process %d was not continuing.\n",
     877                                   job->pid);
     878                    (void) fflush(stdout);
     879                }
    856880#ifdef notdef
    857881                /*
     
    865889            }
    866890            job->flags &= ~JOB_CONTINUING;
    867             Lst_AtEnd(jobs, (void *)job);
     891            Lst_AtEnd(jobs, (ClientData)job);
    868892            nJobs += 1;
    869893            if (!(job->flags & JOB_REMOTE)) {
    870                 DEBUGF(JOB, ("Process %d is continuing locally.\n", job->pid));
     894                if (DEBUG(JOB)) {
     895                    (void) fprintf(stdout,
     896                                   "Process %d is continuing locally.\n",
     897                                   job->pid);
     898                    (void) fflush(stdout);
     899                }
    871900                nLocal += 1;
    872901            }
    873902            if (nJobs == maxJobs) {
    874903                jobFull = TRUE;
    875                 DEBUGF(JOB, ("Job queue is full.\n"));
     904                if (DEBUG(JOB)) {
     905                    (void) fprintf(stdout, "Job queue is full.\n");
     906                    (void) fflush(stdout);
     907                }
    876908            }
    877909            (void) fflush(out);
     
    913945            done = FALSE;
    914946            break;
    915         default:
    916             break;
    917947        }
    918948    } else {
     
    932962         * on the .END target.
    933963         */
    934         if (job->tailCmds != NULL) {
     964        if (job->tailCmds != NILLNODE) {
    935965            Lst_ForEachFrom(job->node->commands, job->tailCmds,
    936966                             JobSaveCommand,
    937                             (void *)job->node);
     967                            (ClientData)job->node);
    938968        }
    939969        job->node->made = MADE;
    940970        Make_Update(job->node);
    941         free(job);
     971        free((Address)job);
    942972    } else if (*status != 0) {
    943973        errors += 1;
    944         free(job);
     974        free((Address)job);
    945975    }
    946976
     
    9701000 * Job_Touch --
    9711001 *      Touch the given target. Called by JobStart when the -t flag was
    972  *      given.  Prints messages unless told to be silent.
     1002 *      given
    9731003 *
    9741004 * Results:
     
    9811011 */
    9821012void
    983 Job_Touch(GNode *gn, Boolean silent)
     1013Job_Touch(gn, silent)
     1014    GNode         *gn;          /* the node of the file to touch */
     1015    Boolean       silent;       /* TRUE if should not print messages */
    9841016{
    9851017    int           streamID;     /* ID of stream opened to do the touch */
     
    10221054                 */
    10231055                if (read(streamID, &c, 1) == 1) {
    1024                     (void) lseek(streamID, (off_t)0, SEEK_SET);
     1056                    (void) lseek(streamID, 0L, SEEK_SET);
    10251057                    (void) write(streamID, &c, 1);
    10261058                }
     
    10501082 */
    10511083Boolean
    1052 Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
     1084Job_CheckCommands(gn, abortProc)
     1085    GNode          *gn;             /* The target whose commands need
     1086                                     * verifying */
     1087    void         (*abortProc) __P((char *, ...));
     1088                        /* Function to abort with message */
    10531089{
    10541090    if (OP_NOP(gn->type) && Lst_IsEmpty(gn->commands) &&
     
    10581094         * commands
    10591095         */
    1060         if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands)) {
     1096        if ((DEFAULT != NILGNODE) && !Lst_IsEmpty(DEFAULT->commands)) {
    10611097            char *p1;
    10621098            /*
     
    11181154/*ARGSUSED*/
    11191155static void
    1120 JobLocalInput(int stream, Job *job)
     1156JobLocalInput(stream, job)
     1157    int     stream;     /* Stream that's ready (ignored) */
     1158    Job     *job;       /* Job to which the stream belongs */
    11211159{
    11221160    JobDoOutput(job, FALSE);
     
    11401178 */
    11411179static void
    1142 JobExec(Job *job, char **argv)
     1180JobExec(job, argv)
     1181    Job           *job;         /* Job to execute */
     1182    char          **argv;
    11431183{
    11441184    int           cpid;         /* ID of new child */
     
    11471187        int       i;
    11481188
    1149         DEBUGF(JOB, ("Running %s %sly\n", job->node->name,
    1150                job->flags&JOB_REMOTE?"remote":"local"));
    1151         DEBUGF(JOB, ("\tCommand: "));
     1189        (void) fprintf(stdout, "Running %s %sly\n", job->node->name,
     1190                       job->flags&JOB_REMOTE?"remote":"local");
     1191        (void) fprintf(stdout, "\tCommand: ");
    11521192        for (i = 0; argv[i] != NULL; i++) {
    1153             DEBUGF(JOB, ("%s ", argv[i]));
    1154         }
    1155         DEBUGF(JOB, ("\n"));
     1193            (void) fprintf(stdout, "%s ", argv[i]);
     1194        }
     1195        (void) fprintf(stdout, "\n");
     1196        (void) fflush(stdout);
    11561197    }
    11571198
     
    11861227            Punt("Cannot dup2: %s", strerror(errno));
    11871228        (void) fcntl(0, F_SETFD, 0);
    1188         (void) lseek(0, (off_t)0, SEEK_SET);
     1229        (void) lseek(0, 0, SEEK_SET);
    11891230
    11901231        if (usePipes) {
     
    12341275           (void) execv(shellPath, argv);
    12351276
    1236         (void) write(STDERR_FILENO, "Could not execute shell\n",
     1277        (void) write(2, "Could not execute shell\n",
    12371278                     sizeof("Could not execute shell"));
    12381279        _exit(1);
     
    12491290             * stream to watch in the outputs mask
    12501291             */
    1251 #ifdef USE_KQUEUE
    1252             struct kevent       kev[2];
    1253 #endif
    12541292            job->curPos = 0;
    12551293
    12561294#ifdef RMT_WILL_WATCH
    12571295            Rmt_Watch(job->inPipe, JobLocalInput, job);
    1258 #elif defined(USE_KQUEUE)
    1259             EV_SET(&kev[0], job->inPipe, EVFILT_READ, EV_ADD, 0, 0, job);
    1260             EV_SET(&kev[1], job->pid, EVFILT_PROC, EV_ADD | EV_ONESHOT,
    1261                 NOTE_EXIT, 0, NULL);
    1262             if (kevent(kqfd, kev, 2, NULL, 0, NULL) != 0) {
    1263                 /* kevent() will fail if the job is already finished */
    1264                 if (errno != EBADF && errno != ESRCH)
    1265                     Punt("kevent: %s", strerror(errno));
    1266             }
    12671296#else
    12681297            FD_SET(job->inPipe, &outputs);
     
    12981327     */
    12991328    nJobs += 1;
    1300     (void) Lst_AtEnd(jobs, (void *)job);
     1329    (void) Lst_AtEnd(jobs, (ClientData)job);
    13011330    if (nJobs == maxJobs) {
    13021331        jobFull = TRUE;
     
    13171346 */
    13181347static void
    1319 JobMakeArgv(Job *job, char **argv)
     1348JobMakeArgv(job, argv)
     1349    Job           *job;
     1350    char          **argv;
    13201351{
    13211352    int           argc;
     
    13711402 */
    13721403static void
    1373 JobRestart(Job *job)
     1404JobRestart(job)
     1405    Job           *job;         /* Job to restart */
    13741406{
    13751407#ifdef REMOTE
     
    14301462                   (void) fflush(stdout);
    14311463                }
    1432                 (void)Lst_AtFront(stoppedJobs, (void *)job);
     1464                (void)Lst_AtFront(stoppedJobs, (ClientData)job);
    14331465                jobFull = TRUE;
    1434                 DEBUGF(JOB, ("Job queue is full.\n"));
     1466                if (DEBUG(JOB)) {
     1467                   (void) fprintf(stdout, "Job queue is full.\n");
     1468                   (void) fflush(stdout);
     1469                }
    14351470                return;
    14361471            }
     
    14481483#endif
    14491484
    1450         (void)Lst_AtEnd(jobs, (void *)job);
     1485        (void)Lst_AtEnd(jobs, (ClientData)job);
    14511486        nJobs += 1;
    14521487        if (nJobs == maxJobs) {
    14531488            jobFull = TRUE;
    1454             DEBUGF(JOB, ("Job queue is full.\n"));
     1489            if (DEBUG(JOB)) {
     1490                (void) fprintf(stdout, "Job queue is full.\n");
     1491                (void) fflush(stdout);
     1492            }
    14551493        }
    14561494    } else if (job->flags & JOB_RESTART) {
     
    14671505        JobMakeArgv(job, argv);
    14681506
    1469         DEBUGF(JOB, ("Restarting %s...", job->node->name));
     1507        if (DEBUG(JOB)) {
     1508            (void) fprintf(stdout, "Restarting %s...", job->node->name);
     1509            (void) fflush(stdout);
     1510        }
    14701511#ifdef REMOTE
    14711512        if ((job->node->type&OP_NOEXPORT) ||
     
    14831524                 * back on the hold queue and mark the table full
    14841525                 */
    1485                 DEBUGF(JOB, ("holding\n"));
    1486                 (void)Lst_AtFront(stoppedJobs, (void *)job);
     1526                if (DEBUG(JOB)) {
     1527                    (void) fprintf(stdout, "holding\n");
     1528                    (void) fflush(stdout);
     1529                }
     1530                (void)Lst_AtFront(stoppedJobs, (ClientData)job);
    14871531                jobFull = TRUE;
    1488                 DEBUGF(JOB, ("Job queue is full.\n"));
     1532                if (DEBUG(JOB)) {
     1533                    (void) fprintf(stdout, "Job queue is full.\n");
     1534                    (void) fflush(stdout);
     1535                }
    14891536                return;
    14901537            } else {
     
    14921539                 * Job may be run locally.
    14931540                 */
    1494                 DEBUGF(JOB, ("running locally\n"));
     1541                if (DEBUG(JOB)) {
     1542                    (void) fprintf(stdout, "running locally\n");
     1543                    (void) fflush(stdout);
     1544                }
    14951545                job->flags &= ~JOB_REMOTE;
    14961546            }
     
    15011551             * Can be exported. Hooray!
    15021552             */
    1503             DEBUGF(JOB, ("exporting\n"));
     1553            if (DEBUG(JOB)) {
     1554                (void) fprintf(stdout, "exporting\n");
     1555                (void) fflush(stdout);
     1556            }
    15041557            job->flags |= JOB_REMOTE;
    15051558        }
     
    15111564         * we don't know...
    15121565         */
    1513         DEBUGF(JOB, ("Resuming %s...", job->node->name));
     1566        if (DEBUG(JOB)) {
     1567           (void) fprintf(stdout, "Resuming %s...", job->node->name);
     1568           (void) fflush(stdout);
     1569        }
    15141570        if (((job->flags & JOB_REMOTE) ||
    15151571            (nLocal < maxLocal) ||
     
    15511607
    15521608                job->flags &= ~(JOB_RESUME|JOB_CONTINUING);
    1553                 DEBUGF(JOB, ("done\n"));
     1609                if (DEBUG(JOB)) {
     1610                   (void) fprintf(stdout, "done\n");
     1611                   (void) fflush(stdout);
     1612                }
    15541613            } else {
    15551614                Error("couldn't resume %s: %s",
     
    15641623             * place the job back on the list of stopped jobs.
    15651624             */
    1566             DEBUGF(JOB, ("table full\n"));
    1567             (void) Lst_AtFront(stoppedJobs, (void *)job);
     1625            if (DEBUG(JOB)) {
     1626                (void) fprintf(stdout, "table full\n");
     1627                (void) fflush(stdout);
     1628            }
     1629            (void) Lst_AtFront(stoppedJobs, (ClientData)job);
    15681630            jobFull = TRUE;
    1569             DEBUGF(JOB, ("Job queue is full.\n"));
     1631            if (DEBUG(JOB)) {
     1632                (void) fprintf(stdout, "Job queue is full.\n");
     1633                (void) fflush(stdout);
     1634            }
    15701635        }
    15711636    }
     
    15891654 */
    15901655static int
    1591 JobStart(GNode *gn, int flags, Job *previous)
    1592 {
    1593     Job           *job;       /* new job descriptor */
     1656JobStart(gn, flags, previous)
     1657    GNode         *gn;        /* target to create */
     1658    int            flags;      /* flags for the job to override normal ones.
     1659                               * e.g. JOB_SPECIAL or JOB_IGNDOTS */
     1660    Job           *previous;  /* The previous Job structure for this node,
     1661                               * if any. */
     1662{
     1663    register Job  *job;       /* new job descriptor */
    15941664    char          *argv[4];   /* Argument vector to shell */
    15951665    Boolean       cmdsOK;     /* true if the nodes commands were all right */
     
    16031673    } else {
    16041674        job = (Job *) emalloc(sizeof(Job));
     1675        if (job == NULL) {
     1676            Punt("JobStart out of memory");
     1677        }
    16051678        flags |= JOB_FIRST;
    16061679    }
    16071680
    16081681    job->node = gn;
    1609     job->tailCmds = NULL;
     1682    job->tailCmds = NILLNODE;
    16101683
    16111684    /*
     
    16821755                LstNode ln = Lst_Next(gn->commands);
    16831756
    1684                 if ((ln == NULL) ||
    1685                     JobPrintCommand((void *) Lst_Datum(ln),
    1686                                     (void *) job))
     1757                if ((ln == NILLNODE) ||
     1758                    JobPrintCommand((ClientData) Lst_Datum(ln),
     1759                                    (ClientData) job))
    16871760                {
    16881761                    noExec = TRUE;
     
    17091782             */
    17101783            numCommands = 0;
    1711             Lst_ForEach(gn->commands, JobPrintCommand, (void *)job);
     1784            Lst_ForEach(gn->commands, JobPrintCommand, (ClientData)job);
    17121785
    17131786            /*
     
    17351808         */
    17361809        if (cmdsOK) {
    1737             Lst_ForEach(gn->commands, JobPrintCommand, (void *)job);
     1810            Lst_ForEach(gn->commands, JobPrintCommand, (ClientData)job);
    17381811        }
    17391812        /*
     
    17731846        if (cmdsOK) {
    17741847            if (aborting == 0) {
    1775                 if (job->tailCmds != NULL) {
     1848                if (job->tailCmds != NILLNODE) {
    17761849                    Lst_ForEachFrom(job->node->commands, job->tailCmds,
    17771850                                    JobSaveCommand,
    1778                                    (void *)job->node);
     1851                                   (ClientData)job->node);
    17791852                }
    17801853                job->node->made = MADE;
    17811854                Make_Update(job->node);
    17821855            }
    1783             free(job);
     1856            free((Address)job);
    17841857            return(JOB_FINISHED);
    17851858        } else {
    1786             free(job);
     1859            free((Address)job);
    17871860            return(JOB_ERROR);
    17881861        }
     
    18551928        jobFull = TRUE;
    18561929
    1857         DEBUGF(JOB, ("Can only run job locally.\n"));
     1930        if (DEBUG(JOB)) {
     1931           (void) fprintf(stdout, "Can only run job locally.\n");
     1932           (void) fflush(stdout);
     1933        }
    18581934        job->flags |= JOB_RESTART;
    1859         (void) Lst_AtEnd(stoppedJobs, (void *)job);
     1935        (void) Lst_AtEnd(stoppedJobs, (ClientData)job);
    18601936    } else {
    18611937        if ((nLocal >= maxLocal) && local) {
     
    18651941             */
    18661942            jobFull = TRUE;
    1867             DEBUGF(JOB, ("Local job queue is full.\n"));
     1943            if (DEBUG(JOB)) {
     1944                (void) fprintf(stdout, "Local job queue is full.\n");
     1945                (void) fflush(stdout);
     1946            }
    18681947        }
    18691948        JobExec(job, argv);
     
    18731952
    18741953static char *
    1875 JobOutput(Job *job, char *cp, char *endp, int msg)
    1876 {
    1877     char *ecp;
     1954JobOutput(job, cp, endp, msg)
     1955    register Job *job;
     1956    register char *cp, *endp;
     1957    int msg;
     1958{
     1959    register char *ecp;
    18781960
    18791961    if (commandShell->noPrint) {
     
    19432025 */
    19442026STATIC void
    1945 JobDoOutput(Job *job, Boolean finish)
     2027JobDoOutput(job, finish)
     2028    register Job   *job;          /* the job whose output needs printing */
     2029    Boolean        finish;        /* TRUE if this is the last time we'll be
     2030                                   * called for this job */
    19462031{
    19472032    Boolean       gotNL = FALSE;  /* true if got a newline */
    19482033    Boolean       fbuf;           /* true if our buffer filled up */
    1949     int           nr;             /* number of bytes read */
    1950     int           i;              /* auxiliary index into outBuf */
    1951     int           max;            /* limit for i (end of current data) */
     2034    register int  nr;             /* number of bytes read */
     2035    register int  i;              /* auxiliary index into outBuf */
     2036    register int  max;            /* limit for i (end of current data) */
    19522037    int           nRead;          /* (Temporary) number of bytes read */
    19532038
     
    19672052                         JOB_BUFSIZE - job->curPos);
    19682053        if (nRead < 0) {
    1969             DEBUGF(JOB, ("JobDoOutput(piperead)"));
     2054            if (DEBUG(JOB)) {
     2055                perror("JobDoOutput(piperead)");
     2056            }
    19702057            nr = 0;
    19712058        } else {
     
    20212108             * first, overwriting the newline character if there was one.
    20222109             * So long as the line isn't one we should filter (according
    2023              * to the shell description), we print the line, preceded
     2110             * to the shell description), we print the line, preceeded
    20242111             * by a target banner if this target isn't the same as the
    20252112             * one for which we last printed something.
     
    20872174            (void) fflush(stdout);
    20882175            while (fgets(inLine, sizeof(inLine), oFILE) != NULL) {
    2089                 char    *cp, *endp, *oendp;
     2176                register char   *cp, *endp, *oendp;
    20902177
    20912178                cp = inLine;
     
    21342221 */
    21352222void
    2136 Job_CatchChildren(Boolean block)
     2223Job_CatchChildren(block)
     2224    Boolean       block;        /* TRUE if should block on the wait. */
    21372225{
    21382226    int           pid;          /* pid of dead child */
    2139     Job           *job;         /* job descriptor for dead child */
     2227    register Job  *job;         /* job descriptor for dead child */
    21402228    LstNode       jnode;        /* list element for finding job */
    21412229    int           status;       /* Exit/termination status */
     
    21512239                          (block?0:WNOHANG)|WUNTRACED)) > 0)
    21522240    {
    2153         DEBUGF(JOB, ("Process %d exited or stopped.\n", pid));
    2154 
    2155         jnode = Lst_Find(jobs, (void *)&pid, JobCmpPid);
    2156 
    2157         if (jnode == NULL) {
     2241        if (DEBUG(JOB)) {
     2242            (void) fprintf(stdout, "Process %d exited or stopped.\n", pid);
     2243            (void) fflush(stdout);
     2244        }
     2245
     2246
     2247        jnode = Lst_Find(jobs, (ClientData)&pid, JobCmpPid);
     2248
     2249        if (jnode == NILLNODE) {
    21582250            if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGCONT)) {
    2159                 jnode = Lst_Find(stoppedJobs, (void *) &pid, JobCmpPid);
    2160                 if (jnode == NULL) {
     2251                jnode = Lst_Find(stoppedJobs, (ClientData) &pid, JobCmpPid);
     2252                if (jnode == NILLNODE) {
    21612253                    Error("Resumed child (%d) not in table", pid);
    21622254                    continue;
     
    21722264            (void) Lst_Remove(jobs, jnode);
    21732265            nJobs -= 1;
    2174             DEBUGF(JOB, ("Job queue is no longer full.\n"));
     2266            if (jobFull && DEBUG(JOB)) {
     2267                (void) fprintf(stdout, "Job queue is no longer full.\n");
     2268                (void) fflush(stdout);
     2269            }
    21752270            jobFull = FALSE;
    21762271#ifdef REMOTE
    21772272            if (!(job->flags & JOB_REMOTE)) {
    2178                 DEBUGF(JOB, ("Job queue has one fewer local process.\n"));
     2273                if (DEBUG(JOB)) {
     2274                    (void) fprintf(stdout,
     2275                                   "Job queue has one fewer local process.\n");
     2276                    (void) fflush(stdout);
     2277                }
    21792278                nLocal -= 1;
    21802279            }
     
    22052304 */
    22062305void
    2207 Job_CatchOutput(void)
     2306Job_CatchOutput()
    22082307{
    22092308    int                   nfds;
    2210 #ifdef USE_KQUEUE
    2211 #define KEV_SIZE        4
    2212     struct kevent         kev[KEV_SIZE];
    2213     int                   i;
    2214 #else
    22152309    struct timeval        timeout;
    22162310    fd_set                readfds;
    2217     LstNode               ln;
    2218     Job                   *job;
    2219 #endif
     2311    register LstNode      ln;
     2312    register Job          *job;
    22202313#ifdef RMT_WILL_WATCH
    22212314    int                   pnJobs;       /* Previous nJobs */
     
    22472340#else
    22482341    if (usePipes) {
    2249 #ifdef USE_KQUEUE
    2250         if ((nfds = kevent(kqfd, NULL, 0, kev, KEV_SIZE, NULL)) == -1) {
    2251             Punt("kevent: %s", strerror(errno));
    2252         } else {
    2253             for (i = 0; i < nfds; i++) {
    2254                 if (kev[i].flags & EV_ERROR) {
    2255                     warnc(kev[i].data, "kevent");
    2256                     continue;
    2257                 }
    2258                 switch (kev[i].filter) {
    2259                 case EVFILT_READ:
    2260                     JobDoOutput(kev[i].udata, FALSE);
    2261                     break;
    2262                 case EVFILT_PROC:
    2263                     /* Just wake up and let Job_CatchChildren() collect the
    2264                      * terminated job. */
    2265                     break;
    2266                 }
    2267             }
    2268         }
    2269 #else
    22702342        readfds = outputs;
    22712343        timeout.tv_sec = SEL_SEC;
     
    22792351                Punt("Cannot open job table");
    22802352            }
    2281             while (nfds && (ln = Lst_Next(jobs)) != NULL) {
     2353            while (nfds && (ln = Lst_Next(jobs)) != NILLNODE) {
    22822354                job = (Job *) Lst_Datum(ln);
    22832355                if (FD_ISSET(job->inPipe, &readfds)) {
     
    22882360            Lst_Close(jobs);
    22892361        }
    2290 #endif /* !USE_KQUEUE */
    22912362    }
    22922363#endif /* RMT_WILL_WATCH */
     
    23082379 */
    23092380void
    2310 Job_Make(GNode *gn)
     2381Job_Make(gn)
     2382    GNode   *gn;
    23112383{
    23122384    (void) JobStart(gn, 0, NULL);
     
    23162388 *-----------------------------------------------------------------------
    23172389 * Job_Init --
    2318  *      Initialize the process module, given a maximum number of jobs, and
    2319  *      a maximum number of local jobs.
     2390 *      Initialize the process module
    23202391 *
    23212392 * Results:
     
    23272398 */
    23282399void
    2329 Job_Init(int maxproc, int maxlocal)
     2400Job_Init(maxproc, maxlocal)
     2401    int           maxproc;  /* the greatest number of jobs which may be
     2402                             * running at one time */
     2403    int           maxlocal; /* the greatest number of local jobs which may
     2404                             * be running at once. */
    23302405{
    23312406    GNode         *begin;     /* node for commands to do at the very start */
     
    23422417    errors =      0;
    23432418
    2344     lastNode =    NULL;
     2419    lastNode =    NILGNODE;
    23452420
    23462421    if (maxJobs == 1 || beVerbose == 0
     
    24142489#endif
    24152490
    2416 #ifdef USE_KQUEUE
    2417     if ((kqfd = kqueue()) == -1) {
    2418         Punt("kqueue: %s", strerror(errno));
    2419     }
    2420 #endif
    2421 
    24222491    begin = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    24232492
    2424     if (begin != NULL) {
     2493    if (begin != NILGNODE) {
    24252494        JobStart(begin, JOB_SPECIAL, (Job *)0);
    24262495        while (nJobs) {
     
    24492518 */
    24502519Boolean
    2451 Job_Full(void)
     2520Job_Full()
    24522521{
    24532522    return(aborting || jobFull);
     
    24712540 */
    24722541Boolean
    2473 Job_Empty(void)
     2542Job_Empty()
    24742543{
    24752544    if (nJobs == 0) {
     
    25042573 */
    25052574static Shell *
    2506 JobMatchShell(char *name)
    2507 {
    2508     Shell         *sh;        /* Pointer into shells table */
    2509     Shell         *match;     /* Longest-matching shell */
    2510     char          *cp1,
     2575JobMatchShell(name)
     2576    char          *name;      /* Final component of shell path */
     2577{
     2578    register Shell *sh;       /* Pointer into shells table */
     2579    Shell          *match;    /* Longest-matching shell */
     2580    register char *cp1,
    25112581                  *cp2;
    25122582    char          *eoname;
     
    25752645 */
    25762646ReturnStatus
    2577 Job_ParseShell(char *line)
     2647Job_ParseShell(line)
     2648    char          *line;  /* The shell spec */
    25782649{
    25792650    char          **words;
    25802651    int           wordCount;
    2581     char          **argv;
    2582     int           argc;
     2652    register char **argv;
     2653    register int  argc;
    25832654    char          *path;
    25842655    Shell         newShell;
    25852656    Boolean       fullSpec = FALSE;
    25862657
    2587     while (isspace((unsigned char) *line)) {
     2658    while (isspace(*line)) {
    25882659        line++;
    25892660    }
    25902661    words = brk_string(line, &wordCount, TRUE);
    25912662
    2592     memset(&newShell, 0, sizeof(newShell));
     2663    memset((Address)&newShell, 0, sizeof(newShell));
    25932664
    25942665    /*
     
    26862757    }
    26872758
     2759    /*
     2760     * Do not free up the words themselves, since they might be in use by the
     2761     * shell specification...
     2762     */
     2763    free(words);
    26882764    return SUCCESS;
    26892765}
     
    27032779 */
    27042780static void
    2705 JobInterrupt(int runINTERRUPT, int signo)
     2781JobInterrupt(runINTERRUPT, signo)
     2782    int     runINTERRUPT;       /* Non-zero if commands for the .INTERRUPT
     2783                                 * target should be executed */
     2784    int     signo;              /* signal received */
    27062785{
    27072786    LstNode       ln;           /* element in job table */
     
    27112790    aborting = ABORT_INTERRUPT;
    27122791
    2713     (void) Lst_Open(jobs);
    2714     while ((ln = Lst_Next(jobs)) != NULL) {
     2792   (void) Lst_Open(jobs);
     2793    while ((ln = Lst_Next(jobs)) != NILLNODE) {
    27152794        job = (Job *) Lst_Datum(ln);
    27162795
     
    27442823#else
    27452824        if (job->pid) {
    2746             DEBUGF(JOB, ("JobInterrupt passing signal to child %d.\n",
    2747                    job->pid));
     2825            if (DEBUG(JOB)) {
     2826                (void) fprintf(stdout,
     2827                               "JobInterrupt passing signal to child %d.\n",
     2828                               job->pid);
     2829                (void) fflush(stdout);
     2830            }
    27482831            KILL(job->pid, signo);
    27492832        }
     
    27522835
    27532836#ifdef REMOTE
    2754     (void)Lst_Open(stoppedJobs);
    2755     while ((ln = Lst_Next(stoppedJobs)) != NULL) {
     2837   (void)Lst_Open(stoppedJobs);
     2838    while ((ln = Lst_Next(stoppedJobs)) != NILLNODE) {
    27562839        job = (Job *) Lst_Datum(ln);
    27572840
    27582841        if (job->flags & JOB_RESTART) {
    2759             DEBUGF(JOB, "JobInterrupt skipping job on stopped queue"
    2760                    "-- it was waiting to be restarted.\n");
     2842            if (DEBUG(JOB)) {
     2843                (void) fprintf(stdout, "%s%s",
     2844                               "JobInterrupt skipping job on stopped queue",
     2845                               "-- it was waiting to be restarted.\n");
     2846                (void) fflush(stdout);
     2847            }
    27612848            continue;
    27622849        }
     
    27722859         * Resume the thing so it will take the signal.
    27732860         */
    2774         DEBUGF(JOB, ("JobInterrupt passing CONT to stopped child %d.\n", job->pid));
     2861        if (DEBUG(JOB)) {
     2862            (void) fprintf(stdout,
     2863                           "JobInterrupt passing CONT to stopped child %d.\n",
     2864                           job->pid);
     2865            (void) fflush(stdout);
     2866        }
    27752867        KILL(job->pid, SIGCONT);
    27762868#ifdef RMT_WANTS_SIGNALS
     
    27902882            }
    27912883        } else if (job->pid) {
    2792             DEBUGF(JOB, "JobInterrupt passing interrupt to stopped child %d.\n",
    2793                    job->pid);
     2884            if (DEBUG(JOB)) {
     2885                (void) fprintf(stdout,
     2886                       "JobInterrupt passing interrupt to stopped child %d.\n",
     2887                               job->pid);
     2888                (void) fflush(stdout);
     2889            }
    27942890            KILL(job->pid, SIGINT);
    27952891        }
     
    28012897    if (runINTERRUPT && !touchFlag) {
    28022898        interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
    2803         if (interrupt != NULL) {
     2899        if (interrupt != NILGNODE) {
    28042900            ignoreErrors = FALSE;
    28052901
     
    28172913/*
    28182914 *-----------------------------------------------------------------------
    2819  * Job_Finish --
     2915 * Job_End --
    28202916 *      Do final processing such as the running of the commands
    28212917 *      attached to the .END target.
     
    28262922 */
    28272923int
    2828 Job_Finish(void)
    2829 {
    2830     if (postCommands != NULL && !Lst_IsEmpty(postCommands->commands)) {
     2924Job_End()
     2925{
     2926    if (postCommands != NILGNODE && !Lst_IsEmpty(postCommands->commands)) {
    28312927        if (errors) {
    28322928            Error("Errors reported so .END ignored");
     
    28602956 */
    28612957void
    2862 Job_Wait(void)
     2958Job_Wait()
    28632959{
    28642960    aborting = ABORT_WAIT;
     
    28872983 */
    28882984void
    2889 Job_AbortAll(void)
     2985Job_AbortAll()
    28902986{
    28912987    LstNode             ln;     /* element in job table */
     
    28982994
    28992995        (void) Lst_Open(jobs);
    2900         while ((ln = Lst_Next(jobs)) != NULL) {
     2996        while ((ln = Lst_Next(jobs)) != NILLNODE) {
    29012997            job = (Job *) Lst_Datum(ln);
    29022998
     
    29323028 * JobFlagForMigration --
    29333029 *      Handle the eviction of a child. Called from RmtStatusChange.
    2934  *      Flags the child as remigratable and then suspends it.  Takes
    2935  *      the ID of the host we used, for matching children.
     3030 *      Flags the child as remigratable and then suspends it.
    29363031 *
    29373032 * Results:
     
    29443039 */
    29453040void
    2946 JobFlagForMigration(int hostID)
    2947 {
    2948     Job           *job;         /* job descriptor for dead child */
     3041JobFlagForMigration(hostID)
     3042    int           hostID;       /* ID of host we used, for matching children. */
     3043{
     3044    register Job  *job;         /* job descriptor for dead child */
    29493045    LstNode       jnode;        /* list element for finding job */
    29503046
    2951     DEBUGF(JOB, ("JobFlagForMigration(%d) called.\n", hostID));
    2952     jnode = Lst_Find(jobs, (void *)hostID, JobCmpRmtID);
    2953 
    2954     if (jnode == NULL) {
    2955         jnode = Lst_Find(stoppedJobs, (void *)hostID, JobCmpRmtID);
    2956                 if (jnode == NULL) {
     3047    if (DEBUG(JOB)) {
     3048        (void) fprintf(stdout, "JobFlagForMigration(%d) called.\n", hostID);
     3049        (void) fflush(stdout);
     3050    }
     3051    jnode = Lst_Find(jobs, (ClientData)hostID, JobCmpRmtID);
     3052
     3053    if (jnode == NILLNODE) {
     3054        jnode = Lst_Find(stoppedJobs, (ClientData)hostID, JobCmpRmtID);
     3055                if (jnode == NILLNODE) {
    29573056                    if (DEBUG(JOB)) {
    29583057                        Error("Evicting host(%d) not in table", hostID);
     
    29633062    job = (Job *) Lst_Datum(jnode);
    29643063
    2965     DEBUGF(JOB, ("JobFlagForMigration(%d) found job '%s'.\n", hostID, job->node->name));
     3064    if (DEBUG(JOB)) {
     3065        (void) fprintf(stdout,
     3066                       "JobFlagForMigration(%d) found job '%s'.\n", hostID,
     3067                       job->node->name);
     3068        (void) fflush(stdout);
     3069    }
    29663070
    29673071    KILL(job->pid, SIGSTOP);
     
    29893093 */
    29903094static void
    2991 JobRestartJobs(void)
     3095JobRestartJobs()
    29923096{
    29933097    while (!jobFull && !Lst_IsEmpty(stoppedJobs)) {
    2994         DEBUGF(JOB, ("Job queue is not full. Restarting a stopped job.\n"));
     3098        if (DEBUG(JOB)) {
     3099            (void) fprintf(stdout,
     3100                       "Job queue is not full. Restarting a stopped job.\n");
     3101            (void) fflush(stdout);
     3102        }
    29953103        JobRestart((Job *)Lst_DeQueue(stoppedJobs));
    29963104    }
Note: See TracChangeset for help on using the changeset viewer.