Changeset 501 in kBuild for vendor/gnumake/current/w32/subproc/sub_proc.c
- Timestamp:
- Sep 15, 2006 2:30:32 AM (18 years ago)
- File:
-
- 1 edited
-
vendor/gnumake/current/w32/subproc/sub_proc.c (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/w32/subproc/sub_proc.c
r284 r501 1 /* Process handling for Windows. 2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 3 2006 Free Software Foundation, Inc. 4 This file is part of GNU Make. 5 6 GNU Make is free software; you can redistribute it and/or modify it under the 7 terms of the GNU General Public License as published by the Free Software 8 Foundation; either version 2, or (at your option) any later version. 9 10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 GNU Make; see the file COPYING. If not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 17 1 18 #include <stdlib.h> 2 19 #include <stdio.h> 3 20 #include <process.h> /* for msvc _beginthreadex, _endthreadex */ 21 #include <signal.h> 4 22 #include <windows.h> 5 23 … … 31 49 32 50 /* keep track of children so we can implement a waitpid-like routine */ 33 static sub_process *proc_array[ 256];51 static sub_process *proc_array[MAXIMUM_WAIT_OBJECTS]; 34 52 static int proc_index = 0; 35 53 static int fake_exits_pending = 0; … … 66 84 process_wait_for_any_private(void) 67 85 { 68 HANDLE handles[ 256];86 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; 69 87 DWORD retval, which; 70 88 int i; … … 120 138 process_register(HANDLE proc) 121 139 { 122 proc_array[proc_index++] = (sub_process *) proc; 140 if (proc_index < MAXIMUM_WAIT_OBJECTS) 141 proc_array[proc_index++] = (sub_process *) proc; 142 } 143 144 /* 145 * Return the number of processes that we are still waiting for. 146 */ 147 int 148 process_used_slots(void) 149 { 150 return proc_index; 123 151 } 124 152 … … 163 191 164 192 long 165 process_errno(HANDLE proc) 166 { 167 return (((sub_process *)proc)->lerrno); 193 process_signal(HANDLE proc) 194 { 195 if (proc == INVALID_HANDLE_VALUE) return 0; 196 return (((sub_process *)proc)->signal); 168 197 } 169 198 170 199 long 171 process_signal(HANDLE proc)172 {173 return (((sub_process *)proc)->signal);174 }175 176 long177 200 process_last_err(HANDLE proc) 178 201 { 202 if (proc == INVALID_HANDLE_VALUE) return ERROR_INVALID_HANDLE; 179 203 return (((sub_process *)proc)->last_err); 180 204 } 181 205 182 long206 long 183 207 process_exit_code(HANDLE proc) 184 208 { 209 if (proc == INVALID_HANDLE_VALUE) return EXIT_FAILURE; 185 210 return (((sub_process *)proc)->exit_code); 186 211 } 187 212 188 char * 213 /* 214 2006-02: 215 All the following functions are currently unused. 216 All of them would crash gmake if called with argument INVALID_HANDLE_VALUE. 217 Hence whoever wants to use one of this functions must invent and implement 218 a reasonable error handling for this function. 219 220 char * 189 221 process_outbuf(HANDLE proc) 190 222 { … … 192 224 } 193 225 194 char *226 char * 195 227 process_errbuf(HANDLE proc) 196 228 { … … 198 230 } 199 231 200 int232 int 201 233 process_outcnt(HANDLE proc) 202 234 { … … 204 236 } 205 237 206 int238 int 207 239 process_errcnt(HANDLE proc) 208 240 { … … 210 242 } 211 243 212 void244 void 213 245 process_pipes(HANDLE proc, int pipes[3]) 214 246 { … … 218 250 return; 219 251 } 220 252 */ 221 253 222 254 HANDLE … … 369 401 * Description: Create the child process to be helped 370 402 * 371 * Returns: 403 * Returns: success <=> 0 372 404 * 373 405 * Notes/Dependencies: … … 523 555 pproc->last_err = GetLastError(); 524 556 pproc->lerrno = E_FORK; 525 fprintf(stderr, "process_begin: CreateProcess(%s, %s, ...) failed.\n", exec_path, command_line); 557 fprintf(stderr, "process_begin: CreateProcess(%s, %s, ...) failed.\n", 558 exec_path ? exec_path : "NULL", command_line); 526 559 if (envblk) free(envblk); 527 560 free( command_line ); … … 535 568 536 569 /* Close the halves of the pipes we don't need */ 537 if (pproc->sv_stdin) { 538 CloseHandle((HANDLE)pproc->sv_stdin[1]); 539 (HANDLE)pproc->sv_stdin[1] = 0; 540 } 541 if (pproc->sv_stdout) { 542 CloseHandle((HANDLE)pproc->sv_stdout[1]); 543 (HANDLE)pproc->sv_stdout[1] = 0; 544 } 545 if (pproc->sv_stderr) { 546 CloseHandle((HANDLE)pproc->sv_stderr[1]); 547 (HANDLE)pproc->sv_stderr[1] = 0; 548 } 570 CloseHandle((HANDLE)pproc->sv_stdin[1]); 571 CloseHandle((HANDLE)pproc->sv_stdout[1]); 572 CloseHandle((HANDLE)pproc->sv_stderr[1]); 573 pproc->sv_stdin[1] = 0; 574 pproc->sv_stdout[1] = 0; 575 pproc->sv_stderr[1] = 0; 549 576 550 577 free( command_line ); … … 658 685 bool_t stdin_eof = FALSE, stdout_eof = FALSE, stderr_eof = FALSE; 659 686 HANDLE childhand = (HANDLE) pproc->pid; 660 HANDLE tStdin , tStdout, tStderr;661 DWORDdwStdin, dwStdout, dwStderr;687 HANDLE tStdin = NULL, tStdout = NULL, tStderr = NULL; 688 unsigned int dwStdin, dwStdout, dwStderr; 662 689 HANDLE wait_list[4]; 663 690 DWORD wait_count; … … 675 702 stdin_eof = TRUE; 676 703 CloseHandle((HANDLE)pproc->sv_stdin[0]); 677 (HANDLE)pproc->sv_stdin[0] = 0;704 pproc->sv_stdin[0] = 0; 678 705 } else { 679 706 tStdin = (HANDLE) _beginthreadex( 0, 1024, 680 (unsigned (__stdcall *) (void *))proc_stdin_thread, pproc, 0,681 (unsigned int *)&dwStdin);707 (unsigned (__stdcall *) (void *))proc_stdin_thread, 708 pproc, 0, &dwStdin); 682 709 if (tStdin == 0) { 683 710 pproc->last_err = GetLastError(); … … 692 719 tStdout = (HANDLE) _beginthreadex( 0, 1024, 693 720 (unsigned (__stdcall *) (void *))proc_stdout_thread, pproc, 0, 694 (unsigned int *)&dwStdout);721 &dwStdout); 695 722 tStderr = (HANDLE) _beginthreadex( 0, 1024, 696 723 (unsigned (__stdcall *) (void *))proc_stderr_thread, pproc, 0, 697 (unsigned int *)&dwStderr);724 &dwStderr); 698 725 699 726 if (tStdout == 0 || tStderr == 0) { … … 740 767 if (ready_hand == tStdin) { 741 768 CloseHandle((HANDLE)pproc->sv_stdin[0]); 742 (HANDLE)pproc->sv_stdin[0] = 0;769 pproc->sv_stdin[0] = 0; 743 770 CloseHandle(tStdin); 744 771 tStdin = 0; … … 748 775 749 776 CloseHandle((HANDLE)pproc->sv_stdout[0]); 750 (HANDLE)pproc->sv_stdout[0] = 0;777 pproc->sv_stdout[0] = 0; 751 778 CloseHandle(tStdout); 752 779 tStdout = 0; … … 756 783 757 784 CloseHandle((HANDLE)pproc->sv_stderr[0]); 758 (HANDLE)pproc->sv_stderr[0] = 0;785 pproc->sv_stderr[0] = 0; 759 786 CloseHandle(tStderr); 760 787 tStderr = 0; … … 763 790 } else if (ready_hand == childhand) { 764 791 765 GetExitCodeResult = GetExitCodeProcess(childhand, (DWORD*)&pproc->exit_code); 792 DWORD ierr; 793 GetExitCodeResult = GetExitCodeProcess(childhand, &ierr); 794 if (ierr == CONTROL_C_EXIT) { 795 pproc->signal = SIGINT; 796 } else { 797 pproc->exit_code = ierr; 798 } 766 799 if (GetExitCodeResult == FALSE) { 767 800 pproc->last_err = GetLastError(); … … 812 845 DWORD wait_return; 813 846 BOOL GetExitCodeResult; 847 DWORD ierr; 814 848 815 849 if (proc == NULL) … … 855 889 } 856 890 857 GetExitCodeResult = GetExitCodeProcess(childhand, (DWORD*)&pproc->exit_code); 891 GetExitCodeResult = GetExitCodeProcess(childhand, &ierr); 892 if (ierr == CONTROL_C_EXIT) { 893 pproc->signal = SIGINT; 894 } else { 895 pproc->exit_code = ierr; 896 } 858 897 if (GetExitCodeResult == FALSE) { 859 898 pproc->last_err = GetLastError(); … … 1156 1195 HANDLE hProcess; 1157 1196 1197 if (proc_index >= MAXIMUM_WAIT_OBJECTS) { 1198 DB (DB_JOBS, ("process_easy: All process slots used up\n")); 1199 return INVALID_HANDLE_VALUE; 1200 } 1158 1201 if (DuplicateHandle(GetCurrentProcess(), 1159 1202 GetStdHandle(STD_INPUT_HANDLE), … … 1164 1207 DUPLICATE_SAME_ACCESS) == FALSE) { 1165 1208 fprintf(stderr, 1166 "process_easy: DuplicateHandle(In) failed (e=% d)\n",1209 "process_easy: DuplicateHandle(In) failed (e=%ld)\n", 1167 1210 GetLastError()); 1168 1211 return INVALID_HANDLE_VALUE; … … 1176 1219 DUPLICATE_SAME_ACCESS) == FALSE) { 1177 1220 fprintf(stderr, 1178 "process_easy: DuplicateHandle(Out) failed (e=% d)\n",1221 "process_easy: DuplicateHandle(Out) failed (e=%ld)\n", 1179 1222 GetLastError()); 1180 1223 return INVALID_HANDLE_VALUE; … … 1188 1231 DUPLICATE_SAME_ACCESS) == FALSE) { 1189 1232 fprintf(stderr, 1190 "process_easy: DuplicateHandle(Err) failed (e=% d)\n",1233 "process_easy: DuplicateHandle(Err) failed (e=%ld)\n", 1191 1234 GetLastError()); 1192 1235 return INVALID_HANDLE_VALUE;
Note:
See TracChangeset
for help on using the changeset viewer.

