Annotation of src/usr.bin/make/compat.c, Revision 1.46
1.36 espie 1: /* $OpenPackages$ */
1.46 ! millert 2: /* $OpenBSD: compat.c,v 1.45 2001/12/02 00:13:16 espie Exp $ */
1.8 millert 3: /* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */
1.1 deraadt 4:
5: /*
6: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
7: * Copyright (c) 1988, 1989 by Adam de Boor
8: * Copyright (c) 1989 by Berkeley Softworks
9: * All rights reserved.
10: *
11: * This code is derived from software contributed to Berkeley by
12: * Adam de Boor.
13: *
14: * Redistribution and use in source and binary forms, with or without
15: * modification, are permitted provided that the following conditions
16: * are met:
17: * 1. Redistributions of source code must retain the above copyright
18: * notice, this list of conditions and the following disclaimer.
19: * 2. Redistributions in binary form must reproduce the above copyright
20: * notice, this list of conditions and the following disclaimer in the
21: * documentation and/or other materials provided with the distribution.
22: * 3. All advertising materials mentioning features or use of this software
23: * must display the following acknowledgement:
24: * This product includes software developed by the University of
25: * California, Berkeley and its contributors.
26: * 4. Neither the name of the University nor the names of its contributors
27: * may be used to endorse or promote products derived from this software
28: * without specific prior written permission.
29: *
30: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40: * SUCH DAMAGE.
41: */
42:
1.37 espie 43: #include <sys/types.h>
44: #include <sys/stat.h>
45: #include <sys/wait.h>
46: #include <ctype.h>
47: #include <errno.h>
1.39 espie 48: #include <limits.h>
1.37 espie 49: #include <signal.h>
50: #include <stddef.h>
51: #include <stdio.h>
1.39 espie 52: #include <stdlib.h>
1.38 espie 53: #include <string.h>
1.37 espie 54: #include <unistd.h>
55: #include "config.h"
56: #include "defines.h"
57: #include "dir.h"
58: #include "job.h"
59: #include "compat.h"
60: #include "suff.h"
61: #include "var.h"
62: #include "targ.h"
63: #include "error.h"
64: #include "str.h"
65: #include "extern.h"
66: #include "memory.h"
67: #include "gnode.h"
68: #include "make.h"
69: #include "timestamp.h"
70: #include "lst.h"
71: #include "pathnames.h"
1.1 deraadt 72:
1.36 espie 73: /* The following array is used to make a fast determination of which
1.1 deraadt 74: * characters are interpreted specially by the shell. If a command
75: * contains any of these characters, it is executed by the shell, not
1.36 espie 76: * directly by us. */
1.1 deraadt 77:
1.36 espie 78: static char meta[256];
1.1 deraadt 79:
80: static GNode *ENDNode;
1.36 espie 81: static void CompatInterrupt(int);
82: static int CompatRunCommand(void *, void *);
83: static void CompatMake(void *, void *);
84: static int shellneed(char **);
1.1 deraadt 85:
1.45 espie 86: static volatile sig_atomic_t interrupted;
87:
88: static void
1.36 espie 89: CompatInterrupt(signo)
1.45 espie 90: int signo;
1.1 deraadt 91: {
1.45 espie 92: if (interrupted != SIGINT)
93: interrupted = signo;
1.1 deraadt 94: }
1.36 espie 95:
1.1 deraadt 96: /*-
97: *-----------------------------------------------------------------------
1.10 deraadt 98: * shellneed --
1.36 espie 99: *
1.10 deraadt 100: * Results:
1.36 espie 101: * Returns 1 if a specified set of arguments
102: * must be executed by the shell,
1.12 espie 103: * 0 if it can be run via execve, and -1 if the command can be
1.36 espie 104: * handled internally
1.10 deraadt 105: *
106: * Side Effects:
1.12 espie 107: * May modify the process umask
1.10 deraadt 108: *-----------------------------------------------------------------------
109: */
110: static int
1.36 espie 111: shellneed(av)
1.12 espie 112: char **av;
1.10 deraadt 113: {
1.36 espie 114: char *runsh[] = {
1.11 deraadt 115: "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit",
1.36 espie 116: "unalias", "unset", "wait",
1.11 deraadt 117: NULL
118: };
119:
1.12 espie 120: char **p;
1.11 deraadt 121:
1.12 espie 122: /* FIXME most of these ARE actual no-ops */
1.11 deraadt 123: for (p = runsh; *p; p++)
1.12 espie 124: if (strcmp(av[0], *p) == 0)
1.36 espie 125: return 1;
1.11 deraadt 126:
1.12 espie 127: if (strcmp(av[0], "umask") == 0) {
1.10 deraadt 128: long umi;
129: char *ep = NULL;
130: mode_t um;
131:
1.12 espie 132: if (av[1] != NULL) {
133: umi = strtol(av[1], &ep, 8);
1.10 deraadt 134: if (ep == NULL)
1.36 espie 135: return 1;
1.10 deraadt 136: um = umi;
137: }
1.12 espie 138: else {
139: um = umask(0);
140: printf("%o\n", um);
141: }
1.36 espie 142: (void)umask(um);
143: return -1;
1.10 deraadt 144: }
145:
1.36 espie 146: return 0;
1.10 deraadt 147: }
1.36 espie 148:
1.10 deraadt 149: /*-
150: *-----------------------------------------------------------------------
1.1 deraadt 151: * CompatRunCommand --
152: * Execute the next command for a target. If the command returns an
153: * error, the node's made field is set to ERROR and creation stops.
154: *
155: * Results:
1.36 espie 156: * 0 in case of error, 1 if ok.
1.1 deraadt 157: *
158: * Side Effects:
159: * The node's 'made' field may be set to ERROR.
160: *-----------------------------------------------------------------------
161: */
162: static int
1.36 espie 163: CompatRunCommand(cmdp, gnp)
164: void * cmdp; /* Command to execute */
165: void * gnp; /* Node from which the command came */
1.1 deraadt 166: {
1.36 espie 167: char *cmdStart; /* Start of expanded command */
1.12 espie 168: char *cp, *bp = NULL;
1.37 espie 169: bool silent, /* Don't print command */
1.32 espie 170: doExecute; /* Execute the command */
1.46 ! millert 171: volatile bool errCheck; /* Check errors */
1.36 espie 172: int reason; /* Reason for child's death */
173: int status; /* Description of child's death */
174: int cpid; /* Child actually found */
1.37 espie 175: int stat; /* Status of fork */
1.36 espie 176: LstNode cmdNode; /* Node where current command is located */
1.46 ! millert 177: char ** volatile av; /* Argument vector for thing to exec */
1.36 espie 178: int argc; /* Number of arguments in av or 0 if not
1.1 deraadt 179: * dynamically allocated */
1.37 espie 180: bool local; /* true if command should be executed
1.1 deraadt 181: * locally */
1.36 espie 182: char *cmd = (char *)cmdp;
183: GNode *gn = (GNode *)gnp;
1.37 espie 184: static char *shargv[4] = { _PATH_BSHELL };
1.36 espie 185:
1.1 deraadt 186: silent = gn->type & OP_SILENT;
187: errCheck = !(gn->type & OP_IGNORE);
1.32 espie 188: doExecute = !noExecute;
1.1 deraadt 189:
1.28 espie 190: cmdNode = Lst_Member(&gn->commands, cmd);
1.37 espie 191: cmdStart = Var_Subst(cmd, &gn->context, false);
1.1 deraadt 192:
1.36 espie 193: /* brk_string will return an argv with a NULL in av[0], thus causing
1.1 deraadt 194: * execvp to choke and die horribly. Besides, how can we execute a null
195: * command? In any case, we warn the user that the command expanded to
1.36 espie 196: * nothing (is this the right thing to do?). */
1.4 millert 197:
1.1 deraadt 198: if (*cmdStart == '\0') {
199: free(cmdStart);
200: Error("%s expands to empty string", cmd);
1.25 espie 201: return 1;
1.36 espie 202: } else
1.1 deraadt 203: cmd = cmdStart;
1.23 espie 204: Lst_Replace(cmdNode, cmdStart);
1.1 deraadt 205:
206: if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
1.28 espie 207: Lst_AtEnd(&ENDNode->commands, cmdStart);
1.25 espie 208: return 1;
1.1 deraadt 209: } else if (strcmp(cmdStart, "...") == 0) {
210: gn->type |= OP_SAVE_CMDS;
1.25 espie 211: return 1;
1.1 deraadt 212: }
213:
1.32 espie 214: for (;; cmd++) {
1.36 espie 215: if (*cmd == '@')
1.37 espie 216: silent = DEBUG(LOUD) ? false : true;
1.32 espie 217: else if (*cmd == '-')
1.37 espie 218: errCheck = false;
1.32 espie 219: else if (*cmd == '+')
1.37 espie 220: doExecute = true;
1.32 espie 221: else
222: break;
1.1 deraadt 223: }
224:
1.36 espie 225: while (isspace(*cmd))
1.1 deraadt 226: cmd++;
1.4 millert 227:
1.36 espie 228: /* Search for meta characters in the command. If there are no meta
1.1 deraadt 229: * characters, there's no need to execute a shell to execute the
1.36 espie 230: * command. */
1.1 deraadt 231: for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
232: continue;
233: }
234:
1.36 espie 235: /* Print the command before echoing if we're not supposed to be quiet for
236: * this one. We also print the command if -n given. */
1.1 deraadt 237: if (!silent || noExecute) {
1.36 espie 238: printf("%s\n", cmd);
1.1 deraadt 239: fflush(stdout);
240: }
241:
1.36 espie 242: /* If we're not supposed to execute any commands, this is as far as
243: * we go... */
1.32 espie 244: if (!doExecute)
1.25 espie 245: return 1;
1.4 millert 246:
1.1 deraadt 247: if (*cp != '\0') {
1.36 espie 248: /* If *cp isn't the null character, we hit a "meta" character and
1.1 deraadt 249: * need to pass the command off to the shell. We give the shell the
250: * -e flag as well as -c if it's supposed to exit when it hits an
1.36 espie 251: * error. */
1.10 deraadt 252:
1.36 espie 253: shargv[1] = errCheck ? "-ec" : "-c";
1.10 deraadt 254: shargv[2] = cmd;
1.36 espie 255: shargv[3] = NULL;
1.10 deraadt 256: av = shargv;
257: argc = 0;
1.12 espie 258: } else {
1.36 espie 259: /* No meta-characters, so probably no need to exec a shell.
260: * Break the command into words to form an argument vector
261: * we can execute. */
262: av = brk_string(cmd, &argc, &bp);
263: switch (shellneed(av)) {
1.12 espie 264: case -1: /* handled internally */
265: free(bp);
266: free(av);
1.25 espie 267: return 1;
1.12 espie 268: case 1:
1.36 espie 269: shargv[1] = errCheck ? "-ec" : "-c";
1.12 espie 270: shargv[2] = cmd;
1.36 espie 271: shargv[3] = NULL;
272: free(av);
1.14 espie 273: free(bp);
274: bp = NULL;
1.12 espie 275: av = shargv;
276: argc = 0;
277: break;
278: default: /* nothing needed */
279: break;
1.10 deraadt 280: }
1.1 deraadt 281: }
1.4 millert 282:
1.37 espie 283: local = true;
1.1 deraadt 284:
1.36 espie 285: /* Fork and execute the single command. If the fork fails, we abort. */
1.1 deraadt 286: cpid = vfork();
1.36 espie 287: if (cpid == -1)
1.1 deraadt 288: Fatal("Could not fork");
289: if (cpid == 0) {
290: if (local) {
291: execvp(av[0], av);
1.17 espie 292: if (errno == ENOENT)
1.36 espie 293: fprintf(stderr, "%s: not found\n", av[0]);
1.17 espie 294: else
295: perror(av[0]);
1.36 espie 296: } else
1.1 deraadt 297: (void)execv(av[0], av);
1.9 deraadt 298: _exit(1);
1.1 deraadt 299: }
1.12 espie 300: if (bp) {
1.36 espie 301: free(av);
1.12 espie 302: free(bp);
303: }
1.1 deraadt 304: free(cmdStart);
1.23 espie 305: Lst_Replace(cmdNode, NULL);
1.4 millert 306:
1.36 espie 307: /* The child is off and running. Now all we can do is wait... */
1.1 deraadt 308: while (1) {
309:
1.2 deraadt 310: while ((stat = wait(&reason)) != cpid) {
1.36 espie 311: if (stat == -1 && errno != EINTR)
1.1 deraadt 312: break;
313: }
1.4 millert 314:
1.45 espie 315: if (interrupted)
316: break;
317:
1.36 espie 318: if (stat != -1) {
319: if (WIFSTOPPED(reason))
1.2 deraadt 320: status = WSTOPSIG(reason); /* stopped */
1.36 espie 321: else if (WIFEXITED(reason)) {
1.2 deraadt 322: status = WEXITSTATUS(reason); /* exited */
1.36 espie 323: if (status != 0)
324: printf("*** Error code %d", status);
1.1 deraadt 325: } else {
1.2 deraadt 326: status = WTERMSIG(reason); /* signaled */
1.36 espie 327: printf("*** Signal %d", status);
1.4 millert 328: }
329:
1.1 deraadt 330:
1.36 espie 331: if (!WIFEXITED(reason) || status != 0) {
1.1 deraadt 332: if (errCheck) {
333: gn->made = ERROR;
1.36 espie 334: if (keepgoing)
335: /* Abort the current target, but let others
336: * continue. */
337: printf(" (continuing)\n");
1.1 deraadt 338: } else {
1.36 espie 339: /* Continue executing commands for this target.
340: * If we return 0, this will happen... */
341: printf(" (ignored)\n");
1.1 deraadt 342: status = 0;
343: }
344: }
1.45 espie 345: return !status;
1.36 espie 346: } else
347: Fatal("error in wait: %d", stat);
1.1 deraadt 348: /*NOTREACHED*/
349: }
350:
1.45 espie 351: /* This is reached only if interrupted */
352: if (!Targ_Precious(gn)) {
353: char *file = Varq_Value(TARGET_INDEX, gn);
354:
355: if (!noExecute && eunlink(file) != -1)
356: Error("*** %s removed\n", file);
357: }
358: if (interrupted == SIGINT) {
359: GNode *i = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
360: signal(SIGINT, SIG_IGN);
361: signal(SIGTERM, SIG_IGN);
362: signal(SIGHUP, SIG_IGN);
363: signal(SIGQUIT, SIG_IGN);
364: interrupted = 0;
365: if (i != NULL)
366: Lst_Find(&i->commands, CompatRunCommand, i);
367: exit(SIGINT);
368: }
369: exit(interrupted);
1.1 deraadt 370: }
1.36 espie 371:
1.1 deraadt 372: /*-
373: *-----------------------------------------------------------------------
374: * CompatMake --
375: * Make a target.
376: *
377: * Side Effects:
378: * If an error is detected and not being ignored, the process exits.
379: *-----------------------------------------------------------------------
380: */
1.26 espie 381: static void
382: CompatMake(gnp, pgnp)
1.36 espie 383: void * gnp; /* The node to make */
384: void * pgnp; /* Parent to abort if necessary */
1.1 deraadt 385: {
1.36 espie 386: GNode *gn = (GNode *)gnp;
387: GNode *pgn = (GNode *)pgnp;
1.5 millert 388:
1.7 deraadt 389: if (pgn->type & OP_MADE) {
1.35 espie 390: (void)Dir_MTime(gn);
1.7 deraadt 391: gn->made = UPTODATE;
392: }
393:
1.8 millert 394: if (gn->type & OP_USE) {
395: Make_HandleUse(gn, pgn);
396: } else if (gn->made == UNMADE) {
1.36 espie 397: /* First mark ourselves to be made, then apply whatever transformations
1.1 deraadt 398: * the suffix module thinks are necessary. Once that's done, we can
399: * descend and make all our children. If any of them has an error
1.37 espie 400: * but the -k flag was given, our 'make' field will be set false again.
1.1 deraadt 401: * This is our signal to not attempt to do anything but abort our
1.36 espie 402: * parent as well. */
1.37 espie 403: gn->make = true;
1.1 deraadt 404: gn->made = BEINGMADE;
1.36 espie 405: Suff_FindDeps(gn);
1.28 espie 406: Lst_ForEach(&gn->children, CompatMake, gn);
1.1 deraadt 407: if (!gn->make) {
408: gn->made = ABORTED;
1.37 espie 409: pgn->make = false;
1.26 espie 410: return;
1.1 deraadt 411: }
412:
1.44 deraadt 413: if (Lst_Member(&gn->iParents, pgn) != NULL) {
414: Varq_Set(IMPSRC_INDEX, Varq_Value(TARGET_INDEX, gn), pgn);
415: }
1.4 millert 416:
1.36 espie 417: /* All the children were made ok. Now cmtime contains the modification
1.1 deraadt 418: * time of the newest child, we need to find out if we exist and when
419: * we were modified last. The criteria for datedness are defined by the
1.36 espie 420: * Make_OODate function. */
421: if (DEBUG(MAKE))
1.1 deraadt 422: printf("Examining %s...", gn->name);
423: if (! Make_OODate(gn)) {
424: gn->made = UPTODATE;
1.36 espie 425: if (DEBUG(MAKE))
1.1 deraadt 426: printf("up-to-date.\n");
1.26 espie 427: return;
1.36 espie 428: } else if (DEBUG(MAKE))
1.1 deraadt 429: printf("out-of-date.\n");
430:
1.36 espie 431: /* If the user is just seeing if something is out-of-date, exit now
432: * to tell him/her "yes". */
433: if (queryFlag)
434: exit(-1);
1.1 deraadt 435:
1.36 espie 436: /* We need to be re-made. We also have to make sure we've got a $?
1.1 deraadt 437: * variable. To be nice, we also define the $> variable using
1.36 espie 438: * Make_DoAllVar(). */
1.1 deraadt 439: Make_DoAllVar(gn);
1.4 millert 440:
1.36 espie 441: /* Alter our type to tell if errors should be ignored or things
442: * should not be printed so CompatRunCommand knows what to do. */
443: if (Targ_Ignore(gn))
1.1 deraadt 444: gn->type |= OP_IGNORE;
1.36 espie 445: if (Targ_Silent(gn))
1.1 deraadt 446: gn->type |= OP_SILENT;
447:
1.36 espie 448: if (Job_CheckCommands(gn, Fatal)) {
449: /* Our commands are ok, but we still have to worry about the -t
450: * flag... */
1.45 espie 451: if (!touchFlag)
1.28 espie 452: Lst_Find(&gn->commands, CompatRunCommand, gn);
1.45 espie 453: else
1.36 espie 454: Job_Touch(gn, gn->type & OP_SILENT);
455: } else
1.1 deraadt 456: gn->made = ERROR;
457:
458: if (gn->made != ERROR) {
1.36 espie 459: /* If the node was made successfully, mark it so, update
1.1 deraadt 460: * its modification time and timestamp all its parents. Note
461: * that for .ZEROTIME targets, the timestamping isn't done.
1.36 espie 462: * This is to keep its state from affecting that of its parent. */
1.1 deraadt 463: gn->made = MADE;
464: #ifndef RECHECK
1.36 espie 465: /* We can't re-stat the thing, but we can at least take care of
1.1 deraadt 466: * rules where a target depends on a source that actually creates
467: * the target, but only if it has changed, e.g.
468: *
469: * parse.h : parse.o
470: *
471: * parse.o : parse.y
1.36 espie 472: * yacc -d parse.y
473: * cc -c y.tab.c
474: * mv y.tab.o parse.o
475: * cmp -s y.tab.h parse.h || mv y.tab.h parse.h
1.1 deraadt 476: *
477: * In this case, if the definitions produced by yacc haven't
478: * changed from before, parse.h won't have been updated and
479: * gn->mtime will reflect the current modification time for
480: * parse.h. This is something of a kludge, I admit, but it's a
481: * useful one..
482: *
483: * XXX: People like to use a rule like
484: *
485: * FRC:
486: *
487: * To force things that depend on FRC to be made, so we have to
1.36 espie 488: * check for gn->children being empty as well... */
489: if (!Lst_IsEmpty(&gn->commands) || Lst_IsEmpty(&gn->children))
1.1 deraadt 490: gn->mtime = now;
491: #else
1.36 espie 492: /* This is what Make does and it's actually a good thing, as it
1.1 deraadt 493: * allows rules like
494: *
495: * cmp -s y.tab.h parse.h || cp y.tab.h parse.h
496: *
497: * to function as intended. Unfortunately, thanks to the stateless
498: * nature of NFS (and the speed of this program), there are times
499: * when the modification time of a file created on a remote
500: * machine will not be modified before the stat() implied by
501: * the Dir_MTime occurs, thus leading us to believe that the file
502: * is unchanged, wreaking havoc with files that depend on this one.
503: *
504: * I have decided it is better to make too much than to make too
505: * little, so this stuff is commented out unless you're sure it's
506: * ok.
507: * -- ardeb 1/12/88
508: */
1.35 espie 509: if (noExecute || is_out_of_date(Dir_MTime(gn)))
1.1 deraadt 510: gn->mtime = now;
1.37 espie 511: if (is_strictly_before(gn->mtime, gn->cmtime))
1.1 deraadt 512: gn->mtime = gn->cmtime;
1.36 espie 513: if (DEBUG(MAKE))
1.1 deraadt 514: printf("update time: %s\n", Targ_FmtTime(gn->mtime));
515: #endif
516: if (!(gn->type & OP_EXEC)) {
1.37 espie 517: pgn->childMade = true;
1.1 deraadt 518: Make_TimeStamp(pgn, gn);
519: }
1.36 espie 520: } else if (keepgoing)
1.37 espie 521: pgn->make = false;
1.36 espie 522: else {
523:
1.24 espie 524: if (gn->lineno)
1.36 espie 525: printf("\n\nStop in %s (line %lu of %s).\n",
526: Var_Value(".CURDIR"),
1.24 espie 527: (unsigned long)gn->lineno,
528: gn->fname);
529: else
1.36 espie 530: printf("\n\nStop in %s.\n", Var_Value(".CURDIR"));
531: exit(1);
1.1 deraadt 532: }
1.36 espie 533: } else if (gn->made == ERROR)
534: /* Already had an error when making this beastie. Tell the parent
535: * to abort. */
1.37 espie 536: pgn->make = false;
1.36 espie 537: else {
1.44 deraadt 538: if (Lst_Member(&gn->iParents, pgn) != NULL) {
539: Varq_Set(IMPSRC_INDEX, Varq_Value(TARGET_INDEX, gn), pgn);
540: }
1.36 espie 541: switch (gn->made) {
1.1 deraadt 542: case BEINGMADE:
543: Error("Graph cycles through %s\n", gn->name);
544: gn->made = ERROR;
1.37 espie 545: pgn->make = false;
1.1 deraadt 546: break;
547: case MADE:
548: if ((gn->type & OP_EXEC) == 0) {
1.37 espie 549: pgn->childMade = true;
1.1 deraadt 550: Make_TimeStamp(pgn, gn);
551: }
552: break;
553: case UPTODATE:
1.36 espie 554: if ((gn->type & OP_EXEC) == 0)
1.1 deraadt 555: Make_TimeStamp(pgn, gn);
556: break;
557: default:
558: break;
559: }
560: }
561: }
1.36 espie 562:
1.1 deraadt 563: void
564: Compat_Run(targs)
1.36 espie 565: Lst targs; /* List of target nodes to re-create */
1.1 deraadt 566: {
1.36 espie 567: char *cp; /* Pointer to string of shell meta-characters */
568: GNode *gn = NULL;/* Current root target */
569: int errors; /* Number of targets not remade due to errors */
1.1 deraadt 570:
1.45 espie 571: signal(SIGINT, CompatInterrupt);
572: signal(SIGTERM, CompatInterrupt);
573: signal(SIGHUP, CompatInterrupt);
574: signal(SIGQUIT, CompatInterrupt);
1.1 deraadt 575:
1.36 espie 576: for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++)
1.1 deraadt 577: meta[(unsigned char) *cp] = 1;
1.36 espie 578: /* The null character serves as a sentinel in the string. */
1.1 deraadt 579: meta[0] = 1;
580:
1.37 espie 581: ENDNode = Targ_FindNode(".END", TARG_CREATE);
1.36 espie 582: /* If the user has defined a .BEGIN target, execute the commands attached
583: * to it. */
1.1 deraadt 584: if (!queryFlag) {
1.37 espie 585: gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
1.18 espie 586: if (gn != NULL) {
1.28 espie 587: Lst_Find(&gn->commands, CompatRunCommand, gn);
1.36 espie 588: if (gn->made == ERROR) {
589: printf("\n\nStop.\n");
590: exit(1);
591: }
1.1 deraadt 592: }
593: }
594:
1.36 espie 595: /* For each entry in the list of targets to create, call CompatMake on
1.1 deraadt 596: * it to create the thing. CompatMake will leave the 'made' field of gn
597: * in one of several states:
598: * UPTODATE gn was already up-to-date
1.36 espie 599: * MADE gn was recreated successfully
600: * ERROR An error occurred while gn was being created
1.1 deraadt 601: * ABORTED gn was not remade because one of its inferiors
1.36 espie 602: * could not be made due to errors. */
1.1 deraadt 603: errors = 0;
1.19 espie 604: while ((gn = (GNode *)Lst_DeQueue(targs)) != NULL) {
1.26 espie 605: CompatMake(gn, gn);
1.1 deraadt 606:
1.36 espie 607: if (gn->made == UPTODATE)
608: printf("`%s' is up to date.\n", gn->name);
609: else if (gn->made == ABORTED) {
610: printf("`%s' not remade because of errors.\n", gn->name);
1.1 deraadt 611: errors += 1;
612: }
613: }
614:
1.36 espie 615: /* If the user has defined a .END target, run its commands. */
616: if (errors == 0)
1.40 mickey 617: Lst_Find(&ENDNode->commands, CompatRunCommand, ENDNode);
1.1 deraadt 618: }