Print this page
make: unifdef for REDIRECT_ERR (defined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/parallel.cc
+++ new/usr/src/cmd/make/bin/parallel.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #ifdef TEAMWARE_MAKE_CMN
27 27
28 28 /*
29 29 * parallel.cc
30 30 *
31 31 * Deal with the parallel processing
32 32 */
33 33
34 34 /*
35 35 * Included files
36 36 */
37 37 #ifdef DISTRIBUTED
38 38 #include <avo/strings.h> /* AVO_STRDUP() */
39 39 #include <dm/Avo_DoJobMsg.h>
40 40 #include <dm/Avo_MToolJobResultMsg.h>
41 41 #endif
42 42 #include <errno.h> /* errno */
43 43 #include <fcntl.h>
44 44 #include <avo/util.h> /* avo_get_user(), avo_hostname() */
45 45 #include <mk/defs.h>
46 46 #include <mksh/dosys.h> /* redirect_io() */
47 47 #include <mksh/macro.h> /* expand_value() */
48 48 #include <mksh/misc.h> /* getmem() */
49 49 #include <sys/signal.h>
50 50 #include <sys/stat.h>
51 51 #include <sys/types.h>
52 52 #include <sys/utsname.h>
53 53 #include <sys/wait.h>
54 54 #include <unistd.h>
55 55
56 56
57 57
58 58 /*
59 59 * Defined macros
60 60 */
61 61 #define MAXRULES 100
62 62
63 63 /*
64 64 * This const should be in avo_dms/include/AvoDmakeCommand.h
65 65 */
66 66 const int local_host_mask = 0x20;
67 67
68 68
69 69 /*
70 70 * typedefs & structs
71 71 */
72 72
73 73
74 74 /*
75 75 * Static variables
76 76 */
77 77 #ifdef TEAMWARE_MAKE_CMN
78 78 static Boolean just_did_subtree = false;
79 79 static char local_host[MAXNAMELEN] = "";
80 80 static char user_name[MAXNAMELEN] = "";
81 81 #endif
82 82 static int pmake_max_jobs = 0;
83 83 static pid_t process_running = -1;
84 84 static Running *running_tail = &running_list;
85 85 static Name subtree_conflict;
86 86 static Name subtree_conflict2;
87 87
88 88
89 89 /*
90 90 * File table of contents
91 91 */
92 92 #ifdef DISTRIBUTED
93 93 static void append_dmake_cmd(Avo_DoJobMsg *dmake_job_msg, char *orig_cmd_line, int cmd_options);
94 94 static void append_job_result_msg(Avo_MToolJobResultMsg *msg, char *outFn, char *errFn);
95 95 static void send_job_result_msg(Running rp);
96 96 #endif
97 97 static void delete_running_struct(Running rp);
98 98 static Boolean dependency_conflict(Name target);
99 99 static Doname distribute_process(char **commands, Property line);
100 100 static void doname_subtree(Name target, Boolean do_get, Boolean implicit);
101 101 static void dump_out_file(char *filename, Boolean err);
102 102 static void finish_doname(Running rp);
103 103 static void maybe_reread_make_state(void);
104 104 static void process_next(void);
105 105 static void reset_conditionals(int cnt, Name *targets, Property *locals);
106 106 static pid_t run_rule_commands(char *host, char **commands);
107 107 static Property *set_conditionals(int cnt, Name *targets);
108 108 static void store_conditionals(Running rp);
109 109
110 110
111 111 /*
112 112 * execute_parallel(line, waitflg)
113 113 *
114 114 * DMake 2.x:
115 115 * parallel mode: spawns a parallel process to execute the command group.
116 116 * distributed mode: sends the command group down the pipe to rxm.
117 117 *
118 118 * Return value:
119 119 * The result of the execution
120 120 *
121 121 * Parameters:
122 122 * line The command group to execute
123 123 */
124 124 Doname
125 125 execute_parallel(Property line, Boolean waitflg, Boolean local)
126 126 {
127 127 int argcnt;
128 128 int cmd_options = 0;
129 129 char *commands[MAXRULES + 5];
130 130 char *cp;
131 131 #ifdef DISTRIBUTED
132 132 Avo_DoJobMsg *dmake_job_msg = NULL;
133 133 #endif
134 134 Name dmake_name;
135 135 Name dmake_value;
136 136 int ignore;
137 137 Name make_machines_name;
138 138 char **p;
139 139 Property prop;
140 140 Doname result = build_ok;
141 141 Cmd_line rule;
142 142 Boolean silent_flag;
143 143 Name target = line->body.line.target;
144 144 Boolean wrote_state_file = false;
145 145
146 146 if ((pmake_max_jobs == 0) &&
147 147 (dmake_mode_type == parallel_mode)) {
148 148 if (user_name[0] == '\0') {
149 149 avo_get_user(user_name, NULL);
150 150 }
151 151 if (local_host[0] == '\0') {
152 152 strcpy(local_host, avo_hostname());
153 153 }
154 154 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MAX_JOBS"));
155 155 dmake_name = GETNAME(wcs_buffer, FIND_LENGTH);
156 156 if (((prop = get_prop(dmake_name->prop, macro_prop)) != NULL) &&
157 157 ((dmake_value = prop->body.macro.value) != NULL)) {
158 158 pmake_max_jobs = atoi(dmake_value->string_mb);
159 159 if (pmake_max_jobs <= 0) {
160 160 warning(catgets(catd, 1, 308, "DMAKE_MAX_JOBS cannot be less than or equal to zero."));
161 161 warning(catgets(catd, 1, 309, "setting DMAKE_MAX_JOBS to %d."), PMAKE_DEF_MAX_JOBS);
162 162 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
163 163 }
164 164 } else {
165 165 /*
166 166 * For backwards compatibility w/ PMake 1.x, when
167 167 * DMake 2.x is being run in parallel mode, DMake
168 168 * should parse the PMake startup file
169 169 * $(HOME)/.make.machines to get the pmake_max_jobs.
170 170 */
171 171 MBSTOWCS(wcs_buffer, NOCATGETS("PMAKE_MACHINESFILE"));
172 172 dmake_name = GETNAME(wcs_buffer, FIND_LENGTH);
173 173 if (((prop = get_prop(dmake_name->prop, macro_prop)) != NULL) &&
174 174 ((dmake_value = prop->body.macro.value) != NULL)) {
175 175 make_machines_name = dmake_value;
176 176 } else {
177 177 make_machines_name = NULL;
178 178 }
179 179 if ((pmake_max_jobs = read_make_machines(make_machines_name)) <= 0) {
180 180 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
181 181 }
182 182 }
183 183 #ifdef DISTRIBUTED
184 184 if (send_mtool_msgs) {
185 185 send_rsrc_info_msg(pmake_max_jobs, local_host, user_name);
186 186 }
187 187 #endif
188 188 }
189 189
190 190 if ((dmake_mode_type == serial_mode) ||
191 191 ((dmake_mode_type == parallel_mode) && (waitflg))) {
192 192 return (execute_serial(line));
193 193 }
194 194
195 195 #ifdef DISTRIBUTED
196 196 if (dmake_mode_type == distributed_mode) {
197 197 if(local) {
198 198 // return (execute_serial(line));
199 199 waitflg = true;
200 200 }
201 201 dmake_job_msg = new Avo_DoJobMsg();
202 202 dmake_job_msg->setJobId(++job_msg_id);
203 203 dmake_job_msg->setTarget(target->string_mb);
204 204 dmake_job_msg->setImmediateOutput(0);
205 205 called_make = false;
206 206 } else
207 207 #endif
208 208 {
209 209 p = commands;
210 210 }
211 211
212 212 argcnt = 0;
213 213 for (rule = line->body.line.command_used;
214 214 rule != NULL;
215 215 rule = rule->next) {
216 216 if (posix && (touch || quest) && !rule->always_exec) {
217 217 continue;
218 218 }
219 219 if (vpath_defined) {
220 220 rule->command_line =
221 221 vpath_translation(rule->command_line);
222 222 }
223 223 if (dmake_mode_type == distributed_mode) {
224 224 cmd_options = 0;
225 225 if(local) {
226 226 cmd_options |= local_host_mask;
227 227 }
228 228 } else {
229 229 silent_flag = false;
230 230 ignore = 0;
231 231 }
232 232 if (rule->command_line->hash.length > 0) {
233 233 if (++argcnt == MAXRULES) {
234 234 if (dmake_mode_type == distributed_mode) {
235 235 /* XXX - tell rxm to execute on local host. */
236 236 /* I WAS HERE!!! */
237 237 } else {
238 238 /* Too many rules, run serially instead. */
239 239 return build_serial;
240 240 }
241 241 }
242 242 #ifdef DISTRIBUTED
243 243 if (dmake_mode_type == distributed_mode) {
244 244 /*
245 245 * XXX - set assign_mask to tell rxm
246 246 * to do the following.
247 247 */
248 248 /* From execute_serial():
249 249 if (rule->assign) {
250 250 result = build_ok;
251 251 do_assign(rule->command_line, target);
252 252 */
253 253 if (0) {
254 254 } else if (report_dependencies_level == 0) {
255 255 if (rule->ignore_error) {
256 256 cmd_options |= ignore_mask;
257 257 }
258 258 if (rule->silent) {
259 259 cmd_options |= silent_mask;
260 260 }
261 261 if (rule->command_line->meta) {
262 262 cmd_options |= meta_mask;
263 263 }
264 264 if (rule->make_refd) {
265 265 cmd_options |= make_refd_mask;
266 266 }
267 267 if (do_not_exec_rule) {
268 268 cmd_options |= do_not_exec_mask;
269 269 }
270 270 append_dmake_cmd(dmake_job_msg,
271 271 rule->command_line->string_mb,
272 272 cmd_options);
273 273 /* Copying dosys()... */
274 274 if (rule->make_refd) {
275 275 if (waitflg) {
276 276 dmake_job_msg->setImmediateOutput(1);
277 277 }
278 278 called_make = true;
279 279 if (command_changed &&
280 280 !wrote_state_file) {
281 281 write_state_file(0, false);
282 282 wrote_state_file = true;
283 283 }
284 284 }
285 285 }
286 286 } else
287 287 #endif
288 288 {
289 289 if (rule->silent && !silent) {
290 290 silent_flag = true;
291 291 }
292 292 if (rule->ignore_error) {
293 293 ignore++;
294 294 }
295 295 /* XXX - need to add support for + prefix */
296 296 if (silent_flag || ignore) {
297 297 *p = getmem((silent_flag ? 1 : 0) +
298 298 ignore +
299 299 (strlen(rule->
300 300 command_line->
301 301 string_mb)) +
302 302 1);
303 303 cp = *p++;
304 304 if (silent_flag) {
305 305 *cp++ = (int) at_char;
306 306 }
307 307 if (ignore) {
308 308 *cp++ = (int) hyphen_char;
309 309 }
310 310 (void) strcpy(cp, rule->command_line->string_mb);
311 311 } else {
312 312 *p++ = rule->command_line->string_mb;
313 313 }
314 314 }
315 315 }
316 316 }
317 317 if ((argcnt == 0) ||
318 318 (report_dependencies_level > 0)) {
319 319 #ifdef DISTRIBUTED
320 320 if (dmake_job_msg) {
321 321 delete dmake_job_msg;
322 322 }
323 323 #endif
324 324 return build_ok;
325 325 }
326 326 #ifdef DISTRIBUTED
327 327 if (dmake_mode_type == distributed_mode) {
328 328 // Send a DoJob message to the rxm process.
329 329 distribute_rxm(dmake_job_msg);
330 330
331 331 // Wait for an acknowledgement.
332 332 Avo_AcknowledgeMsg *ackMsg = getAcknowledgeMsg();
333 333 if (ackMsg) {
334 334 delete ackMsg;
335 335 }
336 336
337 337 if (waitflg) {
338 338 // Wait for, and process a job result.
339 339 result = await_dist(waitflg);
340 340 if (called_make) {
341 341 maybe_reread_make_state();
342 342 }
343 343 check_state(temp_file_name);
344 344 if (result == build_failed) {
345 345 if (!continue_after_error) {
346 346
347 347 #ifdef PRINT_EXIT_STATUS
348 348 warning(NOCATGETS("I'm in execute_parallel. await_dist() returned build_failed"));
349 349 #endif
350 350
351 351 fatal(catgets(catd, 1, 252, "Command failed for target `%s'"),
352 352 target->string_mb);
353 353 }
354 354 /*
355 355 * Make sure a failing command is not
356 356 * saved in .make.state.
357 357 */
358 358 line->body.line.command_used = NULL;
359 359 }
360 360 if (temp_file_name != NULL) {
361 361 free_name(temp_file_name);
362 362 }
363 363 temp_file_name = NULL;
364 364 Property spro = get_prop(sunpro_dependencies->prop, macro_prop);
365 365 if(spro != NULL) {
366 366 Name val = spro->body.macro.value;
367 367 if(val != NULL) {
368 368 free_name(val);
369 369 spro->body.macro.value = NULL;
370 370 }
371 371 }
372 372 spro = get_prop(sunpro_dependencies->prop, env_mem_prop);
373 373 if(spro) {
374 374 char *val = spro->body.env_mem.value;
375 375 if(val != NULL) {
376 376 retmem_mb(val);
377 377 spro->body.env_mem.value = NULL;
378 378 }
379 379 }
380 380 return result;
381 381 } else {
382 382 parallel_process_cnt++;
383 383 return build_running;
384 384 }
385 385 } else
386 386 #endif
387 387 {
388 388 *p = NULL;
389 389
390 390 Doname res = distribute_process(commands, line);
391 391 if (res == build_running) {
392 392 parallel_process_cnt++;
393 393 }
394 394
395 395 /*
396 396 * Return only those memory that were specially allocated
397 397 * for part of commands.
398 398 */
399 399 for (int i = 0; commands[i] != NULL; i++) {
400 400 if ((commands[i][0] == (int) at_char) ||
401 401 (commands[i][0] == (int) hyphen_char)) {
402 402 retmem_mb(commands[i]);
403 403 }
404 404 }
405 405 return res;
406 406 }
407 407 }
408 408
409 409 #ifdef DISTRIBUTED
410 410 /*
411 411 * append_dmake_cmd()
412 412 *
413 413 * Replaces all escaped newline's (\<cr>)
414 414 * in the original command line with space's,
415 415 * then append the new command line to the DoJobMsg object.
416 416 */
417 417 static void
418 418 append_dmake_cmd(Avo_DoJobMsg *dmake_job_msg,
419 419 char *orig_cmd_line,
420 420 int cmd_options)
421 421 {
422 422 /*
423 423 Avo_DmakeCommand *tmp_dmake_command;
424 424
425 425 tmp_dmake_command = new Avo_DmakeCommand(orig_cmd_line, cmd_options);
426 426 dmake_job_msg->appendCmd(tmp_dmake_command);
427 427 delete tmp_dmake_command;
428 428 */
429 429 dmake_job_msg->appendCmd(new Avo_DmakeCommand(orig_cmd_line, cmd_options));
430 430 }
431 431 #endif
432 432
433 433 #ifdef TEAMWARE_MAKE_CMN
434 434 #define MAXJOBS_ADJUST_RFE4694000
435 435
436 436 #ifdef MAXJOBS_ADJUST_RFE4694000
437 437
438 438 #include <unistd.h> /* sysconf(_SC_NPROCESSORS_ONLN) */
439 439 #include <sys/ipc.h> /* ftok() */
440 440 #include <sys/shm.h> /* shmget(), shmat(), shmdt(), shmctl() */
441 441 #include <semaphore.h> /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */
442 442 #include <sys/loadavg.h> /* getloadavg() */
443 443
444 444 /*
445 445 * adjust_pmake_max_jobs (int pmake_max_jobs)
446 446 *
447 447 * Parameters:
448 448 * pmake_max_jobs - max jobs limit set by user
449 449 *
450 450 * External functions used:
451 451 * sysconf()
452 452 * getloadavg()
453 453 */
454 454 static int
455 455 adjust_pmake_max_jobs (int pmake_max_jobs)
456 456 {
457 457 static int ncpu = 0;
458 458 double loadavg[3];
459 459 int adjustment;
460 460 int adjusted_max_jobs;
461 461
462 462 if (ncpu <= 0) {
463 463 if ((ncpu = sysconf(_SC_NPROCESSORS_ONLN)) <= 0) {
464 464 ncpu = 1;
465 465 }
466 466 }
467 467 if (getloadavg(loadavg, 3) != 3) return(pmake_max_jobs);
468 468 adjustment = ((int)loadavg[LOADAVG_1MIN]);
469 469 if (adjustment < 2) return(pmake_max_jobs);
470 470 if (ncpu > 1) {
471 471 adjustment = adjustment / ncpu;
472 472 }
473 473 adjusted_max_jobs = pmake_max_jobs - adjustment;
474 474 if (adjusted_max_jobs < 1) adjusted_max_jobs = 1;
475 475 return(adjusted_max_jobs);
476 476 }
477 477
478 478 /*
479 479 * M2 adjust mode data and functions
480 480 *
481 481 * m2_init() - initializes M2 shared semaphore
482 482 * m2_acquire_job() - decrements M2 semaphore counter
483 483 * m2_release_job() - increments M2 semaphore counter
484 484 * m2_fini() - destroys M2 semaphore and shared memory*
485 485 *
486 486 * Environment variables:
487 487 * __DMAKE_M2_FILE__
488 488 *
489 489 * External functions:
490 490 * ftok(), shmget(), shmat(), shmdt(), shmctl()
491 491 * sem_init(), sem_trywait(), sem_post(), sem_destroy()
492 492 * creat(), close(), unlink()
493 493 * getenv(), putenv()
494 494 *
495 495 * Static variables:
496 496 * m2_file - tmp file name to create ipc key for shared memory
497 497 * m2_shm_id - shared memory id
498 498 * m2_shm_sem - shared memory semaphore
499 499 */
500 500
501 501 static char m2_file[MAXPATHLEN];
502 502 static int m2_shm_id = -1;
503 503 static sem_t* m2_shm_sem = 0;
504 504
505 505 static int
506 506 m2_init() {
507 507 char *var;
508 508 key_t key;
509 509
510 510 if ((var = getenv(NOCATGETS("__DMAKE_M2_FILE__"))) == 0) {
511 511 /* compose tmp file name */
512 512 sprintf(m2_file, NOCATGETS("%s/dmake.m2.%d.XXXXXX"), tmpdir, getpid());
513 513
514 514 /* create tmp file */
515 515 int fd = mkstemp(m2_file);
516 516 if (fd < 0) {
517 517 return -1;
518 518 } else {
519 519 close(fd);
520 520 }
521 521 } else {
522 522 /* using existing semaphore */
523 523 strcpy(m2_file, var);
524 524 }
525 525
526 526 /* combine IPC key */
527 527 if ((key = ftok(m2_file, 38)) == (key_t) -1) {
528 528 return -1;
529 529 }
530 530
531 531 /* create shared memory */
532 532 if ((m2_shm_id = shmget(key, sizeof(*m2_shm_sem), 0666 | (var ? 0 : IPC_CREAT|IPC_EXCL))) == -1) {
533 533 return -1;
534 534 }
535 535
536 536 /* attach shared memory */
537 537 if ((m2_shm_sem = (sem_t*) shmat(m2_shm_id, 0, 0666)) == (sem_t*)-1) {
538 538 return -1;
539 539 }
540 540
541 541 /* root process */
542 542 if (var == 0) {
543 543 /* initialize semaphore */
544 544 if (sem_init(m2_shm_sem, 1, pmake_max_jobs)) {
545 545 return -1;
546 546 }
547 547
548 548 /* alloc memory for env variable */
549 549 if ((var = (char*) malloc(MAXPATHLEN)) == 0) {
550 550 return -1;
551 551 }
552 552
553 553 /* put key to env */
554 554 sprintf(var, NOCATGETS("__DMAKE_M2_FILE__=%s"), m2_file);
555 555 if (putenv(var)) {
556 556 return -1;
557 557 }
558 558 }
559 559 return 0;
560 560 }
561 561
562 562 static void
563 563 m2_fini() {
564 564 if (m2_shm_id >= 0) {
565 565 struct shmid_ds stat;
566 566
567 567 /* determine the number of attached processes */
568 568 if (shmctl(m2_shm_id, IPC_STAT, &stat) == 0) {
569 569 if (stat.shm_nattch <= 1) {
570 570 /* destroy semaphore */
571 571 if (m2_shm_sem != 0) {
572 572 (void) sem_destroy(m2_shm_sem);
573 573 }
574 574
575 575 /* destroy shared memory */
576 576 (void) shmctl(m2_shm_id, IPC_RMID, &stat);
577 577
578 578 /* remove tmp file created for the key */
579 579 (void) unlink(m2_file);
580 580 } else {
581 581 /* detach shared memory */
582 582 if (m2_shm_sem != 0) {
583 583 (void) shmdt((char*) m2_shm_sem);
584 584 }
585 585 }
586 586 }
587 587
588 588 m2_shm_id = -1;
589 589 m2_shm_sem = 0;
590 590 }
591 591 }
592 592
593 593 static int
594 594 m2_acquire_job() {
595 595 if ((m2_shm_id >= 0) && (m2_shm_sem != 0)) {
596 596 if (sem_trywait(m2_shm_sem) == 0) {
597 597 return 1;
598 598 }
599 599 if (errno == EAGAIN) {
600 600 return 0;
601 601 }
602 602 }
603 603 return -1;
604 604 }
605 605
606 606 static int
607 607 m2_release_job() {
608 608 if ((m2_shm_id >= 0) && (m2_shm_sem != 0)) {
609 609 if (sem_post(m2_shm_sem) == 0) {
610 610 return 0;
611 611 }
612 612 }
613 613 return -1;
614 614 }
615 615
616 616 /*
617 617 * job adjust mode
618 618 *
619 619 * Possible values:
620 620 * ADJUST_M1 - adjustment by system load (default)
621 621 * ADJUST_M2 - fixed limit of jobs for the group of nested dmakes
622 622 * ADJUST_NONE - no adjustment - fixed limit of jobs for the current dmake
623 623 */
624 624 static enum {
625 625 ADJUST_UNKNOWN,
626 626 ADJUST_M1,
627 627 ADJUST_M2,
628 628 ADJUST_NONE
629 629 } job_adjust_mode = ADJUST_UNKNOWN;
630 630
631 631 /*
632 632 * void job_adjust_fini()
633 633 *
634 634 * Description:
635 635 * Cleans up job adjust data.
636 636 *
637 637 * Static variables:
638 638 * job_adjust_mode Current job adjust mode
639 639 */
640 640 void
641 641 job_adjust_fini() {
642 642 if (job_adjust_mode == ADJUST_M2) {
643 643 m2_fini();
644 644 }
645 645 }
646 646
647 647 /*
648 648 * void job_adjust_error()
649 649 *
650 650 * Description:
651 651 * Prints warning message, cleans up job adjust data, and disables job adjustment
652 652 *
653 653 * Environment:
654 654 * DMAKE_ADJUST_MAX_JOBS
655 655 *
656 656 * External functions:
657 657 * putenv()
658 658 *
659 659 * Static variables:
660 660 * job_adjust_mode Current job adjust mode
661 661 */
662 662 static void
663 663 job_adjust_error() {
664 664 if (job_adjust_mode != ADJUST_NONE) {
665 665 /* cleanup internals */
666 666 job_adjust_fini();
667 667
668 668 /* warning message for the user */
669 669 warning(catgets(catd, 1, 339, "Encountered max jobs auto adjustment error - disabling auto adjustment."));
670 670
671 671 /* switch off job adjustment for the children */
672 672 putenv(NOCATGETS("DMAKE_ADJUST_MAX_JOBS=NO"));
673 673
674 674 /* and for this dmake */
675 675 job_adjust_mode = ADJUST_NONE;
676 676 }
677 677 }
678 678
679 679 /*
680 680 * void job_adjust_init()
681 681 *
682 682 * Description:
683 683 * Parses DMAKE_ADJUST_MAX_JOBS env variable
684 684 * and performs appropriate initializations.
685 685 *
686 686 * Environment:
687 687 * DMAKE_ADJUST_MAX_JOBS
688 688 * DMAKE_ADJUST_MAX_JOBS == "NO" - no adjustment
689 689 * DMAKE_ADJUST_MAX_JOBS == "M2" - M2 adjust mode
690 690 * other - M1 adjust mode
691 691 *
692 692 * External functions:
693 693 * getenv()
694 694 *
695 695 * Static variables:
696 696 * job_adjust_mode Current job adjust mode
697 697 */
698 698 static void
699 699 job_adjust_init() {
700 700 if (job_adjust_mode == ADJUST_UNKNOWN) {
701 701 /* default mode */
702 702 job_adjust_mode = ADJUST_M1;
703 703
704 704 /* determine adjust mode */
705 705 if (char *var = getenv(NOCATGETS("DMAKE_ADJUST_MAX_JOBS"))) {
706 706 if (strcasecmp(var, NOCATGETS("NO")) == 0) {
707 707 job_adjust_mode = ADJUST_NONE;
708 708 } else if (strcasecmp(var, NOCATGETS("M2")) == 0) {
709 709 job_adjust_mode = ADJUST_M2;
710 710 }
711 711 }
712 712
713 713 /* M2 specific initialization */
714 714 if (job_adjust_mode == ADJUST_M2) {
715 715 if (m2_init()) {
716 716 job_adjust_error();
717 717 }
718 718 }
719 719 }
720 720 }
721 721
722 722 #endif /* MAXJOBS_ADJUST_RFE4694000 */
723 723 #endif /* TEAMWARE_MAKE_CMN */
724 724
725 725 /*
726 726 * distribute_process(char **commands, Property line)
727 727 *
728 728 * Parameters:
729 729 * commands argv vector of commands to execute
730 730 *
731 731 * Return value:
732 732 * The result of the execution
733 733 *
734 734 * Static variables used:
735 735 * process_running Set to the pid of the process set running
736 736 * #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
737 737 * job_adjust_mode Current job adjust mode
738 738 * #endif
739 739 */
740 740 static Doname
741 741 distribute_process(char **commands, Property line)
742 742 {
743 743 static unsigned file_number = 0;
744 744 wchar_t string[MAXPATHLEN];
745 745 char mbstring[MAXPATHLEN];
746 746 int filed;
747 747 int res;
748 748 int tmp_index;
749 749 char *tmp_index_str_ptr;
750 750
751 751 #if !defined (TEAMWARE_MAKE_CMN) || !defined (MAXJOBS_ADJUST_RFE4694000)
752 752 while (parallel_process_cnt >= pmake_max_jobs) {
753 753 await_parallel(false);
754 754 finish_children(true);
755 755 }
756 756 #else /* TEAMWARE_MAKE_CMN && MAXJOBS_ADJUST_RFE4694000 */
757 757 /* initialize adjust mode, if not initialized */
758 758 if (job_adjust_mode == ADJUST_UNKNOWN) {
759 759 job_adjust_init();
760 760 }
761 761
762 762 /* actions depend on adjust mode */
763 763 switch (job_adjust_mode) {
764 764 case ADJUST_M1:
765 765 while (parallel_process_cnt >= adjust_pmake_max_jobs (pmake_max_jobs)) {
766 766 await_parallel(false);
767 767 finish_children(true);
768 768 }
769 769 break;
770 770 case ADJUST_M2:
771 771 if ((res = m2_acquire_job()) == 0) {
772 772 if (parallel_process_cnt > 0) {
773 773 await_parallel(false);
774 774 finish_children(true);
775 775
776 776 if ((res = m2_acquire_job()) == 0) {
777 777 return build_serial;
778 778 }
779 779 } else {
780 780 return build_serial;
781 781 }
782 782 }
783 783 if (res < 0) {
784 784 /* job adjustment error */
785 785 job_adjust_error();
786 786
787 787 /* no adjustment */
788 788 while (parallel_process_cnt >= pmake_max_jobs) {
789 789 await_parallel(false);
790 790 finish_children(true);
791 791 }
792 792 }
793 793 break;
794 794 default:
795 795 while (parallel_process_cnt >= pmake_max_jobs) {
796 796 await_parallel(false);
797 797 finish_children(true);
798 798 }
799 799 }
800 800 #endif /* TEAMWARE_MAKE_CMN && MAXJOBS_ADJUST_RFE4694000 */
801 801 #ifdef DISTRIBUTED
802 802 if (send_mtool_msgs) {
803 803 send_job_start_msg(line);
804 804 }
805 805 #endif
806 806 #ifdef DISTRIBUTED
807 807 setvar_envvar((Avo_DoJobMsg *)NULL);
808 808 #else
809 809 setvar_envvar();
810 810 #endif
811 811 /*
812 812 * Tell the user what DMake is doing.
813 813 */
814 814 if (!silent && output_mode != txt2_mode) {
815 815 /*
816 816 * Print local_host --> x job(s).
817 817 */
818 818 (void) fprintf(stdout,
819 819 catgets(catd, 1, 325, "%s --> %d %s\n"),
820 820 local_host,
821 821 parallel_process_cnt + 1,
822 822 (parallel_process_cnt == 0) ? catgets(catd, 1, 124, "job") : catgets(catd, 1, 125, "jobs"));
823 823
824 824 /* Print command line(s). */
825 825 tmp_index = 0;
826 826 while (commands[tmp_index] != NULL) {
827 827 /* No @ char. */
828 828 /* XXX - need to add [2] when + prefix is added */
829 829 if ((commands[tmp_index][0] != (int) at_char) &&
830 830 (commands[tmp_index][1] != (int) at_char)) {
831 831 tmp_index_str_ptr = commands[tmp_index];
832 832 if (*tmp_index_str_ptr == (int) hyphen_char) {
833 833 tmp_index_str_ptr++;
834 834 }
835 835 (void) fprintf(stdout, "%s\n", tmp_index_str_ptr);
836 836 }
837 837 tmp_index++;
838 838 }
839 839 (void) fflush(stdout);
840 840 }
841 841
↓ open down ↓ |
841 lines elided |
↑ open up ↑ |
842 842 (void) sprintf(mbstring,
843 843 NOCATGETS("%s/dmake.stdout.%d.%d.XXXXXX"),
844 844 tmpdir,
845 845 getpid(),
846 846 file_number++);
847 847
848 848 mktemp(mbstring);
849 849
850 850 stdout_file = strdup(mbstring);
851 851 stderr_file = NULL;
852 -#if defined (TEAMWARE_MAKE_CMN) && defined(REDIRECT_ERR)
852 +#if defined (TEAMWARE_MAKE_CMN)
853 853 if (!out_err_same) {
854 854 (void) sprintf(mbstring,
855 855 NOCATGETS("%s/dmake.stderr.%d.%d.XXXXXX"),
856 856 tmpdir,
857 857 getpid(),
858 858 file_number++);
859 859
860 860 mktemp(mbstring);
861 861
862 862 stderr_file = strdup(mbstring);
863 863 }
864 864 #endif
865 865
866 866 process_running = run_rule_commands(local_host, commands);
867 867
868 868 return build_running;
869 869 }
870 870
871 871 /*
872 872 * doname_parallel(target, do_get, implicit)
873 873 *
874 874 * Processes the given target and finishes up any parallel
875 875 * processes left running.
876 876 *
877 877 * Return value:
878 878 * Result of target build
879 879 *
880 880 * Parameters:
881 881 * target Target to build
882 882 * do_get True if sccs get to be done
883 883 * implicit True if this is an implicit target
884 884 */
885 885 Doname
886 886 doname_parallel(Name target, Boolean do_get, Boolean implicit)
887 887 {
888 888 Doname result;
889 889
890 890 result = doname_check(target, do_get, implicit, false);
891 891 if (result == build_ok || result == build_failed) {
892 892 return result;
893 893 }
894 894 finish_running();
895 895 return (Doname) target->state;
896 896 }
897 897
898 898 /*
899 899 * doname_subtree(target, do_get, implicit)
900 900 *
901 901 * Completely computes an object and its dependents for a
902 902 * serial subtree build.
903 903 *
904 904 * Parameters:
905 905 * target Target to build
906 906 * do_get True if sccs get to be done
907 907 * implicit True if this is an implicit target
908 908 *
909 909 * Static variables used:
910 910 * running_tail Tail of the list of running processes
911 911 *
912 912 * Global variables used:
913 913 * running_list The list of running processes
914 914 */
915 915 static void
916 916 doname_subtree(Name target, Boolean do_get, Boolean implicit)
917 917 {
918 918 Running save_running_list;
919 919 Running *save_running_tail;
920 920
921 921 save_running_list = running_list;
922 922 save_running_tail = running_tail;
923 923 running_list = NULL;
924 924 running_tail = &running_list;
925 925 target->state = build_subtree;
926 926 target->checking_subtree = true;
927 927 while(doname_check(target, do_get, implicit, false) == build_running) {
928 928 target->checking_subtree = false;
929 929 finish_running();
930 930 target->state = build_subtree;
931 931 }
932 932 target->checking_subtree = false;
933 933 running_list = save_running_list;
934 934 running_tail = save_running_tail;
935 935 }
936 936
937 937 /*
938 938 * finish_running()
939 939 *
940 940 * Keeps processing until the running_list is emptied out.
941 941 *
942 942 * Parameters:
943 943 *
944 944 * Global variables used:
945 945 * running_list The list of running processes
946 946 */
947 947 void
948 948 finish_running(void)
949 949 {
950 950 while (running_list != NULL) {
951 951 #ifdef DISTRIBUTED
952 952 if (dmake_mode_type == distributed_mode) {
953 953 if ((just_did_subtree) ||
954 954 (parallel_process_cnt == 0)) {
955 955 just_did_subtree = false;
956 956 } else {
957 957 (void) await_dist(false);
958 958 finish_children(true);
959 959 }
960 960 } else
961 961 #endif
962 962 {
963 963 await_parallel(false);
964 964 finish_children(true);
965 965 }
966 966 if (running_list != NULL) {
967 967 process_next();
968 968 }
969 969 }
970 970 }
971 971
972 972 /*
973 973 * process_next()
974 974 *
975 975 * Searches the running list for any targets which can start processing.
976 976 * This can be a pending target, a serial target, or a subtree target.
977 977 *
978 978 * Parameters:
979 979 *
980 980 * Static variables used:
981 981 * running_tail The end of the list of running procs
982 982 * subtree_conflict A target which conflicts with a subtree
983 983 * subtree_conflict2 The other target which conflicts
984 984 *
985 985 * Global variables used:
986 986 * commands_done True if commands executed
987 987 * debug_level Controls debug output
988 988 * parallel_process_cnt Number of parallel process running
989 989 * recursion_level Indentation for debug output
990 990 * running_list List of running processes
991 991 */
992 992 static void
993 993 process_next(void)
994 994 {
995 995 Running rp;
996 996 Running *rp_prev;
997 997 Property line;
998 998 Chain target_group;
999 999 Dependency dep;
1000 1000 Boolean quiescent = true;
1001 1001 Running *subtree_target;
1002 1002 Boolean saved_commands_done;
1003 1003 Property *conditionals;
1004 1004
1005 1005 subtree_target = NULL;
1006 1006 subtree_conflict = NULL;
1007 1007 subtree_conflict2 = NULL;
1008 1008 /*
1009 1009 * If nothing currently running, build a serial target, if any.
1010 1010 */
1011 1011 start_loop_1:
1012 1012 for (rp_prev = &running_list, rp = running_list;
1013 1013 rp != NULL && parallel_process_cnt == 0;
1014 1014 rp = rp->next) {
1015 1015 if (rp->state == build_serial) {
1016 1016 *rp_prev = rp->next;
1017 1017 if (rp->next == NULL) {
1018 1018 running_tail = rp_prev;
1019 1019 }
1020 1020 recursion_level = rp->recursion_level;
1021 1021 rp->target->state = build_pending;
1022 1022 (void) doname_check(rp->target,
1023 1023 rp->do_get,
1024 1024 rp->implicit,
1025 1025 false);
1026 1026 quiescent = false;
1027 1027 delete_running_struct(rp);
1028 1028 goto start_loop_1;
1029 1029 } else {
1030 1030 rp_prev = &rp->next;
1031 1031 }
1032 1032 }
1033 1033 /*
1034 1034 * Find a target to build. The target must be pending, have all
1035 1035 * its dependencies built, and not be in a target group with a target
1036 1036 * currently building.
1037 1037 */
1038 1038 start_loop_2:
1039 1039 for (rp_prev = &running_list, rp = running_list;
1040 1040 rp != NULL;
1041 1041 rp = rp->next) {
1042 1042 if (!(rp->state == build_pending ||
1043 1043 rp->state == build_subtree)) {
1044 1044 quiescent = false;
1045 1045 rp_prev = &rp->next;
1046 1046 } else if (rp->state == build_pending) {
1047 1047 line = get_prop(rp->target->prop, line_prop);
1048 1048 for (dep = line->body.line.dependencies;
1049 1049 dep != NULL;
1050 1050 dep = dep->next) {
1051 1051 if (dep->name->state == build_running ||
1052 1052 dep->name->state == build_pending ||
1053 1053 dep->name->state == build_serial) {
1054 1054 break;
1055 1055 }
1056 1056 }
1057 1057 if (dep == NULL) {
1058 1058 for (target_group = line->body.line.target_group;
1059 1059 target_group != NULL;
1060 1060 target_group = target_group->next) {
1061 1061 if (is_running(target_group->name)) {
1062 1062 break;
1063 1063 }
1064 1064 }
1065 1065 if (target_group == NULL) {
1066 1066 *rp_prev = rp->next;
1067 1067 if (rp->next == NULL) {
1068 1068 running_tail = rp_prev;
1069 1069 }
1070 1070 recursion_level = rp->recursion_level;
1071 1071 rp->target->state = rp->redo ?
1072 1072 build_dont_know : build_pending;
1073 1073 saved_commands_done = commands_done;
1074 1074 conditionals =
1075 1075 set_conditionals
1076 1076 (rp->conditional_cnt,
1077 1077 rp->conditional_targets);
1078 1078 rp->target->dont_activate_cond_values = true;
1079 1079 if ((doname_check(rp->target,
1080 1080 rp->do_get,
1081 1081 rp->implicit,
1082 1082 rp->target->has_target_prop ? true : false) !=
1083 1083 build_running) &&
1084 1084 !commands_done) {
1085 1085 commands_done =
1086 1086 saved_commands_done;
1087 1087 }
1088 1088 rp->target->dont_activate_cond_values = false;
1089 1089 reset_conditionals
1090 1090 (rp->conditional_cnt,
1091 1091 rp->conditional_targets,
1092 1092 conditionals);
1093 1093 quiescent = false;
1094 1094 delete_running_struct(rp);
1095 1095 goto start_loop_2;
1096 1096 } else {
1097 1097 rp_prev = &rp->next;
1098 1098 }
1099 1099 } else {
1100 1100 rp_prev = &rp->next;
1101 1101 }
1102 1102 } else {
1103 1103 rp_prev = &rp->next;
1104 1104 }
1105 1105 }
1106 1106 /*
1107 1107 * If nothing has been found to build and there exists a subtree
1108 1108 * target with no dependency conflicts, build it.
1109 1109 */
1110 1110 if (quiescent) {
1111 1111 start_loop_3:
1112 1112 for (rp_prev = &running_list, rp = running_list;
1113 1113 rp != NULL;
1114 1114 rp = rp->next) {
1115 1115 if (rp->state == build_subtree) {
1116 1116 if (!dependency_conflict(rp->target)) {
1117 1117 *rp_prev = rp->next;
1118 1118 if (rp->next == NULL) {
1119 1119 running_tail = rp_prev;
1120 1120 }
1121 1121 recursion_level = rp->recursion_level;
1122 1122 doname_subtree(rp->target,
1123 1123 rp->do_get,
1124 1124 rp->implicit);
1125 1125 #ifdef DISTRIBUTED
1126 1126 just_did_subtree = true;
1127 1127 #endif
1128 1128 quiescent = false;
1129 1129 delete_running_struct(rp);
1130 1130 goto start_loop_3;
1131 1131 } else {
1132 1132 subtree_target = rp_prev;
1133 1133 rp_prev = &rp->next;
1134 1134 }
1135 1135 } else {
1136 1136 rp_prev = &rp->next;
1137 1137 }
1138 1138 }
1139 1139 }
1140 1140 /*
1141 1141 * If still nothing found to build, we either have a deadlock
1142 1142 * or a subtree with a dependency conflict with something waiting
1143 1143 * to build.
1144 1144 */
1145 1145 if (quiescent) {
1146 1146 if (subtree_target == NULL) {
1147 1147 fatal(catgets(catd, 1, 126, "Internal error: deadlock detected in process_next"));
1148 1148 } else {
1149 1149 rp = *subtree_target;
1150 1150 if (debug_level > 0) {
1151 1151 warning(catgets(catd, 1, 127, "Conditional macro conflict encountered for %s between %s and %s"),
1152 1152 subtree_conflict2->string_mb,
1153 1153 rp->target->string_mb,
1154 1154 subtree_conflict->string_mb);
1155 1155 }
1156 1156 *subtree_target = (*subtree_target)->next;
1157 1157 if (rp->next == NULL) {
1158 1158 running_tail = subtree_target;
1159 1159 }
1160 1160 recursion_level = rp->recursion_level;
1161 1161 doname_subtree(rp->target, rp->do_get, rp->implicit);
1162 1162 #ifdef DISTRIBUTED
1163 1163 just_did_subtree = true;
1164 1164 #endif
1165 1165 delete_running_struct(rp);
1166 1166 }
1167 1167 }
1168 1168 }
1169 1169
1170 1170 /*
1171 1171 * set_conditionals(cnt, targets)
1172 1172 *
1173 1173 * Sets the conditional macros for the targets given in the array of
1174 1174 * targets. The old macro values are returned in an array of
1175 1175 * Properties for later resetting.
1176 1176 *
1177 1177 * Return value:
1178 1178 * Array of conditional macro settings
1179 1179 *
1180 1180 * Parameters:
1181 1181 * cnt Number of targets
1182 1182 * targets Array of targets
1183 1183 */
1184 1184 static Property *
1185 1185 set_conditionals(int cnt, Name *targets)
1186 1186 {
1187 1187 Property *locals, *lp;
1188 1188 Name *tp;
1189 1189
1190 1190 locals = (Property *) getmem(cnt * sizeof(Property));
1191 1191 for (lp = locals, tp = targets;
1192 1192 cnt > 0;
1193 1193 cnt--, lp++, tp++) {
1194 1194 *lp = (Property) getmem((*tp)->conditional_cnt *
1195 1195 sizeof(struct _Property));
1196 1196 set_locals(*tp, *lp);
1197 1197 }
1198 1198 return locals;
1199 1199 }
1200 1200
1201 1201 /*
1202 1202 * reset_conditionals(cnt, targets, locals)
1203 1203 *
1204 1204 * Resets the conditional macros as saved in the given array of
1205 1205 * Properties. The resets are done in reverse order. Afterwards the
1206 1206 * data structures are freed.
1207 1207 *
1208 1208 * Parameters:
1209 1209 * cnt Number of targets
1210 1210 * targets Array of targets
1211 1211 * locals Array of dependency macro settings
1212 1212 */
1213 1213 static void
1214 1214 reset_conditionals(int cnt, Name *targets, Property *locals)
1215 1215 {
1216 1216 Name *tp;
1217 1217 Property *lp;
1218 1218
1219 1219 for (tp = targets + (cnt - 1), lp = locals + (cnt - 1);
1220 1220 cnt > 0;
1221 1221 cnt--, tp--, lp--) {
1222 1222 reset_locals(*tp,
1223 1223 *lp,
1224 1224 get_prop((*tp)->prop, conditional_prop),
1225 1225 0);
1226 1226 retmem_mb((caddr_t) *lp);
1227 1227 }
1228 1228 retmem_mb((caddr_t) locals);
1229 1229 }
1230 1230
1231 1231 /*
1232 1232 * dependency_conflict(target)
1233 1233 *
1234 1234 * Returns true if there is an intersection between
1235 1235 * the subtree of the target and any dependents of the pending targets.
1236 1236 *
1237 1237 * Return value:
1238 1238 * True if conflict found
1239 1239 *
1240 1240 * Parameters:
1241 1241 * target Subtree target to check
1242 1242 *
1243 1243 * Static variables used:
1244 1244 * subtree_conflict Target conflict found
1245 1245 * subtree_conflict2 Second conflict found
1246 1246 *
1247 1247 * Global variables used:
1248 1248 * running_list List of running processes
1249 1249 * wait_name .WAIT, not a real dependency
1250 1250 */
1251 1251 static Boolean
1252 1252 dependency_conflict(Name target)
1253 1253 {
1254 1254 Property line;
1255 1255 Property pending_line;
1256 1256 Dependency dp;
1257 1257 Dependency pending_dp;
1258 1258 Running rp;
1259 1259
1260 1260 /* Return if we are already checking this target */
1261 1261 if (target->checking_subtree) {
1262 1262 return false;
1263 1263 }
1264 1264 target->checking_subtree = true;
1265 1265 line = get_prop(target->prop, line_prop);
1266 1266 if (line == NULL) {
1267 1267 target->checking_subtree = false;
1268 1268 return false;
1269 1269 }
1270 1270 /* Check each dependency of the target for conflicts */
1271 1271 for (dp = line->body.line.dependencies; dp != NULL; dp = dp->next) {
1272 1272 /* Ignore .WAIT dependency */
1273 1273 if (dp->name == wait_name) {
1274 1274 continue;
1275 1275 }
1276 1276 /*
1277 1277 * For each pending target, look for a dependency which
1278 1278 * is the same as a dependency of the subtree target. Since
1279 1279 * we can't build the subtree until all pending targets have
1280 1280 * finished which depend on the same dependency, this is
1281 1281 * a conflict.
1282 1282 */
1283 1283 for (rp = running_list; rp != NULL; rp = rp->next) {
1284 1284 if (rp->state == build_pending) {
1285 1285 pending_line = get_prop(rp->target->prop,
1286 1286 line_prop);
1287 1287 if (pending_line == NULL) {
1288 1288 continue;
1289 1289 }
1290 1290 for(pending_dp = pending_line->
1291 1291 body.line.dependencies;
1292 1292 pending_dp != NULL;
1293 1293 pending_dp = pending_dp->next) {
1294 1294 if (dp->name == pending_dp->name) {
1295 1295 target->checking_subtree
1296 1296 = false;
1297 1297 subtree_conflict = rp->target;
1298 1298 subtree_conflict2 = dp->name;
1299 1299 return true;
1300 1300 }
1301 1301 }
1302 1302 }
1303 1303 }
1304 1304 if (dependency_conflict(dp->name)) {
1305 1305 target->checking_subtree = false;
1306 1306 return true;
1307 1307 }
1308 1308 }
1309 1309 target->checking_subtree = false;
1310 1310 return false;
1311 1311 }
1312 1312
1313 1313 /*
1314 1314 * await_parallel(waitflg)
1315 1315 *
1316 1316 * Waits for parallel children to exit and finishes their processing.
1317 1317 * If waitflg is false, the function returns after update_delay.
1318 1318 *
1319 1319 * Parameters:
1320 1320 * waitflg dwight
1321 1321 */
1322 1322 void
1323 1323 await_parallel(Boolean waitflg)
1324 1324 {
1325 1325 Boolean nohang;
1326 1326 pid_t pid;
1327 1327 int status;
1328 1328 Running rp;
1329 1329 int waiterr;
1330 1330
1331 1331 nohang = false;
1332 1332 for ( ; ; ) {
1333 1333 if (!nohang) {
1334 1334 (void) alarm((int) update_delay);
1335 1335 }
1336 1336 pid = waitpid((pid_t)-1,
1337 1337 &status,
1338 1338 nohang ? WNOHANG : 0);
1339 1339 waiterr = errno;
1340 1340 if (!nohang) {
1341 1341 (void) alarm(0);
1342 1342 }
1343 1343 if (pid <= 0) {
1344 1344 if (waiterr == EINTR) {
1345 1345 if (waitflg) {
1346 1346 continue;
1347 1347 } else {
1348 1348 return;
1349 1349 }
1350 1350 } else {
1351 1351 return;
1352 1352 }
1353 1353 }
1354 1354 for (rp = running_list;
1355 1355 (rp != NULL) && (rp->pid != pid);
1356 1356 rp = rp->next) {
1357 1357 ;
1358 1358 }
1359 1359 if (rp == NULL) {
1360 1360 if (send_mtool_msgs) {
1361 1361 continue;
1362 1362 } else {
1363 1363 fatal(catgets(catd, 1, 128, "Internal error: returned child pid not in running_list"));
1364 1364 }
1365 1365 } else {
1366 1366 rp->state = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? build_ok : build_failed;
1367 1367 }
1368 1368 nohang = true;
1369 1369 parallel_process_cnt--;
1370 1370
1371 1371 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
1372 1372 if (job_adjust_mode == ADJUST_M2) {
1373 1373 if (m2_release_job()) {
1374 1374 job_adjust_error();
1375 1375 }
1376 1376 }
1377 1377 #endif
1378 1378 }
1379 1379 }
1380 1380
1381 1381 /*
1382 1382 * finish_children(docheck)
1383 1383 *
1384 1384 * Finishes the processing for all targets which were running
1385 1385 * and have now completed.
1386 1386 *
1387 1387 * Parameters:
1388 1388 * docheck Completely check the finished target
1389 1389 *
1390 1390 * Static variables used:
1391 1391 * running_tail The tail of the running list
1392 1392 *
1393 1393 * Global variables used:
1394 1394 * continue_after_error -k flag
1395 1395 * fatal_in_progress True if we are finishing up after fatal err
1396 1396 * running_list List of running processes
1397 1397 */
1398 1398 void
1399 1399 finish_children(Boolean docheck)
1400 1400 {
1401 1401 int cmds_length;
1402 1402 Property line;
1403 1403 Property line2;
1404 1404 struct stat out_buf;
1405 1405 Running rp;
1406 1406 Running *rp_prev;
1407 1407 Cmd_line rule;
1408 1408 Boolean silent_flag;
1409 1409
1410 1410 for (rp_prev = &running_list, rp = running_list;
1411 1411 rp != NULL;
1412 1412 rp = rp->next) {
1413 1413 bypass_for_loop_inc_4:
1414 1414 /*
1415 1415 * If the state is ok or failed, then this target has
1416 1416 * finished building.
1417 1417 * In parallel_mode, output the accumulated stdout/stderr.
1418 1418 * Read the auto dependency stuff, handle a failed build,
1419 1419 * update the target, then finish the doname process for
1420 1420 * that target.
1421 1421 */
1422 1422 if (rp->state == build_ok || rp->state == build_failed) {
1423 1423 *rp_prev = rp->next;
1424 1424 if (rp->next == NULL) {
1425 1425 running_tail = rp_prev;
1426 1426 }
1427 1427 if ((line2 = rp->command) == NULL) {
1428 1428 line2 = get_prop(rp->target->prop, line_prop);
1429 1429 }
1430 1430 if (dmake_mode_type == distributed_mode) {
1431 1431 if (rp->make_refd) {
1432 1432 maybe_reread_make_state();
1433 1433 }
1434 1434 } else {
1435 1435 /*
1436 1436 * Send an Avo_MToolJobResultMsg to maketool.
1437 1437 */
1438 1438 #ifdef DISTRIBUTED
1439 1439 if (send_mtool_msgs) {
1440 1440 send_job_result_msg(rp);
1441 1441 }
1442 1442 #endif
1443 1443 /*
1444 1444 * Check if there were any job output
1445 1445 * from the parallel build.
1446 1446 */
1447 1447 if (rp->stdout_file != NULL) {
1448 1448 if (stat(rp->stdout_file, &out_buf) < 0) {
1449 1449 fatal(catgets(catd, 1, 130, "stat of %s failed: %s"),
1450 1450 rp->stdout_file,
1451 1451 errmsg(errno));
1452 1452 }
1453 1453 if ((line2 != NULL) &&
1454 1454 (out_buf.st_size > 0)) {
1455 1455 cmds_length = 0;
1456 1456 for (rule = line2->body.line.command_used,
1457 1457 silent_flag = silent;
1458 1458 rule != NULL;
1459 1459 rule = rule->next) {
1460 1460 cmds_length += rule->command_line->hash.length + 1;
1461 1461 silent_flag = BOOLEAN(silent_flag || rule->silent);
↓ open down ↓ |
599 lines elided |
↑ open up ↑ |
1462 1462 }
1463 1463 if (out_buf.st_size != cmds_length || silent_flag ||
1464 1464 output_mode == txt2_mode) {
1465 1465 dump_out_file(rp->stdout_file, false);
1466 1466 }
1467 1467 }
1468 1468 (void) unlink(rp->stdout_file);
1469 1469 retmem_mb(rp->stdout_file);
1470 1470 rp->stdout_file = NULL;
1471 1471 }
1472 -#if defined(REDIRECT_ERR)
1472 +
1473 1473 if (!out_err_same && (rp->stderr_file != NULL)) {
1474 1474 if (stat(rp->stderr_file, &out_buf) < 0) {
1475 1475 fatal(catgets(catd, 1, 130, "stat of %s failed: %s"),
1476 1476 rp->stderr_file,
1477 1477 errmsg(errno));
1478 1478 }
1479 1479 if ((line2 != NULL) &&
1480 1480 (out_buf.st_size > 0)) {
1481 1481 dump_out_file(rp->stderr_file, true);
1482 1482 }
1483 1483 (void) unlink(rp->stderr_file);
1484 1484 retmem_mb(rp->stderr_file);
1485 1485 rp->stderr_file = NULL;
1486 1486 }
1487 -#endif
1488 1487 }
1489 1488 check_state(rp->temp_file);
1490 1489 if (rp->temp_file != NULL) {
1491 1490 free_name(rp->temp_file);
1492 1491 }
1493 1492 rp->temp_file = NULL;
1494 1493 if (rp->state == build_failed) {
1495 1494 line = get_prop(rp->target->prop, line_prop);
1496 1495 if (line != NULL) {
1497 1496 line->body.line.command_used = NULL;
1498 1497 }
1499 1498 if (continue_after_error ||
1500 1499 fatal_in_progress ||
1501 1500 !docheck) {
1502 1501 warning(catgets(catd, 1, 256, "Command failed for target `%s'"),
1503 1502 rp->command ? line2->body.line.target->string_mb : rp->target->string_mb);
1504 1503 build_failed_seen = true;
1505 1504 } else {
1506 1505 /*
1507 1506 * XXX??? - DMake needs to exit(),
1508 1507 * but shouldn't call fatal().
1509 1508 */
1510 1509 #ifdef PRINT_EXIT_STATUS
1511 1510 warning(NOCATGETS("I'm in finish_children. rp->state == build_failed."));
1512 1511 #endif
1513 1512
1514 1513 fatal(catgets(catd, 1, 258, "Command failed for target `%s'"),
1515 1514 rp->command ? line2->body.line.target->string_mb : rp->target->string_mb);
1516 1515 }
1517 1516 }
1518 1517 if (!docheck) {
1519 1518 delete_running_struct(rp);
1520 1519 rp = *rp_prev;
1521 1520 if (rp == NULL) {
1522 1521 break;
1523 1522 } else {
1524 1523 goto bypass_for_loop_inc_4;
1525 1524 }
1526 1525 }
1527 1526 update_target(get_prop(rp->target->prop, line_prop),
1528 1527 rp->state);
1529 1528 finish_doname(rp);
1530 1529 delete_running_struct(rp);
1531 1530 rp = *rp_prev;
1532 1531 if (rp == NULL) {
1533 1532 break;
1534 1533 } else {
1535 1534 goto bypass_for_loop_inc_4;
1536 1535 }
1537 1536 } else {
1538 1537 rp_prev = &rp->next;
1539 1538 }
1540 1539 }
1541 1540 }
1542 1541
1543 1542 /*
1544 1543 * dump_out_file(filename, err)
1545 1544 *
1546 1545 * Write the contents of the file to stdout, then unlink the file.
1547 1546 *
1548 1547 * Parameters:
1549 1548 * filename Name of temp file containing output
1550 1549 *
1551 1550 * Global variables used:
1552 1551 */
1553 1552 static void
1554 1553 dump_out_file(char *filename, Boolean err)
1555 1554 {
1556 1555 int chars_read;
1557 1556 char copybuf[BUFSIZ];
1558 1557 int fd;
1559 1558 int out_fd = (err ? 2 : 1);
1560 1559
1561 1560 if ((fd = open(filename, O_RDONLY)) < 0) {
1562 1561 fatal(catgets(catd, 1, 141, "open failed for output file %s: %s"),
1563 1562 filename,
1564 1563 errmsg(errno));
1565 1564 }
1566 1565 if (!silent && output_mode != txt2_mode) {
1567 1566 (void) fprintf(err ? stderr : stdout,
1568 1567 err ?
1569 1568 catgets(catd, 1, 338, "%s --> Job errors\n") :
1570 1569 catgets(catd, 1, 259, "%s --> Job output\n"),
1571 1570 local_host);
1572 1571 (void) fflush(err ? stderr : stdout);
1573 1572 }
1574 1573 for (chars_read = read(fd, copybuf, BUFSIZ);
1575 1574 chars_read > 0;
1576 1575 chars_read = read(fd, copybuf, BUFSIZ)) {
1577 1576 /*
1578 1577 * Read buffers from the source file until end or error.
1579 1578 */
1580 1579 if (write(out_fd, copybuf, chars_read) < 0) {
1581 1580 fatal(catgets(catd, 1, 260, "write failed for output file %s: %s"),
1582 1581 filename,
1583 1582 errmsg(errno));
1584 1583 }
1585 1584 }
1586 1585 (void) close(fd);
1587 1586 (void) unlink(filename);
1588 1587 }
1589 1588
1590 1589 /*
1591 1590 * finish_doname(rp)
1592 1591 *
1593 1592 * Completes the processing for a target which was left running.
1594 1593 *
1595 1594 * Parameters:
1596 1595 * rp Running list entry for target
1597 1596 *
1598 1597 * Global variables used:
1599 1598 * debug_level Debug flag
1600 1599 * recursion_level Indentation for debug output
1601 1600 */
1602 1601 static void
1603 1602 finish_doname(Running rp)
1604 1603 {
1605 1604 int auto_count = rp->auto_count;
1606 1605 Name *automatics = rp->automatics;
1607 1606 Doname result = rp->state;
1608 1607 Name target = rp->target;
1609 1608 Name true_target = rp->true_target;
1610 1609 Property *conditionals;
1611 1610
1612 1611 recursion_level = rp->recursion_level;
1613 1612 if (result == build_ok) {
1614 1613 if (true_target == NULL) {
1615 1614 (void) printf(NOCATGETS("Target = %s\n"), target->string_mb);
1616 1615 (void) printf(NOCATGETS(" State = %d\n"), result);
1617 1616 fatal(NOCATGETS("Internal error: NULL true_target in finish_doname"));
1618 1617 }
1619 1618 /* If all went OK, set a nice timestamp */
1620 1619 if (true_target->stat.time == file_doesnt_exist) {
1621 1620 true_target->stat.time = file_max_time;
1622 1621 }
1623 1622 }
1624 1623 target->state = result;
1625 1624 if (target->is_member) {
1626 1625 Property member;
1627 1626
1628 1627 /* Propagate the timestamp from the member file to the member */
1629 1628 if ((target->stat.time != file_max_time) &&
1630 1629 ((member = get_prop(target->prop, member_prop)) != NULL) &&
1631 1630 (exists(member->body.member.member) > file_doesnt_exist)) {
1632 1631 target->stat.time =
1633 1632 /*
1634 1633 exists(member->body.member.member);
1635 1634 */
1636 1635 member->body.member.member->stat.time;
1637 1636 }
1638 1637 }
1639 1638 /*
1640 1639 * Check if we found any new auto dependencies when we
1641 1640 * built the target.
1642 1641 */
1643 1642 if ((result == build_ok) && check_auto_dependencies(target,
1644 1643 auto_count,
1645 1644 automatics)) {
1646 1645 if (debug_level > 0) {
1647 1646 (void) printf(catgets(catd, 1, 261, "%*sTarget `%s' acquired new dependencies from build, checking all dependencies\n"),
1648 1647 recursion_level,
1649 1648 "",
1650 1649 true_target->string_mb);
1651 1650 }
1652 1651 target->rechecking_target = true;
1653 1652 target->state = build_running;
1654 1653
1655 1654 /* [tolik, Tue Mar 25 1997]
1656 1655 * Fix for bug 4038824:
1657 1656 * command line options set by conditional macros get dropped
1658 1657 * rp->conditional_cnt and rp->conditional_targets must be copied
1659 1658 * to new 'rp' during add_pending(). Set_conditionals() stores
1660 1659 * rp->conditional_targets to the global variable 'conditional_targets'
1661 1660 * Add_pending() will use this variable to set up 'rp'.
1662 1661 */
1663 1662 conditionals = set_conditionals(rp->conditional_cnt, rp->conditional_targets);
1664 1663 add_pending(target,
1665 1664 recursion_level,
1666 1665 rp->do_get,
1667 1666 rp->implicit,
1668 1667 true);
1669 1668 reset_conditionals(rp->conditional_cnt, rp->conditional_targets, conditionals);
1670 1669 }
1671 1670 }
1672 1671
1673 1672 /*
1674 1673 * new_running_struct()
1675 1674 *
1676 1675 * Constructor for Running struct. Creates a structure and initializes
1677 1676 * its fields.
1678 1677 *
1679 1678 */
1680 1679 static Running new_running_struct()
1681 1680 {
1682 1681 Running rp;
1683 1682
1684 1683 rp = ALLOC(Running);
1685 1684 rp->target = NULL;
1686 1685 rp->true_target = NULL;
1687 1686 rp->command = NULL;
1688 1687 rp->sprodep_value = NULL;
1689 1688 rp->sprodep_env = NULL;
1690 1689 rp->auto_count = 0;
1691 1690 rp->automatics = NULL;
1692 1691 rp->pid = -1;
1693 1692 rp->job_msg_id = -1;
1694 1693 rp->stdout_file = NULL;
1695 1694 rp->stderr_file = NULL;
1696 1695 rp->temp_file = NULL;
1697 1696 rp->next = NULL;
1698 1697 return rp;
1699 1698 }
1700 1699
1701 1700 /*
1702 1701 * add_running(target, true_target, command, recursion_level, auto_count,
1703 1702 * automatics, do_get, implicit)
1704 1703 *
1705 1704 * Adds a record on the running list for this target, which
1706 1705 * was just spawned and is running.
1707 1706 *
1708 1707 * Parameters:
1709 1708 * target Target being built
1710 1709 * true_target True target for target
1711 1710 * command Running command.
1712 1711 * recursion_level Debug indentation level
1713 1712 * auto_count Count of automatic dependencies
1714 1713 * automatics List of automatic dependencies
1715 1714 * do_get Sccs get flag
1716 1715 * implicit Implicit flag
1717 1716 *
1718 1717 * Static variables used:
1719 1718 * running_tail Tail of running list
1720 1719 * process_running PID of process
1721 1720 *
1722 1721 * Global variables used:
1723 1722 * current_line Current line for target
1724 1723 * current_target Current target being built
1725 1724 * stderr_file Temporary file for stdout
1726 1725 * stdout_file Temporary file for stdout
1727 1726 * temp_file_name Temporary file for auto dependencies
1728 1727 */
1729 1728 void
1730 1729 add_running(Name target, Name true_target, Property command, int recursion_level, int auto_count, Name *automatics, Boolean do_get, Boolean implicit)
1731 1730 {
1732 1731 Running rp;
1733 1732 Name *p;
1734 1733
1735 1734 rp = new_running_struct();
1736 1735 rp->state = build_running;
1737 1736 rp->target = target;
1738 1737 rp->true_target = true_target;
1739 1738 rp->command = command;
1740 1739 Property spro_val = get_prop(sunpro_dependencies->prop, macro_prop);
1741 1740 if(spro_val) {
1742 1741 rp->sprodep_value = spro_val->body.macro.value;
1743 1742 spro_val->body.macro.value = NULL;
1744 1743 spro_val = get_prop(sunpro_dependencies->prop, env_mem_prop);
1745 1744 if(spro_val) {
1746 1745 rp->sprodep_env = spro_val->body.env_mem.value;
1747 1746 spro_val->body.env_mem.value = NULL;
1748 1747 }
1749 1748 }
1750 1749 rp->recursion_level = recursion_level;
1751 1750 rp->do_get = do_get;
1752 1751 rp->implicit = implicit;
1753 1752 rp->auto_count = auto_count;
1754 1753 if (auto_count > 0) {
1755 1754 rp->automatics = (Name *) getmem(auto_count * sizeof (Name));
1756 1755 for (p = rp->automatics; auto_count > 0; auto_count--) {
1757 1756 *p++ = *automatics++;
1758 1757 }
1759 1758 } else {
1760 1759 rp->automatics = NULL;
1761 1760 }
1762 1761 #ifdef DISTRIBUTED
1763 1762 if (dmake_mode_type == distributed_mode) {
1764 1763 rp->make_refd = called_make;
1765 1764 called_make = false;
1766 1765 } else
1767 1766 #endif
1768 1767 {
1769 1768 rp->pid = process_running;
1770 1769 process_running = -1;
1771 1770 childPid = -1;
1772 1771 }
1773 1772 rp->job_msg_id = job_msg_id;
1774 1773 rp->stdout_file = stdout_file;
1775 1774 rp->stderr_file = stderr_file;
1776 1775 rp->temp_file = temp_file_name;
1777 1776 rp->redo = false;
1778 1777 rp->next = NULL;
1779 1778 store_conditionals(rp);
1780 1779 stdout_file = NULL;
1781 1780 stderr_file = NULL;
1782 1781 temp_file_name = NULL;
1783 1782 current_target = NULL;
1784 1783 current_line = NULL;
1785 1784 *running_tail = rp;
1786 1785 running_tail = &rp->next;
1787 1786 }
1788 1787
1789 1788 /*
1790 1789 * add_pending(target, recursion_level, do_get, implicit, redo)
1791 1790 *
1792 1791 * Adds a record on the running list for a pending target
1793 1792 * (waiting for its dependents to finish running).
1794 1793 *
1795 1794 * Parameters:
1796 1795 * target Target being built
1797 1796 * recursion_level Debug indentation level
1798 1797 * do_get Sccs get flag
1799 1798 * implicit Implicit flag
1800 1799 * redo True if this target is being redone
1801 1800 *
1802 1801 * Static variables used:
1803 1802 * running_tail Tail of running list
1804 1803 */
1805 1804 void
1806 1805 add_pending(Name target, int recursion_level, Boolean do_get, Boolean implicit, Boolean redo)
1807 1806 {
1808 1807 Running rp;
1809 1808 rp = new_running_struct();
1810 1809 rp->state = build_pending;
1811 1810 rp->target = target;
1812 1811 rp->recursion_level = recursion_level;
1813 1812 rp->do_get = do_get;
1814 1813 rp->implicit = implicit;
1815 1814 rp->redo = redo;
1816 1815 store_conditionals(rp);
1817 1816 *running_tail = rp;
1818 1817 running_tail = &rp->next;
1819 1818 }
1820 1819
1821 1820 /*
1822 1821 * add_serial(target, recursion_level, do_get, implicit)
1823 1822 *
1824 1823 * Adds a record on the running list for a target which must be
1825 1824 * executed in serial after others have finished.
1826 1825 *
1827 1826 * Parameters:
1828 1827 * target Target being built
1829 1828 * recursion_level Debug indentation level
1830 1829 * do_get Sccs get flag
1831 1830 * implicit Implicit flag
1832 1831 *
1833 1832 * Static variables used:
1834 1833 * running_tail Tail of running list
1835 1834 */
1836 1835 void
1837 1836 add_serial(Name target, int recursion_level, Boolean do_get, Boolean implicit)
1838 1837 {
1839 1838 Running rp;
1840 1839
1841 1840 rp = new_running_struct();
1842 1841 rp->target = target;
1843 1842 rp->recursion_level = recursion_level;
1844 1843 rp->do_get = do_get;
1845 1844 rp->implicit = implicit;
1846 1845 rp->state = build_serial;
1847 1846 rp->redo = false;
1848 1847 store_conditionals(rp);
1849 1848 *running_tail = rp;
1850 1849 running_tail = &rp->next;
1851 1850 }
1852 1851
1853 1852 /*
1854 1853 * add_subtree(target, recursion_level, do_get, implicit)
1855 1854 *
1856 1855 * Adds a record on the running list for a target which must be
1857 1856 * executed in isolation after others have finished.
1858 1857 *
1859 1858 * Parameters:
1860 1859 * target Target being built
1861 1860 * recursion_level Debug indentation level
1862 1861 * do_get Sccs get flag
1863 1862 * implicit Implicit flag
1864 1863 *
1865 1864 * Static variables used:
1866 1865 * running_tail Tail of running list
1867 1866 */
1868 1867 void
1869 1868 add_subtree(Name target, int recursion_level, Boolean do_get, Boolean implicit)
1870 1869 {
1871 1870 Running rp;
1872 1871
1873 1872 rp = new_running_struct();
1874 1873 rp->target = target;
1875 1874 rp->recursion_level = recursion_level;
1876 1875 rp->do_get = do_get;
1877 1876 rp->implicit = implicit;
1878 1877 rp->state = build_subtree;
1879 1878 rp->redo = false;
1880 1879 store_conditionals(rp);
1881 1880 *running_tail = rp;
1882 1881 running_tail = &rp->next;
1883 1882 }
1884 1883
1885 1884 /*
1886 1885 * store_conditionals(rp)
1887 1886 *
1888 1887 * Creates an array of the currently active targets with conditional
1889 1888 * macros (found in the chain conditional_targets) and puts that
1890 1889 * array in the Running struct.
1891 1890 *
1892 1891 * Parameters:
1893 1892 * rp Running struct for storing chain
1894 1893 *
1895 1894 * Global variables used:
1896 1895 * conditional_targets Chain of current dynamic conditionals
1897 1896 */
1898 1897 static void
1899 1898 store_conditionals(Running rp)
1900 1899 {
1901 1900 int cnt;
1902 1901 Chain cond_name;
1903 1902
1904 1903 if (conditional_targets == NULL) {
1905 1904 rp->conditional_cnt = 0;
1906 1905 rp->conditional_targets = NULL;
1907 1906 return;
1908 1907 }
1909 1908 cnt = 0;
1910 1909 for (cond_name = conditional_targets;
1911 1910 cond_name != NULL;
1912 1911 cond_name = cond_name->next) {
1913 1912 cnt++;
1914 1913 }
1915 1914 rp->conditional_cnt = cnt;
1916 1915 rp->conditional_targets = (Name *) getmem(cnt * sizeof(Name));
1917 1916 for (cond_name = conditional_targets;
1918 1917 cond_name != NULL;
1919 1918 cond_name = cond_name->next) {
1920 1919 rp->conditional_targets[--cnt] = cond_name->name;
1921 1920 }
1922 1921 }
1923 1922
1924 1923 /*
1925 1924 * parallel_ok(target, line_prop_must_exists)
1926 1925 *
1927 1926 * Returns true if the target can be run in parallel
1928 1927 *
1929 1928 * Return value:
1930 1929 * True if can run in parallel
1931 1930 *
1932 1931 * Parameters:
1933 1932 * target Target being tested
1934 1933 *
1935 1934 * Global variables used:
1936 1935 * all_parallel True if all targets default to parallel
1937 1936 * only_parallel True if no targets default to parallel
1938 1937 */
1939 1938 Boolean
1940 1939 parallel_ok(Name target, Boolean line_prop_must_exists)
1941 1940 {
1942 1941 Boolean assign;
1943 1942 Boolean make_refd;
1944 1943 Property line;
1945 1944 Cmd_line rule;
1946 1945
1947 1946 assign = make_refd = false;
1948 1947 if (((line = get_prop(target->prop, line_prop)) == NULL) &&
1949 1948 line_prop_must_exists) {
1950 1949 return false;
1951 1950 }
1952 1951 if (line != NULL) {
1953 1952 for (rule = line->body.line.command_used;
1954 1953 rule != NULL;
1955 1954 rule = rule->next) {
1956 1955 if (rule->assign) {
1957 1956 assign = true;
1958 1957 } else if (rule->make_refd) {
1959 1958 make_refd = true;
1960 1959 }
1961 1960 }
1962 1961 }
1963 1962 if (assign) {
1964 1963 return false;
1965 1964 } else if (target->parallel) {
1966 1965 return true;
1967 1966 } else if (target->no_parallel) {
1968 1967 return false;
1969 1968 } else if (all_parallel) {
1970 1969 return true;
1971 1970 } else if (only_parallel) {
1972 1971 return false;
1973 1972 } else if (make_refd) {
1974 1973 return false;
1975 1974 } else {
1976 1975 return true;
1977 1976 }
1978 1977 }
1979 1978
1980 1979 /*
1981 1980 * is_running(target)
1982 1981 *
1983 1982 * Returns true if the target is running.
1984 1983 *
1985 1984 * Return value:
1986 1985 * True if target is running
1987 1986 *
1988 1987 * Parameters:
1989 1988 * target Target to check
1990 1989 *
1991 1990 * Global variables used:
1992 1991 * running_list List of running processes
1993 1992 */
1994 1993 Boolean
1995 1994 is_running(Name target)
1996 1995 {
1997 1996 Running rp;
1998 1997
1999 1998 if (target->state != build_running) {
2000 1999 return false;
2001 2000 }
2002 2001 for (rp = running_list;
2003 2002 rp != NULL && target != rp->target;
2004 2003 rp = rp->next);
2005 2004 if (rp == NULL) {
2006 2005 return false;
2007 2006 } else {
2008 2007 return (rp->state == build_running) ? true : false;
2009 2008 }
2010 2009 }
2011 2010
2012 2011 /*
2013 2012 * This function replaces the makesh binary.
2014 2013 */
2015 2014
2016 2015
2017 2016 static pid_t
2018 2017 run_rule_commands(char *host, char **commands)
2019 2018 {
2020 2019 Boolean always_exec;
2021 2020 Name command;
2022 2021 Boolean ignore;
2023 2022 int length;
2024 2023 Doname result;
2025 2024 Boolean silent_flag;
2026 2025 wchar_t *tmp_wcs_buffer;
↓ open down ↓ |
529 lines elided |
↑ open up ↑ |
2027 2026
2028 2027 childPid = fork();
2029 2028 switch (childPid) {
2030 2029 case -1: /* Error */
2031 2030 fatal(catgets(catd, 1, 337, "Could not fork child process for dmake job: %s"),
2032 2031 errmsg(errno));
2033 2032 break;
2034 2033 case 0: /* Child */
2035 2034 /* To control the processed targets list is not the child's business */
2036 2035 running_list = NULL;
2037 -#if defined(REDIRECT_ERR)
2038 2036 if(out_err_same) {
2039 2037 redirect_io(stdout_file, (char*)NULL);
2040 2038 } else {
2041 2039 redirect_io(stdout_file, stderr_file);
2042 2040 }
2043 -#else
2044 - redirect_io(stdout_file, (char*)NULL);
2045 -#endif
2046 2041 for (commands = commands;
2047 2042 (*commands != (char *)NULL);
2048 2043 commands++) {
2049 2044 silent_flag = silent;
2050 2045 ignore = false;
2051 2046 always_exec = false;
2052 2047 while ((**commands == (int) at_char) ||
2053 2048 (**commands == (int) hyphen_char) ||
2054 2049 (**commands == (int) plus_char)) {
2055 2050 if (**commands == (int) at_char) {
2056 2051 silent_flag = true;
2057 2052 }
2058 2053 if (**commands == (int) hyphen_char) {
2059 2054 ignore = true;
2060 2055 }
2061 2056 if (**commands == (int) plus_char) {
2062 2057 always_exec = true;
2063 2058 }
2064 2059 (*commands)++;
2065 2060 }
2066 2061 if ((length = strlen(*commands)) >= MAXPATHLEN) {
2067 2062 tmp_wcs_buffer = ALLOC_WC(length + 1);
2068 2063 (void) mbstowcs(tmp_wcs_buffer, *commands, length + 1);
2069 2064 command = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2070 2065 retmem(tmp_wcs_buffer);
2071 2066 } else {
2072 2067 MBSTOWCS(wcs_buffer, *commands);
2073 2068 command = GETNAME(wcs_buffer, FIND_LENGTH);
2074 2069 }
2075 2070 if ((command->hash.length > 0) &&
2076 2071 !silent_flag) {
2077 2072 (void) printf("%s\n", command->string_mb);
2078 2073 }
2079 2074 result = dosys(command,
2080 2075 ignore,
2081 2076 false,
2082 2077 false, /* bugs #4085164 & #4990057 */
2083 2078 /* BOOLEAN(silent_flag && ignore), */
2084 2079 always_exec,
2085 2080 (Name) NULL,
2086 2081 false);
2087 2082 if (result == build_failed) {
2088 2083 if (silent_flag) {
2089 2084 (void) printf(catgets(catd, 1, 152, "The following command caused the error:\n%s\n"), command->string_mb);
2090 2085 }
2091 2086 if (!ignore) {
2092 2087 _exit(1);
2093 2088 }
2094 2089 }
2095 2090 }
2096 2091 _exit(0);
2097 2092 break;
2098 2093 default:
2099 2094 break;
2100 2095 }
2101 2096 return childPid;
2102 2097 }
2103 2098
2104 2099 static void
2105 2100 maybe_reread_make_state(void)
2106 2101 {
2107 2102 /* Copying dosys()... */
2108 2103 if (report_dependencies_level == 0) {
2109 2104 make_state->stat.time = file_no_time;
2110 2105 (void) exists(make_state);
2111 2106 if (make_state_before == make_state->stat.time) {
2112 2107 return;
2113 2108 }
2114 2109 makefile_type = reading_statefile;
2115 2110 if (read_trace_level > 1) {
2116 2111 trace_reader = true;
2117 2112 }
2118 2113 temp_file_number++;
2119 2114 (void) read_simple_file(make_state,
2120 2115 false,
2121 2116 false,
2122 2117 false,
2123 2118 false,
2124 2119 false,
2125 2120 true);
2126 2121 trace_reader = false;
2127 2122 }
2128 2123 }
2129 2124
2130 2125 #ifdef DISTRIBUTED
2131 2126 /*
2132 2127 * Create and send an Avo_MToolJobResultMsg.
2133 2128 */
2134 2129 static void
2135 2130 send_job_result_msg(Running rp)
2136 2131 {
2137 2132 Avo_MToolJobResultMsg *msg;
2138 2133 RWCollectable *xdr_msg;
2139 2134
2140 2135 msg = new Avo_MToolJobResultMsg();
2141 2136 msg->setResult(rp->job_msg_id,
2142 2137 (rp->state == build_ok) ? 0 : 1,
2143 2138 DONE);
2144 2139 append_job_result_msg(msg,
2145 2140 rp->stdout_file,
2146 2141 rp->stderr_file);
2147 2142
2148 2143 xdr_msg = (RWCollectable *)msg;
2149 2144 xdr(get_xdrs_ptr(), xdr_msg);
2150 2145 (void) fflush(get_mtool_msgs_fp());
2151 2146
2152 2147 delete msg;
2153 2148 }
2154 2149
2155 2150 /*
2156 2151 * Append the stdout/err to Avo_MToolJobResultMsg.
2157 2152 */
2158 2153 static void
2159 2154 append_job_result_msg(Avo_MToolJobResultMsg *msg, char *outFn, char *errFn)
2160 2155 {
2161 2156 FILE *fp;
2162 2157 char line[MAXPATHLEN];
2163 2158
2164 2159 fp = fopen(outFn, "r");
2165 2160 if (fp == NULL) {
2166 2161 /* Hmmm... what should we do here? */
2167 2162 return;
2168 2163 }
2169 2164 while (fgets(line, MAXPATHLEN, fp) != NULL) {
2170 2165 if (line[strlen(line) - 1] == '\n') {
2171 2166 line[strlen(line) - 1] = '\0';
2172 2167 }
2173 2168 msg->appendOutput(AVO_STRDUP(line));
2174 2169 }
2175 2170 (void) fclose(fp);
2176 2171 }
2177 2172 #endif
2178 2173
2179 2174 static void
2180 2175 delete_running_struct(Running rp)
2181 2176 {
2182 2177 if ((rp->conditional_cnt > 0) &&
2183 2178 (rp->conditional_targets != NULL)) {
2184 2179 retmem_mb((char *) rp->conditional_targets);
2185 2180 }
2186 2181 /**/
2187 2182 if ((rp->auto_count > 0) &&
2188 2183 (rp->automatics != NULL)) {
2189 2184 retmem_mb((char *) rp->automatics);
2190 2185 }
2191 2186 /**/
2192 2187 if(rp->sprodep_value) {
2193 2188 free_name(rp->sprodep_value);
2194 2189 }
2195 2190 if(rp->sprodep_env) {
2196 2191 retmem_mb(rp->sprodep_env);
2197 2192 }
2198 2193 retmem_mb((char *) rp);
2199 2194
2200 2195 }
2201 2196
2202 2197 #endif
2203 2198
↓ open down ↓ |
148 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX