Deleted Added
full compact
job.c (246223) job.c (249033)
1/* $NetBSD: job.c,v 1.165 2013/01/26 15:52:59 christos Exp $ */
1/* $NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $ */
2
3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 55 unchanged lines hidden (view full) ---

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
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
69 * SUCH DAMAGE.
70 */
71
72#ifndef MAKE_NATIVE
2
3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 55 unchanged lines hidden (view full) ---

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
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
69 * SUCH DAMAGE.
70 */
71
72#ifndef MAKE_NATIVE
73static char rcsid[] = "$NetBSD: job.c,v 1.165 2013/01/26 15:52:59 christos Exp $";
73static char rcsid[] = "$NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $";
74#else
75#include <sys/cdefs.h>
76#ifndef lint
77#if 0
78static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
79#else
74#else
75#include <sys/cdefs.h>
76#ifndef lint
77#if 0
78static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
79#else
80__RCSID("$NetBSD: job.c,v 1.165 2013/01/26 15:52:59 christos Exp $");
80__RCSID("$NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $");
81#endif
82#endif /* not lint */
83#endif
84
85/*-
86 * job.c --
87 * handle the creation etc. of our child processes.
88 *

--- 48 unchanged lines hidden (view full) ---

137# include "config.h"
138#endif
139#include <sys/types.h>
140#include <sys/stat.h>
141#include <sys/file.h>
142#include <sys/time.h>
143#include "wait.h"
144
81#endif
82#endif /* not lint */
83#endif
84
85/*-
86 * job.c --
87 * handle the creation etc. of our child processes.
88 *

--- 48 unchanged lines hidden (view full) ---

137# include "config.h"
138#endif
139#include <sys/types.h>
140#include <sys/stat.h>
141#include <sys/file.h>
142#include <sys/time.h>
143#include "wait.h"
144
145#include <assert.h>
145#include <errno.h>
146#include <fcntl.h>
147#if !defined(USE_SELECT) && defined(HAVE_POLL_H)
148#include <poll.h>
149#else
150#ifndef USE_SELECT /* no poll.h */
151# define USE_SELECT
152#endif

--- 1087 unchanged lines hidden (view full) ---

