Changeset 903 for trunk/src/gmakenew/job.c
- Timestamp:
- May 23, 2007, 7:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/job.c
r898 r903 103 103 # include <starlet.h> 104 104 # include <lib$routines.h> 105 static void vmsWaitForChildren PARAMS ((int *));105 static void vmsWaitForChildren (int *); 106 106 #endif 107 107 … … 135 135 136 136 #if !defined (wait) && !defined (POSIX) 137 externint wait ();137 int wait (); 138 138 #endif 139 139 … … 180 180 181 181 #ifndef HAVE_UNISTD_H 182 # ifndef _MSC_VER 183 extern int dup2 (); 184 extern int execve (); 185 extern void _exit (); 182 # ifndef _MSC_VER /* bird */ 183 int dup2 (); 184 int execve (); 185 void _exit (); 186 # endif /* bird */ 187 # ifndef VMS 188 int geteuid (); 189 int getegid (); 190 int setgid (); 191 int getgid (); 186 192 # endif 187 # ifndef VMS 188 extern int geteuid (); 189 extern int getegid (); 190 extern int setgid (); 191 extern int getgid (); 192 # endif 193 #endif 194 195 extern char *allocated_variable_expand_for_file PARAMS ((char *line, struct file *file)); 196 197 extern int getloadavg PARAMS ((double loadavg[], int nelem)); 198 extern int start_remote_job PARAMS ((char **argv, char **envp, int stdin_fd, 199 int *is_remote, int *id_ptr, int *used_stdin)); 200 extern int start_remote_job_p PARAMS ((int)); 201 extern int remote_status PARAMS ((int *exit_code_ptr, int *signal_ptr, 202 int *coredump_ptr, int block)); 203 204 RETSIGTYPE child_handler PARAMS ((int)); 205 static void free_child PARAMS ((struct child *)); 206 static void start_job_command PARAMS ((struct child *child)); 207 static int load_too_high PARAMS ((void)); 208 static int job_next_command PARAMS ((struct child *)); 209 static int start_waiting_job PARAMS ((struct child *)); 193 #endif 194 195 int getloadavg (double loadavg[], int nelem); 196 int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote, 197 int *id_ptr, int *used_stdin); 198 int start_remote_job_p (int); 199 int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr, 200 int block); 201 202 RETSIGTYPE child_handler (int); 203 static void free_child (struct child *); 204 static void start_job_command (struct child *child); 205 static int load_too_high (void); 206 static int job_next_command (struct child *); 207 static int start_waiting_job (struct child *); 210 208 211 209 … … 310 308 { 311 309 const unsigned final_size = path_size + size + 1; 312 char *const path = (char *)xmalloc (final_size);310 char *const path = xmalloc (final_size); 313 311 memcpy (path, temp_path, final_size); 314 312 *fd = _open_osfhandle ((long)h, 0); … … 369 367 i = 0; 370 368 while (known_os2shells[i] != NULL) { 371 if (str icmp (name, known_os2shells[i]) == 0) /* strcasecmp() */369 if (strcasecmp (name, known_os2shells[i]) == 0) 372 370 return 0; /* not a unix shell */ 373 371 i++; … … 386 384 387 385 static void 388 child_error (c har *target_name, int exit_code, int exit_sig, int coredump,389 int ignored)386 child_error (const char *target_name, 387 int exit_code, int exit_sig, int coredump, int ignored) 390 388 { 391 389 if (ignored && silent_flag) … … 435 433 } 436 434 437 #if defined __EMX__ && !defined(__INNOTEK_LIBC__) 435 #if defined __EMX__ && !defined(__INNOTEK_LIBC__) /* bird */ 438 436 /* The signal handler must called only once! */ 439 437 signal (SIGCHLD, SIG_DFL); … … 510 508 511 509 The test and decrement are not atomic; if it is compiled into: 512 510 register = dead_children - 1; 513 511 dead_children = register; 514 512 a SIGCHLD could come between the two instructions. … … 925 923 for (i = 0; i < child->file->cmds->ncommand_lines; ++i) 926 924 free (child->command_lines[i]); 927 free ( (char *)child->command_lines);925 free (child->command_lines); 928 926 } 929 927 … … 933 931 while (*ep != 0) 934 932 free (*ep++); 935 free ( (char *)child->environment);936 } 937 938 free ( (char *)child);933 free (child->environment); 934 } 935 936 free (child); 939 937 } 940 938 … … 977 975 struct sigaction sa; 978 976 979 #if defined(__EMX__) && !defined(__KLIBC__) 977 #if defined(__EMX__) && !defined(__KLIBC__) /* bird */ 980 978 /* The child handler must be turned off here. */ 981 979 signal (SIGCHLD, SIG_DFL); 982 980 #endif 983 981 984 bzero ((char *) &sa, sizeof sa);982 memset (&sa, '\0', sizeof sa); 985 983 sa.sa_handler = child_handler; 986 984 sa.sa_flags = set_handler ? 0 : SA_RESTART; … … 1098 1096 #ifndef VMS 1099 1097 free (argv[0]); 1100 free ( (char *)argv);1098 free (argv); 1101 1099 #endif 1102 1100 child->file->update_status = 1; … … 1113 1111 { 1114 1112 free (argv[0]); 1115 free ( (char *)argv);1113 free (argv); 1116 1114 } 1117 1115 #endif … … 1184 1182 { 1185 1183 free (argv[0]); 1186 free ( (char *)argv);1184 free (argv); 1187 1185 goto next_command; 1188 1186 } … … 1195 1193 #ifndef VMS 1196 1194 free (argv[0]); 1197 free ( (char *)argv);1195 free (argv); 1198 1196 #endif 1199 1197 goto next_command; … … 1506 1504 #ifndef VMS 1507 1505 free (argv[0]); 1508 free ( (char *)argv);1506 free (argv); 1509 1507 #endif 1510 1508 … … 1625 1623 new_job (struct file *file) 1626 1624 { 1627 registerstruct commands *cmds = file->cmds;1628 registerstruct child *c;1625 struct commands *cmds = file->cmds; 1626 struct child *c; 1629 1627 char **lines; 1630 registerunsigned int i;1628 unsigned int i; 1631 1629 1632 1630 /* Let any previously decided-upon jobs that are waiting … … 1641 1639 1642 1640 /* Expand the command lines and store the results in LINES. */ 1643 lines = (char **)xmalloc (cmds->ncommand_lines * sizeof (char *));1641 lines = xmalloc (cmds->ncommand_lines * sizeof (char *)); 1644 1642 for (i = 0; i < cmds->ncommand_lines; ++i) 1645 1643 { … … 1667 1665 we processed (where IN points) and the new chunk 1668 1666 we are about to process (where REF points). */ 1669 bcopy (in, out, ref - in);1667 memmove (out, in, ref - in); 1670 1668 1671 1669 /* Move both pointers past the boring stuff. */ … … 1745 1743 `struct child', and add that to the chain. */ 1746 1744 1747 c = (struct child *)xmalloc (sizeof (struct child));1748 bzero ((char *)c, sizeof (struct child));1745 c = xmalloc (sizeof (struct child)); 1746 memset (c, '\0', sizeof (struct child)); 1749 1747 c->file = file; 1750 1748 c->command_lines = lines; … … 1866 1864 /* The job is now primed. Start it running. 1867 1865 (This will notice if there are in fact no commands.) */ 1868 (void) start_waiting_job (c); 1866 if (cmds->fileinfo.filenm) 1867 DB (DB_BASIC, (_("Invoking commands from %s:%lu to update target `%s'.\n"), 1868 cmds->fileinfo.filenm, cmds->fileinfo.lineno, 1869 c->file->name)); 1870 else 1871 DB (DB_BASIC, (_("Invoking builtin commands to update target `%s'.\n"), 1872 c->file->name)); 1873 1874 1875 start_waiting_job (c); 1869 1876 1870 1877 #ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL … … 2293 2300 # endif 2294 2301 2295 new_argv = (char **)alloca ((1 + argc + 1) * sizeof (char *));2302 new_argv = alloca ((1 + argc + 1) * sizeof (char *)); 2296 2303 new_argv[0] = shell; 2297 2304 … … 2486 2493 "shift", "switch", "test", "times", "trap", 2487 2494 "umask", "wait", "while", 0 }; 2488 #endif 2489 register int i; 2490 register char *p; 2491 register char *ap; 2495 # ifdef HAVE_DOS_PATHS 2496 /* This is required if the MSYS/Cygwin ports (which do not define 2497 WINDOWS32) are compiled with HAVE_DOS_PATHS defined, which uses 2498 sh_chars_sh[] directly (see below). */ 2499 static char *sh_chars_sh = sh_chars; 2500 # endif /* HAVE_DOS_PATHS */ 2501 #endif 2502 int i; 2503 char *p; 2504 char *ap; 2492 2505 char *end; 2493 2506 int instring, word_has_equals, seen_nonequals, last_argument_was_empty; … … 2521 2534 else if (strcmp (shell, default_shell)) 2522 2535 { 2523 char *s1 = _fullpath (NULL, shell, 0);2524 char *s2 = _fullpath (NULL, default_shell, 0);2525 2526 slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : ""));2536 char *s1 = _fullpath (NULL, shell, 0); 2537 char *s2 = _fullpath (NULL, default_shell, 0); 2538 2539 slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : "")); 2527 2540 2528 2541 if (s1) … … 2535 2548 #else /* not WINDOWS32 */ 2536 2549 #if defined (__MSDOS__) || defined (__EMX__) 2537 else if (str icmp (shell, default_shell))2550 else if (strcasecmp (shell, default_shell)) 2538 2551 { 2539 2552 extern int _is_unixy_shell (const char *_path); … … 2587 2600 2588 2601 /* More than 1 arg per character is impossible. */ 2589 new_argv = (char **)xmalloc (i * sizeof (char *));2602 new_argv = xmalloc (i * sizeof (char *)); 2590 2603 2591 2604 /* All the args can fit in a buffer as big as LINE is. */ 2592 ap = new_argv[0] = argstr = (char *)xmalloc (i);2605 ap = new_argv[0] = argstr = xmalloc (i); 2593 2606 end = ap + i; 2594 2607 … … 2629 2642 *(ap++) = *p; 2630 2643 } 2631 /* If there's a TABhere, skip it. */2632 if (p[1] == '\t')2644 /* If there's a command prefix char here, skip it. */ 2645 if (p[1] == cmd_prefix) 2633 2646 ++p; 2634 2647 } … … 2679 2692 ++p; 2680 2693 2681 /* If there is a tab after a backslash-newline, remove it. */ 2682 if (p[1] == '\t') 2694 /* If there is a command prefix after a backslash-newline, 2695 remove it. */ 2696 if (p[1] == cmd_prefix) 2683 2697 ++p; 2684 2698 … … 2807 2821 /* Line was empty. */ 2808 2822 free (argstr); 2809 free ( (char *)new_argv);2823 free (new_argv); 2810 2824 return 0; 2811 2825 } … … 2820 2834 /* Free the old argument list we were working on. */ 2821 2835 free (argstr); 2822 free ( (char *)new_argv);2836 free (new_argv); 2823 2837 } 2824 2838 … … 2833 2847 char *dptr; 2834 2848 2835 buffer = (char *)xmalloc (strlen (line)+1);2849 buffer = xmalloc (strlen (line)+1); 2836 2850 2837 2851 ptr = line; … … 2850 2864 *dptr = 0; 2851 2865 2852 new_argv = (char **)xmalloc (2 * sizeof (char *));2866 new_argv = xmalloc (2 * sizeof (char *)); 2853 2867 new_argv[0] = buffer; 2854 2868 new_argv[1] = 0; … … 2886 2900 unsigned int line_len = strlen (line); 2887 2901 2888 char *new_line = (char *) alloca (shell_len + (sizeof (minus_c) -1)2889 + (line_len *2) + 1);2902 char *new_line = alloca (shell_len + (sizeof (minus_c)-1) 2903 + (line_len*2) + 1); 2890 2904 char *command_ptr = NULL; /* used for batch_mode_shell mode */ 2891 2905 … … 2896 2910 2897 2911 ap = new_line; 2898 bcopy (shell, ap, shell_len);2912 memcpy (ap, shell, shell_len); 2899 2913 ap += shell_len; 2900 bcopy (minus_c, ap, sizeof (minus_c) - 1);2914 memcpy (ap, minus_c, sizeof (minus_c) - 1); 2901 2915 ap += sizeof (minus_c) - 1; 2902 2916 command_ptr = ap; … … 2930 2944 2931 2945 ++p; 2932 if (p[1] == '\t')2946 if (p[1] == cmd_prefix) 2933 2947 ++p; 2934 2948 … … 2965 2979 /* Need to allocate new_argv, although it's unused, because 2966 2980 start_job_command will want to free it and its 0'th element. */ 2967 new_argv = (char **)xmalloc(2 * sizeof (char *));2981 new_argv = xmalloc(2 * sizeof (char *)); 2968 2982 new_argv[0] = xstrdup (""); 2969 2983 new_argv[1] = NULL; … … 2992 3006 2993 3007 /* create argv */ 2994 new_argv = (char **)xmalloc(3 * sizeof (char *));3008 new_argv = xmalloc(3 * sizeof (char *)); 2995 3009 if (unixy_shell) { 2996 3010 new_argv[0] = xstrdup (shell); … … 3004 3018 #endif /* WINDOWS32 */ 3005 3019 if (unixy_shell) 3006 new_argv = construct_command_argv_internal (new_line, (char **) NULL, 3007 (char *) 0, (char *) 0, 3008 (char **) 0); 3020 new_argv = construct_command_argv_internal (new_line, 0, 0, 0, 0); 3009 3021 #ifdef __EMX__ 3010 3022 else if (!unixy_shell) … … 3023 3035 { 3024 3036 q += 2; /* remove '\\' and '\n' */ 3025 if (q[0] == '\t') 3026 q++; /* remove 1st tab in the next line */ 3037 /* Remove any command prefix in the next line */ 3038 if (q[0] == cmd_prefix) 3039 q++; 3027 3040 } 3028 3041 else … … 3064 3077 3065 3078 /* exactly 3 arguments + NULL */ 3066 new_argv = (char **)xmalloc (4 * sizeof (char *));3079 new_argv = xmalloc (4 * sizeof (char *)); 3067 3080 /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times 3068 3081 the trailing '\0' */ 3069 new_argv[0] = (char *)malloc (sh_len + line_len + 5);3082 new_argv[0] = xmalloc (sh_len + line_len + 5); 3070 3083 memcpy (new_argv[0], shell, sh_len + 1); 3071 3084 new_argv[1] = new_argv[0] + sh_len + 1; … … 3082 3095 instead of recursively calling ourselves, because we 3083 3096 cannot backslash-escape the special characters (see above). */ 3084 new_argv = (char **)xmalloc (sizeof (char *));3097 new_argv = xmalloc (sizeof (char *)); 3085 3098 line_len = strlen (new_line) - shell_len - sizeof (minus_c) + 1; 3086 3099 new_argv[0] = xmalloc (line_len + 1); … … 3140 3153 } 3141 3154 3142 argv = (char **)malloc (argc * sizeof (char *));3155 argv = xmalloc (argc * sizeof (char *)); 3143 3156 if (argv == 0) 3144 3157 abort ();
Note:
See TracChangeset
for help on using the changeset viewer.