| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: job.c,v 1.220 2020/08/28 04:48:57 rillig Exp $ */ | | 1 | /* $NetBSD: job.c,v 1.221 2020/08/28 20:23:20 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. | | 4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -60,34 +60,34 @@ | | | @@ -60,34 +60,34 @@ |
60 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 60 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
61 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 61 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
62 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 62 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
63 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 63 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
64 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 64 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
65 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 65 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
69 | * SUCH DAMAGE. | | 69 | * SUCH DAMAGE. |
70 | */ | | 70 | */ |
71 | | | 71 | |
72 | #ifndef MAKE_NATIVE | | 72 | #ifndef MAKE_NATIVE |
73 | static char rcsid[] = "$NetBSD: job.c,v 1.220 2020/08/28 04:48:57 rillig Exp $"; | | 73 | static char rcsid[] = "$NetBSD: job.c,v 1.221 2020/08/28 20:23:20 rillig Exp $"; |
74 | #else | | 74 | #else |
75 | #include <sys/cdefs.h> | | 75 | #include <sys/cdefs.h> |
76 | #ifndef lint | | 76 | #ifndef lint |
77 | #if 0 | | 77 | #if 0 |
78 | static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; | | 78 | static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; |
79 | #else | | 79 | #else |
80 | __RCSID("$NetBSD: job.c,v 1.220 2020/08/28 04:48:57 rillig Exp $"); | | 80 | __RCSID("$NetBSD: job.c,v 1.221 2020/08/28 20:23:20 rillig Exp $"); |
81 | #endif | | 81 | #endif |
82 | #endif /* not lint */ | | 82 | #endif /* not lint */ |
83 | #endif | | 83 | #endif |
84 | | | 84 | |
85 | /*- | | 85 | /*- |
86 | * job.c -- | | 86 | * job.c -- |
87 | * handle the creation etc. of our child processes. | | 87 | * handle the creation etc. of our child processes. |
88 | * | | 88 | * |
89 | * Interface: | | 89 | * Interface: |
90 | * Job_Make Start the creation of the given target. | | 90 | * Job_Make Start the creation of the given target. |
91 | * | | 91 | * |
92 | * Job_CatchChildren Check for and handle the termination of any | | 92 | * Job_CatchChildren Check for and handle the termination of any |
93 | * children. This must be called reasonably | | 93 | * children. This must be called reasonably |
| @@ -157,27 +157,26 @@ __RCSID("$NetBSD: job.c,v 1.220 2020/08/ | | | @@ -157,27 +157,26 @@ __RCSID("$NetBSD: job.c,v 1.220 2020/08/ |
157 | * error handling variables | | 157 | * error handling variables |
158 | */ | | 158 | */ |
159 | static int errors = 0; /* number of errors reported */ | | 159 | static int errors = 0; /* number of errors reported */ |
160 | static int aborting = 0; /* why is the make aborting? */ | | 160 | static int aborting = 0; /* why is the make aborting? */ |
161 | #define ABORT_ERROR 1 /* Because of an error */ | | 161 | #define ABORT_ERROR 1 /* Because of an error */ |
162 | #define ABORT_INTERRUPT 2 /* Because it was interrupted */ | | 162 | #define ABORT_INTERRUPT 2 /* Because it was interrupted */ |
163 | #define ABORT_WAIT 3 /* Waiting for jobs to finish */ | | 163 | #define ABORT_WAIT 3 /* Waiting for jobs to finish */ |
164 | #define JOB_TOKENS "+EI+" /* Token to requeue for each abort state */ | | 164 | #define JOB_TOKENS "+EI+" /* Token to requeue for each abort state */ |
165 | | | 165 | |
166 | /* | | 166 | /* |
167 | * this tracks the number of tokens currently "out" to build jobs. | | 167 | * this tracks the number of tokens currently "out" to build jobs. |
168 | */ | | 168 | */ |
169 | int jobTokensRunning = 0; | | 169 | int jobTokensRunning = 0; |
170 | int not_parallel = 0; /* set if .NOT_PARALLEL */ | | | |
171 | | | 170 | |
172 | /* | | 171 | /* |
173 | * XXX: Avoid SunOS bug... FILENO() is fp->_file, and file | | 172 | * XXX: Avoid SunOS bug... FILENO() is fp->_file, and file |
174 | * is a char! So when we go above 127 we turn negative! | | 173 | * is a char! So when we go above 127 we turn negative! |
175 | */ | | 174 | */ |
176 | #define FILENO(a) ((unsigned) fileno(a)) | | 175 | #define FILENO(a) ((unsigned) fileno(a)) |
177 | | | 176 | |
178 | /* | | 177 | /* |
179 | * post-make command processing. The node postCommands is really just the | | 178 | * post-make command processing. The node postCommands is really just the |
180 | * .END target but we keep it around to avoid having to search for it | | 179 | * .END target but we keep it around to avoid having to search for it |
181 | * all the time. | | 180 | * all the time. |
182 | */ | | 181 | */ |
183 | static GNode *postCommands = NULL; | | 182 | static GNode *postCommands = NULL; |
| @@ -343,27 +342,27 @@ static void JobClose(Job *); | | | @@ -343,27 +342,27 @@ static void JobClose(Job *); |
343 | static void JobExec(Job *, char **); | | 342 | static void JobExec(Job *, char **); |
344 | static void JobMakeArgv(Job *, char **); | | 343 | static void JobMakeArgv(Job *, char **); |
345 | static int JobStart(GNode *, int); | | 344 | static int JobStart(GNode *, int); |
346 | static char *JobOutput(Job *, char *, char *, int); | | 345 | static char *JobOutput(Job *, char *, char *, int); |
347 | static void JobDoOutput(Job *, Boolean); | | 346 | static void JobDoOutput(Job *, Boolean); |
348 | static Shell *JobMatchShell(const char *); | | 347 | static Shell *JobMatchShell(const char *); |
349 | static void JobInterrupt(int, int) MAKE_ATTR_DEAD; | | 348 | static void JobInterrupt(int, int) MAKE_ATTR_DEAD; |
350 | static void JobRestartJobs(void); | | 349 | static void JobRestartJobs(void); |
351 | static void JobTokenAdd(void); | | 350 | static void JobTokenAdd(void); |
352 | static void JobSigLock(sigset_t *); | | 351 | static void JobSigLock(sigset_t *); |
353 | static void JobSigUnlock(sigset_t *); | | 352 | static void JobSigUnlock(sigset_t *); |
354 | static void JobSigReset(void); | | 353 | static void JobSigReset(void); |
355 | | | 354 | |
356 | const char *malloc_options="A"; | | 355 | const char *malloc_options MAKE_ATTR_UNUSED = "A"; /* see jemalloc(3) */ |
357 | | | 356 | |
358 | static unsigned | | 357 | static unsigned |
359 | nfds_per_job(void) | | 358 | nfds_per_job(void) |
360 | { | | 359 | { |
361 | #if defined(USE_FILEMON) && !defined(USE_FILEMON_DEV) | | 360 | #if defined(USE_FILEMON) && !defined(USE_FILEMON_DEV) |
362 | if (useMeta) | | 361 | if (useMeta) |
363 | return 2; | | 362 | return 2; |
364 | #endif | | 363 | #endif |
365 | return 1; | | 364 | return 1; |
366 | } | | 365 | } |
367 | | | 366 | |
368 | static void | | 367 | static void |
369 | job_table_dump(const char *where) | | 368 | job_table_dump(const char *where) |
| @@ -896,27 +895,27 @@ JobPrintCommand(void *cmdp, void *jobp) | | | @@ -896,27 +895,27 @@ JobPrintCommand(void *cmdp, void *jobp) |
896 | return 0; | | 895 | return 0; |
897 | } | | 896 | } |
898 | | | 897 | |
899 | /*- | | 898 | /*- |
900 | *----------------------------------------------------------------------- | | 899 | *----------------------------------------------------------------------- |
901 | * JobSaveCommand -- | | 900 | * JobSaveCommand -- |
902 | * Save a command to be executed when everything else is done. | | 901 | * Save a command to be executed when everything else is done. |
903 | * Callback function for JobFinish... | | 902 | * Callback function for JobFinish... |
904 | * | | 903 | * |
905 | * Results: | | 904 | * Results: |
906 | * Always returns 0 | | 905 | * Always returns 0 |
907 | * | | 906 | * |
908 | * Side Effects: | | 907 | * Side Effects: |
909 | * The command is tacked onto the end of postCommands's commands list. | | 908 | * The command is tacked onto the end of postCommands' commands list. |
910 | * | | 909 | * |
911 | *----------------------------------------------------------------------- | | 910 | *----------------------------------------------------------------------- |
912 | */ | | 911 | */ |
913 | static int | | 912 | static int |
914 | JobSaveCommand(void *cmd, void *gn) | | 913 | JobSaveCommand(void *cmd, void *gn) |
915 | { | | 914 | { |
916 | cmd = Var_Subst((char *)cmd, (GNode *)gn, VARE_WANTRES); | | 915 | cmd = Var_Subst((char *)cmd, (GNode *)gn, VARE_WANTRES); |
917 | Lst_Append(postCommands->commands, cmd); | | 916 | Lst_Append(postCommands->commands, cmd); |
918 | return 0; | | 917 | return 0; |
919 | } | | 918 | } |
920 | | | 919 | |
921 | | | 920 | |
922 | /*- | | 921 | /*- |