Changeset 501 in kBuild for vendor/gnumake/current/job.c
- Timestamp:
- Sep 15, 2006 2:30:32 AM (18 years ago)
- File:
-
- 1 edited
-
vendor/gnumake/current/job.c (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/job.c
r280 r501 1 1 /* Job execution and handling for GNU Make. 2 Copyright (C) 1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1999, 3 2000,2001,2002,2003,2004,2005 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 4 5 This file is part of GNU Make. 5 6 6 GNU Make is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Make is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Make; see the file COPYING. If not, write to 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 Boston, MA 02111-1307, USA. */ 7 GNU Make is free software; you can redistribute it and/or modify it under the 8 terms of the GNU General Public License as published by the Free Software 9 Foundation; either version 2, or (at your option) any later version. 10 11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 20 18 21 19 #include "make.h" … … 34 32 /* Default shell to use. */ 35 33 #ifdef WINDOWS32 34 #include <windows.h> 36 35 37 36 char *default_shell = "sh.exe"; 38 37 int no_default_sh_exe = 1; 39 38 int batch_mode_shell = 1; 39 HANDLE main_thread; 40 40 41 41 #elif defined (_AMIGA) … … 99 99 # include <starlet.h> 100 100 # include <lib$routines.h> 101 static void vmsWaitForChildren PARAMS ((int *)); 101 102 #endif 102 103 … … 242 243 } 243 244 244 /* This function creates a temporary file name with the given extension 245 * the unixy param controls both the extension and the path separator 246 * return an xmalloc'ed string of a newly created temp file or die. */ 245 /* This function creates a temporary file name with an extension specified 246 * by the unixy arg. 247 * Return an xmalloc'ed string of a newly created temp file and its 248 * file descriptor, or die. */ 247 249 static char * 248 create_batch_file name(char const *base, int unixy)250 create_batch_file (char const *base, int unixy, int *fd) 249 251 { 250 252 const char *const ext = unixy ? "sh" : "bat"; … … 304 306 char *const path = (char *) xmalloc (final_size); 305 307 memcpy (path, temp_path, final_size); 306 CloseHandle (h);308 *fd = _open_osfhandle ((long)h, 0); 307 309 if (unixy) 308 310 { … … 317 319 } 318 320 321 *fd = -1; 319 322 if (error == NULL) 320 323 error = _("Cannot create a temporary file\n"); … … 448 451 reap_children (int block, int err) 449 452 { 453 #ifndef WINDOWS32 450 454 WAIT_T status; 451 455 /* Initially, assume we have some. */ 452 456 int reap_more = 1; 457 #endif 453 458 454 459 #ifdef WAIT_NOHANG … … 475 480 int child_failed; 476 481 int any_remote, any_local; 482 int dontcare; 477 483 478 484 if (err && block) 479 485 { 480 /* We might block for a while, so let the user know why. */ 486 static int printed = 0; 487 488 /* We might block for a while, so let the user know why. 489 Only print this message once no matter how many jobs are left. */ 481 490 fflush (stdout); 482 error (NILF, _("*** Waiting for unfinished jobs....")); 491 if (!printed) 492 error (NILF, _("*** Waiting for unfinished jobs....")); 493 printed = 1; 483 494 } 484 495 … … 539 550 { 540 551 #ifdef VMS 541 static void vmsWaitForChildren PARAMS ((int *));542 552 vmsWaitForChildren (&status); 543 553 pid = c->pid; … … 612 622 { 613 623 HANDLE hPID; 614 int err; 624 int werr; 625 HANDLE hcTID, hcPID; 615 626 exit_code = 0; 616 627 exit_sig = 0; 617 628 coredump = 0; 629 630 /* Record the thread ID of the main process, so that we 631 could suspend it in the signal handler. */ 632 if (!main_thread) 633 { 634 hcTID = GetCurrentThread (); 635 hcPID = GetCurrentProcess (); 636 if (!DuplicateHandle (hcPID, hcTID, hcPID, &main_thread, 0, 637 FALSE, DUPLICATE_SAME_ACCESS)) 638 { 639 DWORD e = GetLastError (); 640 fprintf (stderr, 641 "Determine main thread ID (Error %ld: %s)\n", 642 e, map_windows32_error_to_string(e)); 643 } 644 else 645 DB (DB_VERBOSE, ("Main thread handle = 0x%08lx\n", 646 (unsigned long)main_thread)); 647 } 618 648 619 649 /* wait for anything to finish */ … … 623 653 624 654 /* was an error found on this process? */ 625 err = process_last_err(hPID);655 werr = process_last_err(hPID); 626 656 627 657 /* get exit data */ 628 658 exit_code = process_exit_code(hPID); 629 659 630 if ( err)660 if (werr) 631 661 fprintf(stderr, "make (e=%d): %s", 632 662 exit_code, map_windows32_error_to_string(exit_code)); … … 691 721 good_stdin_used = 0; 692 722 723 dontcare = c->dontcare; 724 693 725 if (child_failed && !c->noerror && !ignore_errors_flag) 694 726 { … … 696 728 delete non-precious targets, and abort. */ 697 729 static int delete_on_error = -1; 698 child_error (c->file->name, exit_code, exit_sig, coredump, 0); 730 731 if (!dontcare) 732 child_error (c->file->name, exit_code, exit_sig, coredump, 0); 733 699 734 c->file->update_status = 2; 700 735 if (delete_on_error == -1) … … 796 831 /* If the job failed, and the -k flag was not given, die, 797 832 unless we are already in the process of dying. */ 798 if (!err && child_failed && ! keep_going_flag &&833 if (!err && child_failed && !dontcare && !keep_going_flag && 799 834 /* fatal_error_signal will die with the right signal. */ 800 835 !handling_fatal_signal) … … 938 973 start_job_command (struct child *child) 939 974 { 940 #if ndef _AMIGA975 #if !defined(_AMIGA) && !defined(WINDOWS32) 941 976 static int bad_stdin = -1; 942 977 #endif … … 959 994 960 995 p = child->command_ptr; 961 child->noerror = flags & COMMANDS_NOERROR;996 child->noerror = ((flags & COMMANDS_NOERROR) != 0); 962 997 963 998 while (*p != '\0') … … 1352 1387 unblock_sigs(); 1353 1388 fprintf(stderr, 1354 _("process_easy() failed failed to launch process (e=%d)\n"), 1355 process_last_err(hPID)); 1356 for (i = 0; argv[i]; i++) 1357 fprintf(stderr, "%s ", argv[i]); 1358 fprintf(stderr, _("\nCounted %d args in failed launch\n"), i); 1389 _("process_easy() failed to launch process (e=%ld)\n"), 1390 process_last_err(hPID)); 1391 for (i = 0; argv[i]; i++) 1392 fprintf(stderr, "%s ", argv[i]); 1393 fprintf(stderr, _("\nCounted %d args in failed launch\n"), i); 1394 goto error; 1359 1395 } 1360 1396 } … … 1401 1437 /* If we are running at least one job already and the load average 1402 1438 is too high, make this one wait. */ 1403 if (!c->remote && job_slots_used > 0 && load_too_high ()) 1439 if (!c->remote 1440 && ((job_slots_used > 0 && load_too_high ()) 1441 #ifdef WINDOWS32 1442 || (process_used_slots () >= MAXIMUM_WAIT_OBJECTS) 1443 #endif 1444 )) 1404 1445 { 1405 1446 /* Put this child on the chain of children waiting for the load average … … 1575 1616 c->command_lines = lines; 1576 1617 c->sh_batch_file = NULL; 1618 1619 /* Cache dontcare flag because file->dontcare can be changed once we 1620 return. Check dontcare inheritance mechanism for details. */ 1621 c->dontcare = file->dontcare; 1577 1622 1578 1623 /* Fetch the first command line to be run. */ … … 1772 1817 time_t now; 1773 1818 1819 #ifdef WINDOWS32 1820 /* sub_proc.c cannot wait for more than MAXIMUM_WAIT_OBJECTS children */ 1821 if (process_used_slots () >= MAXIMUM_WAIT_OBJECTS) 1822 return 1; 1823 #endif 1824 1774 1825 if (max_load_average < 0) 1775 1826 return 0; … … 1908 1959 } 1909 1960 1910 #elif !defined (_AMIGA) && !defined (__MSDOS__) 1961 #elif !defined (_AMIGA) && !defined (__MSDOS__) && !defined (VMS) 1911 1962 1912 1963 /* UNIX: … … 1929 1980 exec_command (argv, envp); 1930 1981 } 1931 #endif /* !AMIGA && !__MSDOS__ */1982 #endif /* !AMIGA && !__MSDOS__ && !VMS */ 1932 1983 #endif /* !WINDOWS32 */ 1933 1984 … … 1972 2023 int i; 1973 2024 fprintf(stderr, 1974 _("process_easy() failed failed to launch process (e=% d)\n"),2025 _("process_easy() failed failed to launch process (e=%ld)\n"), 1975 2026 process_last_err(hPID)); 1976 2027 for (i = 0; argv[i]; i++) … … 2002 2053 else 2003 2054 fprintf(stderr, 2004 _("make reaped child pid % d, still waiting for pid %d\n"),2005 hWaitPID,hPID);2055 _("make reaped child pid %ld, still waiting for pid %ld\n"), 2056 (DWORD)hWaitPID, (DWORD)hPID); 2006 2057 } 2007 2058 … … 2274 2325 int instring, word_has_equals, seen_nonequals, last_argument_was_empty; 2275 2326 char **new_argv = 0; 2327 char *argstr = 0; 2276 2328 #ifdef WINDOWS32 2277 2329 int slow_flag = 0; 2278 2330 2279 if ( no_default_sh_exe) {2331 if (!unixy_shell) { 2280 2332 sh_cmds = sh_cmds_dos; 2281 2333 sh_chars = sh_chars_dos; … … 2360 2412 2361 2413 /* All the args can fit in a buffer as big as LINE is. */ 2362 ap = new_argv[0] = (char *) xmalloc (i);2414 ap = new_argv[0] = argstr = (char *) xmalloc (i); 2363 2415 end = ap + i; 2364 2416 … … 2368 2420 for (p = line; *p != '\0'; ++p) 2369 2421 { 2370 if (ap > end) 2371 abort (); 2422 assert (ap <= end); 2372 2423 2373 2424 if (instring) 2374 2425 { 2375 string_char:2376 2426 /* Inside a string, just copy any char except a closing quote 2377 2427 or a backslash-newline combination. */ … … 2383 2433 } 2384 2434 else if (*p == '\\' && p[1] == '\n') 2385 goto swallow_escaped_newline; 2435 { 2436 /* Backslash-newline is handled differently depending on what 2437 kind of string we're in: inside single-quoted strings you 2438 keep them; in double-quoted strings they disappear. 2439 For DOS/Windows/OS2, if we don't have a POSIX shell, 2440 we keep the pre-POSIX behavior of removing the 2441 backslash-newline. */ 2442 if (instring == '"' 2443 #if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32) 2444 || !unixy_shell 2445 #endif 2446 ) 2447 ++p; 2448 else 2449 { 2450 *(ap++) = *(p++); 2451 *(ap++) = *p; 2452 } 2453 /* If there's a TAB here, skip it. */ 2454 if (p[1] == '\t') 2455 ++p; 2456 } 2386 2457 else if (*p == '\n' && restp != NULL) 2387 2458 { … … 2423 2494 2424 2495 case '\\': 2425 /* Backslash-newline combinations are eaten. */ 2496 /* Backslash-newline has special case handling, ref POSIX. 2497 We're in the fastpath, so emulate what the shell would do. */ 2426 2498 if (p[1] == '\n') 2427 2499 { 2428 swallow_escaped_newline: 2429 2430 /* Eat the backslash, the newline, and following whitespace, 2431 replacing it all with a single space. */ 2432 p += 2; 2433 2434 /* If there is a tab after a backslash-newline, 2435 remove it from the source line which will be echoed, 2436 since it was most likely used to line 2437 up the continued line with the previous one. */ 2438 if (*p == '\t') 2439 /* Note these overlap and strcpy() is undefined for 2440 overlapping objects in ANSI C. The strlen() _IS_ right, 2441 since we need to copy the nul byte too. */ 2442 bcopy (p + 1, p, strlen (p)); 2443 2444 if (instring) 2445 goto string_char; 2446 else 2447 { 2448 if (ap != new_argv[i]) 2449 /* Treat this as a space, ending the arg. 2450 But if it's at the beginning of the arg, it should 2451 just get eaten, rather than becoming an empty arg. */ 2452 goto end_of_arg; 2453 else 2454 p = next_token (p) - 1; 2455 } 2500 /* Throw out the backslash and newline. */ 2501 ++p; 2502 2503 /* If there is a tab after a backslash-newline, remove it. */ 2504 if (p[1] == '\t') 2505 ++p; 2506 2507 /* If there's nothing in this argument yet, skip any 2508 whitespace before the start of the next word. */ 2509 if (ap == new_argv[i]) 2510 p = next_token (p + 1) - 1; 2456 2511 } 2457 2512 else if (p[1] != '\0') 2458 2513 { 2459 2514 #ifdef HAVE_DOS_PATHS 2460 /* Only remove backslashes before characters special 2461 to Unixy shells. All other backslashes are copied 2462 verbatim, since they are probably DOS-style 2463 directory separators. This still leaves a small 2464 window for problems, but at least it should work 2465 for the vast majority of naive users. */ 2515 /* Only remove backslashes before characters special to Unixy 2516 shells. All other backslashes are copied verbatim, since 2517 they are probably DOS-style directory separators. This 2518 still leaves a small window for problems, but at least it 2519 should work for the vast majority of naive users. */ 2466 2520 2467 2521 #ifdef __MSDOS__ … … 2478 2532 if (p[1] != '\\' && p[1] != '\'' 2479 2533 && !isspace ((unsigned char)p[1]) 2480 && (strchr (sh_chars_sh, p[1]) == 0))2534 && strchr (sh_chars_sh, p[1]) == 0) 2481 2535 /* back up one notch, to copy the backslash */ 2482 2536 --p; … … 2507 2561 case ' ': 2508 2562 case '\t': 2509 end_of_arg:2510 2563 /* We have the end of an argument. 2511 2564 Terminate the text of the argument. */ … … 2543 2596 2544 2597 /* Ignore multiple whitespace chars. */ 2545 p = next_token (p); 2546 /* Next iteration should examine the first nonwhite char. */ 2547 --p; 2598 p = next_token (p) - 1; 2548 2599 break; 2549 2600 … … 2575 2626 2576 2627 if (new_argv[0] == 0) 2577 /* Line was empty. */ 2578 return 0; 2628 { 2629 /* Line was empty. */ 2630 free (argstr); 2631 free ((char *)new_argv); 2632 return 0; 2633 } 2579 2634 2580 2635 return new_argv; … … 2586 2641 { 2587 2642 /* Free the old argument list we were working on. */ 2588 free ( new_argv[0]);2589 free (( void*)new_argv);2643 free (argstr); 2644 free ((char *)new_argv); 2590 2645 } 2591 2646 … … 2677 2732 else if (*p == '\\' && p[1] == '\n') 2678 2733 { 2679 /* Eat the backslash, the newline, and following whitespace, 2680 replacing it all with a single space (which is escaped 2681 from the shell). */ 2682 p += 2; 2683 2684 /* If there is a tab after a backslash-newline, 2685 remove it from the source line which will be echoed, 2686 since it was most likely used to line 2687 up the continued line with the previous one. */ 2688 if (*p == '\t') 2689 bcopy (p + 1, p, strlen (p)); 2690 2691 p = next_token (p); 2692 --p; 2693 if (unixy_shell && !batch_mode_shell) 2694 *ap++ = '\\'; 2695 *ap++ = ' '; 2734 /* POSIX says we keep the backslash-newline, but throw out 2735 the next char if it's a TAB. If we don't have a POSIX 2736 shell on DOS/Windows/OS2, mimic the pre-POSIX behavior 2737 and remove the backslash/newline. */ 2738 #if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32) 2739 # define PRESERVE_BSNL unixy_shell 2740 #else 2741 # define PRESERVE_BSNL 1 2742 #endif 2743 if (PRESERVE_BSNL) 2744 { 2745 *(ap++) = '\\'; 2746 *(ap++) = '\\'; 2747 *(ap++) = '\n'; 2748 } 2749 2750 ++p; 2751 if (p[1] == '\t') 2752 ++p; 2753 2696 2754 continue; 2697 2755 } … … 2723 2781 command line (e.g. Cygnus GNUWIN32 sh.exe on WIN32 systems). In these 2724 2782 cases, run commands via a script file. */ 2725 if ((no_default_sh_exe || batch_mode_shell) && batch_filename_ptr) { 2783 if (just_print_flag) { 2784 /* Need to allocate new_argv, although it's unused, because 2785 start_job_command will want to free it and its 0'th element. */ 2786 new_argv = (char **) xmalloc(2 * sizeof (char *)); 2787 new_argv[0] = xstrdup (""); 2788 new_argv[1] = NULL; 2789 } else if ((no_default_sh_exe || batch_mode_shell) && batch_filename_ptr) { 2790 int temp_fd; 2726 2791 FILE* batch = NULL; 2727 2792 int id = GetCurrentProcessId(); … … 2730 2795 /* create a file name */ 2731 2796 sprintf(fbuf, "make%d", id); 2732 *batch_filename_ptr = create_batch_file name (fbuf, unixy_shell);2797 *batch_filename_ptr = create_batch_file (fbuf, unixy_shell, &temp_fd); 2733 2798 2734 2799 DB (DB_JOBS, (_("Creating temporary batch file %s\n"), 2735 2800 *batch_filename_ptr)); 2736 2801 2737 /* create batch file to execute command */ 2738 batch = fopen (*batch_filename_ptr, "w"); 2802 /* Create a FILE object for the batch file, and write to it the 2803 commands to be executed. Put the batch file in TEXT mode. */ 2804 _setmode (temp_fd, _O_TEXT); 2805 batch = _fdopen (temp_fd, "wt"); 2739 2806 if (!unixy_shell) 2740 2807 fputs ("@echo off\n", batch);
Note:
See TracChangeset
for help on using the changeset viewer.

