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