Changeset 900 in kBuild for vendor/gnumake/current/job.c
- Timestamp:
- May 23, 2007 3:13:11 AM (17 years ago)
- File:
-
- 1 edited
-
vendor/gnumake/current/job.c (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/job.c
r501 r900 99 99 # include <starlet.h> 100 100 # include <lib$routines.h> 101 static void vmsWaitForChildren PARAMS ((int *));101 static void vmsWaitForChildren (int *); 102 102 #endif 103 103 … … 131 131 132 132 #if !defined (wait) && !defined (POSIX) 133 externint wait ();133 int wait (); 134 134 #endif 135 135 … … 176 176 177 177 #ifndef HAVE_UNISTD_H 178 externint dup2 ();179 externint execve ();180 externvoid _exit ();178 int dup2 (); 179 int execve (); 180 void _exit (); 181 181 # ifndef VMS 182 externint geteuid ();183 externint getegid ();184 externint setgid ();185 externint getgid ();182 int geteuid (); 183 int getegid (); 184 int setgid (); 185 int getgid (); 186 186 # endif 187 187 #endif 188 188 189 extern char *allocated_variable_expand_for_file PARAMS ((char *line, struct file *file)); 190 191 extern int getloadavg PARAMS ((double loadavg[], int nelem)); 192 extern int start_remote_job PARAMS ((char **argv, char **envp, int stdin_fd, 193 int *is_remote, int *id_ptr, int *used_stdin)); 194 extern int start_remote_job_p PARAMS ((int)); 195 extern int remote_status PARAMS ((int *exit_code_ptr, int *signal_ptr, 196 int *coredump_ptr, int block)); 197 198 RETSIGTYPE child_handler PARAMS ((int)); 199 static void free_child PARAMS ((struct child *)); 200 static void start_job_command PARAMS ((struct child *child)); 201 static int load_too_high PARAMS ((void)); 202 static int job_next_command PARAMS ((struct child *)); 203 static int start_waiting_job PARAMS ((struct child *)); 189 int getloadavg (double loadavg[], int nelem); 190 int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote, 191 int *id_ptr, int *used_stdin); 192 int start_remote_job_p (int); 193 int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr, 194 int block); 195 196 RETSIGTYPE child_handler (int); 197 static void free_child (struct child *); 198 static void start_job_command (struct child *child); 199 static int load_too_high (void); 200 static int job_next_command (struct child *); 201 static int start_waiting_job (struct child *); 204 202 205 203 … … 304 302 { 305 303 const unsigned final_size = path_size + size + 1; 306 char *const path = (char *)xmalloc (final_size);304 char *const path = xmalloc (final_size); 307 305 memcpy (path, temp_path, final_size); 308 306 *fd = _open_osfhandle ((long)h, 0); … … 363 361 i = 0; 364 362 while (known_os2shells[i] != NULL) { 365 if (str icmp (name, known_os2shells[i]) == 0) /* strcasecmp() */363 if (strcasecmp (name, known_os2shells[i]) == 0) 366 364 return 0; /* not a unix shell */ 367 365 i++; … … 380 378 381 379 static void 382 child_error (c har *target_name, int exit_code, int exit_sig, int coredump,383 int ignored)380 child_error (const char *target_name, 381 int exit_code, int exit_sig, int coredump, int ignored) 384 382 { 385 383 if (ignored && silent_flag) … … 501 499 502 500 The test and decrement are not atomic; if it is compiled into: 503 register = dead_children - 1;501 register = dead_children - 1; 504 502 dead_children = register; 505 503 a SIGCHLD could come between the two instructions. … … 881 879 for (i = 0; i < child->file->cmds->ncommand_lines; ++i) 882 880 free (child->command_lines[i]); 883 free ( (char *)child->command_lines);881 free (child->command_lines); 884 882 } 885 883 … … 889 887 while (*ep != 0) 890 888 free (*ep++); 891 free ( (char *)child->environment);892 } 893 894 free ( (char *)child);889 free (child->environment); 890 } 891 892 free (child); 895 893 } 896 894 … … 938 936 #endif 939 937 940 bzero ((char *) &sa, sizeof sa);938 memset (&sa, '\0', sizeof sa); 941 939 sa.sa_handler = child_handler; 942 940 sa.sa_flags = set_handler ? 0 : SA_RESTART; … … 1044 1042 #ifndef VMS 1045 1043 free (argv[0]); 1046 free ( (char *)argv);1044 free (argv); 1047 1045 #endif 1048 1046 child->file->update_status = 1; … … 1059 1057 { 1060 1058 free (argv[0]); 1061 free ( (char *)argv);1059 free (argv); 1062 1060 } 1063 1061 #endif … … 1120 1118 { 1121 1119 free (argv[0]); 1122 free ( (char *)argv);1120 free (argv); 1123 1121 goto next_command; 1124 1122 } … … 1131 1129 #ifndef VMS 1132 1130 free (argv[0]); 1133 free ( (char *)argv);1131 free (argv); 1134 1132 #endif 1135 1133 goto next_command; … … 1409 1407 #ifndef VMS 1410 1408 free (argv[0]); 1411 free ( (char *)argv);1409 free (argv); 1412 1410 #endif 1413 1411 … … 1491 1489 new_job (struct file *file) 1492 1490 { 1493 registerstruct commands *cmds = file->cmds;1494 registerstruct child *c;1491 struct commands *cmds = file->cmds; 1492 struct child *c; 1495 1493 char **lines; 1496 registerunsigned int i;1494 unsigned int i; 1497 1495 1498 1496 /* Let any previously decided-upon jobs that are waiting … … 1507 1505 1508 1506 /* Expand the command lines and store the results in LINES. */ 1509 lines = (char **)xmalloc (cmds->ncommand_lines * sizeof (char *));1507 lines = xmalloc (cmds->ncommand_lines * sizeof (char *)); 1510 1508 for (i = 0; i < cmds->ncommand_lines; ++i) 1511 1509 { … … 1533 1531 we processed (where IN points) and the new chunk 1534 1532 we are about to process (where REF points). */ 1535 bcopy (in, out, ref - in);1533 memmove (out, in, ref - in); 1536 1534 1537 1535 /* Move both pointers past the boring stuff. */ … … 1611 1609 `struct child', and add that to the chain. */ 1612 1610 1613 c = (struct child *)xmalloc (sizeof (struct child));1614 bzero ((char *)c, sizeof (struct child));1611 c = xmalloc (sizeof (struct child)); 1612 memset (c, '\0', sizeof (struct child)); 1615 1613 c->file = file; 1616 1614 c->command_lines = lines; … … 1732 1730 /* The job is now primed. Start it running. 1733 1731 (This will notice if there are in fact no commands.) */ 1734 (void) start_waiting_job (c); 1732 if (cmds->fileinfo.filenm) 1733 DB (DB_BASIC, (_("Invoking commands from %s:%lu to update target `%s'.\n"), 1734 cmds->fileinfo.filenm, cmds->fileinfo.lineno, 1735 c->file->name)); 1736 else 1737 DB (DB_BASIC, (_("Invoking builtin commands to update target `%s'.\n"), 1738 c->file->name)); 1739 1740 1741 start_waiting_job (c); 1735 1742 1736 1743 if (job_slots == 1 || not_parallel) … … 2125 2132 # endif 2126 2133 2127 new_argv = (char **)alloca ((1 + argc + 1) * sizeof (char *));2134 new_argv = alloca ((1 + argc + 1) * sizeof (char *)); 2128 2135 new_argv[0] = shell; 2129 2136 … … 2318 2325 "shift", "switch", "test", "times", "trap", 2319 2326 "umask", "wait", "while", 0 }; 2320 #endif 2321 register int i; 2322 register char *p; 2323 register char *ap; 2327 # ifdef HAVE_DOS_PATHS 2328 /* This is required if the MSYS/Cygwin ports (which do not define 2329 WINDOWS32) are compiled with HAVE_DOS_PATHS defined, which uses 2330 sh_chars_sh[] directly (see below). */ 2331 static char *sh_chars_sh = sh_chars; 2332 # endif /* HAVE_DOS_PATHS */ 2333 #endif 2334 int i; 2335 char *p; 2336 char *ap; 2324 2337 char *end; 2325 2338 int instring, word_has_equals, seen_nonequals, last_argument_was_empty; … … 2353 2366 else if (strcmp (shell, default_shell)) 2354 2367 { 2355 char *s1 = _fullpath (NULL, shell, 0);2356 char *s2 = _fullpath (NULL, default_shell, 0);2357 2358 slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : ""));2368 char *s1 = _fullpath (NULL, shell, 0); 2369 char *s2 = _fullpath (NULL, default_shell, 0); 2370 2371 slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : "")); 2359 2372 2360 2373 if (s1) … … 2367 2380 #else /* not WINDOWS32 */ 2368 2381 #if defined (__MSDOS__) || defined (__EMX__) 2369 else if (str icmp (shell, default_shell))2382 else if (strcasecmp (shell, default_shell)) 2370 2383 { 2371 2384 extern int _is_unixy_shell (const char *_path); … … 2409 2422 2410 2423 /* More than 1 arg per character is impossible. */ 2411 new_argv = (char **)xmalloc (i * sizeof (char *));2424 new_argv = xmalloc (i * sizeof (char *)); 2412 2425 2413 2426 /* All the args can fit in a buffer as big as LINE is. */ 2414 ap = new_argv[0] = argstr = (char *)xmalloc (i);2427 ap = new_argv[0] = argstr = xmalloc (i); 2415 2428 end = ap + i; 2416 2429 … … 2451 2464 *(ap++) = *p; 2452 2465 } 2453 /* If there's a TABhere, skip it. */2454 if (p[1] == '\t')2466 /* If there's a command prefix char here, skip it. */ 2467 if (p[1] == cmd_prefix) 2455 2468 ++p; 2456 2469 } … … 2501 2514 ++p; 2502 2515 2503 /* If there is a tab after a backslash-newline, remove it. */ 2504 if (p[1] == '\t') 2516 /* If there is a command prefix after a backslash-newline, 2517 remove it. */ 2518 if (p[1] == cmd_prefix) 2505 2519 ++p; 2506 2520 … … 2629 2643 /* Line was empty. */ 2630 2644 free (argstr); 2631 free ( (char *)new_argv);2645 free (new_argv); 2632 2646 return 0; 2633 2647 } … … 2642 2656 /* Free the old argument list we were working on. */ 2643 2657 free (argstr); 2644 free ( (char *)new_argv);2658 free (new_argv); 2645 2659 } 2646 2660 … … 2655 2669 char *dptr; 2656 2670 2657 buffer = (char *)xmalloc (strlen (line)+1);2671 buffer = xmalloc (strlen (line)+1); 2658 2672 2659 2673 ptr = line; … … 2672 2686 *dptr = 0; 2673 2687 2674 new_argv = (char **)xmalloc (2 * sizeof (char *));2688 new_argv = xmalloc (2 * sizeof (char *)); 2675 2689 new_argv[0] = buffer; 2676 2690 new_argv[1] = 0; … … 2708 2722 unsigned int line_len = strlen (line); 2709 2723 2710 char *new_line = (char *) alloca (shell_len + (sizeof (minus_c) -1)2711 + (line_len *2) + 1);2724 char *new_line = alloca (shell_len + (sizeof (minus_c)-1) 2725 + (line_len*2) + 1); 2712 2726 char *command_ptr = NULL; /* used for batch_mode_shell mode */ 2713 2727 … … 2718 2732 2719 2733 ap = new_line; 2720 bcopy (shell, ap, shell_len);2734 memcpy (ap, shell, shell_len); 2721 2735 ap += shell_len; 2722 bcopy (minus_c, ap, sizeof (minus_c) - 1);2736 memcpy (ap, minus_c, sizeof (minus_c) - 1); 2723 2737 ap += sizeof (minus_c) - 1; 2724 2738 command_ptr = ap; … … 2749 2763 2750 2764 ++p; 2751 if (p[1] == '\t')2765 if (p[1] == cmd_prefix) 2752 2766 ++p; 2753 2767 … … 2784 2798 /* Need to allocate new_argv, although it's unused, because 2785 2799 start_job_command will want to free it and its 0'th element. */ 2786 new_argv = (char **)xmalloc(2 * sizeof (char *));2800 new_argv = xmalloc(2 * sizeof (char *)); 2787 2801 new_argv[0] = xstrdup (""); 2788 2802 new_argv[1] = NULL; … … 2811 2825 2812 2826 /* create argv */ 2813 new_argv = (char **)xmalloc(3 * sizeof (char *));2827 new_argv = xmalloc(3 * sizeof (char *)); 2814 2828 if (unixy_shell) { 2815 2829 new_argv[0] = xstrdup (shell); … … 2823 2837 #endif /* WINDOWS32 */ 2824 2838 if (unixy_shell) 2825 new_argv = construct_command_argv_internal (new_line, (char **) NULL, 2826 (char *) 0, (char *) 0, 2827 (char **) 0); 2839 new_argv = construct_command_argv_internal (new_line, 0, 0, 0, 0); 2828 2840 #ifdef __EMX__ 2829 2841 else if (!unixy_shell) … … 2842 2854 { 2843 2855 q += 2; /* remove '\\' and '\n' */ 2844 if (q[0] == '\t') 2845 q++; /* remove 1st tab in the next line */ 2856 /* Remove any command prefix in the next line */ 2857 if (q[0] == cmd_prefix) 2858 q++; 2846 2859 } 2847 2860 else … … 2883 2896 2884 2897 /* exactly 3 arguments + NULL */ 2885 new_argv = (char **)xmalloc (4 * sizeof (char *));2898 new_argv = xmalloc (4 * sizeof (char *)); 2886 2899 /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times 2887 2900 the trailing '\0' */ 2888 new_argv[0] = (char *)malloc (sh_len + line_len + 5);2901 new_argv[0] = xmalloc (sh_len + line_len + 5); 2889 2902 memcpy (new_argv[0], shell, sh_len + 1); 2890 2903 new_argv[1] = new_argv[0] + sh_len + 1; … … 2901 2914 instead of recursively calling ourselves, because we 2902 2915 cannot backslash-escape the special characters (see above). */ 2903 new_argv = (char **)xmalloc (sizeof (char *));2916 new_argv = xmalloc (sizeof (char *)); 2904 2917 line_len = strlen (new_line) - shell_len - sizeof (minus_c) + 1; 2905 2918 new_argv[0] = xmalloc (line_len + 1); … … 2959 2972 } 2960 2973 2961 argv = (char **)malloc (argc * sizeof (char *));2974 argv = xmalloc (argc * sizeof (char *)); 2962 2975 if (argv == 0) 2963 2976 abort ();
Note:
See TracChangeset
for help on using the changeset viewer.