1240 * rule to go on and the target doesn't already exist. There's
1241 * nothing more we can do for this branch. If the -k flag wasn't
1242 * given, we stop in our tracks, otherwise we just don't update
1243 * this node's parents so they never get examined.
1244 */
1245 static const char msg[] = ": don't know how to make";
1246
1247 if (gn->flags & FROM_DEPEND) {
146#include <errno.h>
147#include <fcntl.h>
148#if !defined(USE_SELECT) && defined(HAVE_POLL_H)
149#include <poll.h>
150#else
151#ifndef USE_SELECT /* no poll.h */
152# define USE_SELECT
153#endif

--- 1087 unchanged lines hidden (view full) ---

1241 * rule to go on and the target doesn't already exist. There's
1242 * nothing more we can do for this branch. If the -k flag wasn't
1243 * given, we stop in our tracks, otherwise we just don't update
1244 * this node's parents so they never get examined.
1245 */
1246 static const char msg[] = ": don't know how to make";
1247
1248 if (gn->flags & FROM_DEPEND) {
1248 fprintf(stdout, "%s: ignoring stale %s for %s\n",
1249 progname, makeDependfile, gn->name);
1249 if (!Job_RunTarget(".STALE", gn->fname))
1250 fprintf(stdout, "%s: %s, %d: ignoring stale %s for %s\n",
1251 progname, gn->fname, gn->lineno, makeDependfile,
1252 gn->name);
1250 return TRUE;
1251 }
1252
1253 if (gn->type & OP_OPTIONAL) {
1254 (void)fprintf(stdout, "%s%s %s (ignored)\n", progname,
1255 msg, gn->name);
1256 (void)fflush(stdout);
1257 } else if (keepgoing) {

--- 800 unchanged lines hidden (view full) ---

2058{
2059 int nready;
2060 Job *job;
2061 int i;
2062
2063 (void)fflush(stdout);
2064
2065 /* The first fd in the list is the job token pipe */
1253 return TRUE;
1254 }
1255
1256 if (gn->type & OP_OPTIONAL) {
1257 (void)fprintf(stdout, "%s%s %s (ignored)\n", progname,
1258 msg, gn->name);
1259 (void)fflush(stdout);
1260 } else if (keepgoing) {

--- 800 unchanged lines hidden (view full) ---

2061{
2062 int nready;
2063 Job *job;
2064 int i;
2065
2066 (void)fflush(stdout);
2067
2068 /* The first fd in the list is the job token pipe */
2066 nready = poll(fds + 1 - wantToken, nfds - 1 + wantToken, POLL_MSEC);
2069 do {
2070 nready = poll(fds + 1 - wantToken, nfds - 1 + wantToken, POLL_MSEC);
2071 } while (nready < 0 && errno == EINTR);
2067
2072
2068 if (nready < 0 || readyfd(&childExitJob)) {
2073 if (nready < 0)
2074 Punt("poll: %s", strerror(errno));
2075
2076 if (nready > 0 && readyfd(&childExitJob)) {
2069 char token = 0;
2077 char token = 0;
2070 nready -= 1;
2071 while (read(childExitJob.inPipe, &token, 1) == -1 && errno == EAGAIN)
2072 continue;
2073 if (token == DO_JOB_RESUME[0])
2074 /* Complete relay requested from our SIGCONT handler */
2075 JobRestartJobs();
2076 Job_CatchChildren();
2078 ssize_t count;
2079 count = read(childExitJob.inPipe, &token, 1);
2080 switch (count) {
2081 case 0:
2082 Punt("unexpected eof on token pipe");
2083 case -1:
2084 Punt("token pipe read: %s", strerror(errno));
2085 case 1:
2086 if (token == DO_JOB_RESUME[0])
2087 /* Complete relay requested from our SIGCONT handler */
2088 JobRestartJobs();
2089 break;
2090 default:
2091 abort();
2092 }
2093 --nready;
2077 }
2078
2094 }
2095
2079 if (nready <= 0)
2080 return;
2096 Job_CatchChildren();
2097 if (nready == 0)
2098 return;
2081
2099
2082 if (wantToken && readyfd(&tokenWaitJob))
2083 nready--;
2084
2085 for (i = 2; i < nfds; i++) {
2086 if (!fds[i].revents)
2087 continue;
2088 job = jobfds[i];
2100 for (i = 2; i < nfds; i++) {
2101 if (!fds[i].revents)
2102 continue;
2103 job = jobfds[i];
2089 if (job->job_state != JOB_ST_RUNNING)
2090 continue;
2091 JobDoOutput(job, FALSE);
2104 if (job->job_state == JOB_ST_RUNNING)
2105 JobDoOutput(job, FALSE);
2106 if (--nready == 0)
2107 return;
2092 }
2093}
2094
2095/*-
2096 *-----------------------------------------------------------------------
2097 * Job_Make --
2098 * Start the creation of a target. Basically a front-end for
2099 * JobStart used by the Make module.

--- 74 unchanged lines hidden (view full) ---

2174 *
2175 * Side Effects:
2176 * lists and counters are initialized
2177 *-----------------------------------------------------------------------
2178 */
2179void
2180Job_Init(void)
2181{
2108 }
2109}
2110
2111/*-
2112 *-----------------------------------------------------------------------
2113 * Job_Make --
2114 * Start the creation of a target. Basically a front-end for
2115 * JobStart used by the Make module.

--- 74 unchanged lines hidden (view full) ---

2190 *
2191 * Side Effects:
2192 * lists and counters are initialized
2193 *-----------------------------------------------------------------------
2194 */
2195void
2196Job_Init(void)
2197{
2182 GNode *begin; /* node for commands to do at the very start */
2183
2184 /* Allocate space for all the job info */
2185 job_table = bmake_malloc(maxJobs * sizeof *job_table);
2186 memset(job_table, 0, maxJobs * sizeof *job_table);
2187 job_table_end = job_table + maxJobs;
2188 wantToken = 0;
2189
2190 aborting = 0;
2191 errors = 0;

--- 59 unchanged lines hidden (view full) ---

2251 */
2252 ADDSIG(SIGTSTP, JobPassSig_suspend)
2253 ADDSIG(SIGTTOU, JobPassSig_suspend)
2254 ADDSIG(SIGTTIN, JobPassSig_suspend)
2255 ADDSIG(SIGWINCH, JobCondPassSig)
2256 ADDSIG(SIGCONT, JobContinueSig)
2257#undef ADDSIG
2258
2198 /* Allocate space for all the job info */
2199 job_table = bmake_malloc(maxJobs * sizeof *job_table);
2200 memset(job_table, 0, maxJobs * sizeof *job_table);
2201 job_table_end = job_table + maxJobs;
2202 wantToken = 0;
2203
2204 aborting = 0;
2205 errors = 0;

--- 59 unchanged lines hidden (view full) ---

2265 */
2266 ADDSIG(SIGTSTP, JobPassSig_suspend)
2267 ADDSIG(SIGTTOU, JobPassSig_suspend)
2268 ADDSIG(SIGTTIN, JobPassSig_suspend)
2269 ADDSIG(SIGWINCH, JobCondPassSig)
2270 ADDSIG(SIGCONT, JobContinueSig)
2271#undef ADDSIG
2272
2259 begin = Targ_FindNode(".BEGIN", TARG_NOCREATE);
2260
2261 if (begin != NULL) {
2262 JobRun(begin);
2263 if (begin->made == ERROR) {
2264 PrintOnError(begin, "\n\nStop.");
2265 exit(1);
2266 }
2267 }
2273 (void)Job_RunTarget(".BEGIN", NULL);
2268 postCommands = Targ_FindNode(".END", TARG_CREATE);
2269}
2270
2271static void JobSigReset(void)
2272{
2273#define DELSIG(s) \
2274 if (sigismember(&caught_signals, s)) { \
2275 (void)bmake_signal(s, SIG_DFL); \

--- 649 unchanged lines hidden (view full) ---

2925 continue;
2926
2927 jobTokensRunning++;
2928 if (DEBUG(JOB))
2929 fprintf(debug_file, "(%d) withdrew token\n", getpid());
2930 return TRUE;
2931}
2932
2274 postCommands = Targ_FindNode(".END", TARG_CREATE);
2275}
2276
2277static void JobSigReset(void)
2278{
2279#define DELSIG(s) \
2280 if (sigismember(&caught_signals, s)) { \
2281 (void)bmake_signal(s, SIG_DFL); \

--- 649 unchanged lines hidden (view full) ---

2931 continue;
2932
2933 jobTokensRunning++;
2934 if (DEBUG(JOB))
2935 fprintf(debug_file, "(%d) withdrew token\n", getpid());
2936 return TRUE;
2937}
2938
2939/*-
2940 *-----------------------------------------------------------------------
2941 * Job_RunTarget --
2942 * Run the named target if found. If a filename is specified, then
2943 * set that to the sources.
2944 *
2945 * Results:
2946 * None
2947 *
2948 * Side Effects:
2949 * exits if the target fails.
2950 *
2951 *-----------------------------------------------------------------------
2952 */
2953Boolean
2954Job_RunTarget(const char *target, const char *fname) {
2955 GNode *gn = Targ_FindNode(target, TARG_NOCREATE);
2956
2957 if (gn == NULL)
2958 return FALSE;
2959
2960 if (fname)
2961 Var_Set(ALLSRC, fname, gn, 0);
2962
2963 JobRun(gn);
2964 if (gn->made == ERROR) {
2965 PrintOnError(gn, "\n\nStop.");
2966 exit(1);
2967 }
2968 return TRUE;
2969}
2970
2933#ifdef USE_SELECT
2934int
2935emul_poll(struct pollfd *fd, int nfd, int timeout)
2936{
2937 fd_set rfds, wfds;
2938 int i, maxfd, nselect, npoll;
2939 struct timeval tv, *tvp;
2940 long usecs;

--- 52 unchanged lines hidden ---
2971#ifdef USE_SELECT
2972int
2973emul_poll(struct pollfd *fd, int nfd, int timeout)
2974{
2975 fd_set rfds, wfds;
2976 int i, maxfd, nselect, npoll;
2977 struct timeval tv, *tvp;
2978 long usecs;

--- 52 unchanged lines hidden ---