Changeset 1167 in kBuild for trunk/src/kmk/w32
- Timestamp:
- Sep 30, 2007 9:37:09 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/w32/subproc/sub_proc.c
r1166 r1167 48 48 } sub_process; 49 49 50 static long process_file_io_private(sub_process *pproc, BOOL fNeedToWait); /* bird */ 51 50 52 /* keep track of children so we can implement a waitpid-like routine */ 51 53 static sub_process *proc_array[MAXIMUM_WAIT_OBJECTS]; … … 184 186 * Ouch! can't tell caller if this fails directly. Caller 185 187 * will have to use process_last_err() 186 */ 188 */ 189 #ifdef KMK 190 (void) process_file_io_private(pproc, FALSE); 191 #else 187 192 (void) process_file_io(pproc); 193 #endif 188 194 return ((HANDLE) pproc); 189 195 } … … 353 359 char *fname; 354 360 char *ext; 355 361 #ifdef KMK 362 size_t exec_path_len; 363 364 /* 365 * if there is an .exe extension there already, don't waste time here. 366 * If .exe scripts become common, they can be handled in a CreateProcess 367 * failure path instead of here. 368 */ 369 exec_path_len = strlen(exec_path); 370 if ( exec_path_len > 4 371 && exec_path[exec_path_len - 4] == '.' 372 && !stricmp(exec_path + exec_path_len - 3, "exe")){ 373 return((HANDLE)HFILE_ERROR); 374 } 375 376 fname = malloc(exec_path_len + 5); 377 #else 356 378 fname = malloc(strlen(exec_path) + 5); 379 #endif 357 380 strcpy(fname, exec_path); 358 381 ext = fname + strlen(fname); … … 525 548 */ 526 549 GetStartupInfo(&startInfo); 550 #ifndef KMK 527 551 startInfo.dwFlags = STARTF_USESTDHANDLES; 552 #endif 528 553 startInfo.lpReserved = 0; 529 554 startInfo.cbReserved2 = 0; 530 555 startInfo.lpReserved2 = 0; 531 556 startInfo.lpTitle = shell_name ? shell_name : exec_path; 557 #ifndef KMK 532 558 startInfo.hStdInput = (HANDLE)pproc->sv_stdin[1]; 533 559 startInfo.hStdOutput = (HANDLE)pproc->sv_stdout[1]; 534 560 startInfo.hStdError = (HANDLE)pproc->sv_stderr[1]; 561 #else 562 if ( pproc->sv_stdin[1] 563 || pproc->sv_stdout[1] 564 || pproc->sv_stderr[1]) { 565 startInfo.dwFlags = STARTF_USESTDHANDLES; 566 startInfo.hStdInput = (HANDLE)pproc->sv_stdin[1]; 567 startInfo.hStdOutput = (HANDLE)pproc->sv_stdout[1]; 568 startInfo.hStdError = (HANDLE)pproc->sv_stderr[1]; 569 } else { 570 startInfo.dwFlags = 0; 571 startInfo.hStdInput = 0; 572 startInfo.hStdOutput = 0; 573 startInfo.hStdError = 0; 574 } 575 #endif 535 576 536 577 if (as_user) { … … 568 609 569 610 /* Close the halves of the pipes we don't need */ 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; 611 #ifndef KMK 612 CloseHandle((HANDLE)pproc->sv_stdin[1]); 613 CloseHandle((HANDLE)pproc->sv_stdout[1]); 614 CloseHandle((HANDLE)pproc->sv_stderr[1]); 615 pproc->sv_stdin[1] = 0; 616 pproc->sv_stdout[1] = 0; 617 pproc->sv_stderr[1] = 0; 618 #else 619 if ((HANDLE)pproc->sv_stdin[1]) { 620 CloseHandle((HANDLE)pproc->sv_stdin[1]); 621 pproc->sv_stdin[1] = 0; 622 } 623 if ((HANDLE)pproc->sv_stdout[1]) { 624 CloseHandle((HANDLE)pproc->sv_stdout[1]); 625 pproc->sv_stdout[1] = 0; 626 } 627 if ((HANDLE)pproc->sv_stderr[1]) { 628 CloseHandle((HANDLE)pproc->sv_stderr[1]); 629 pproc->sv_stderr[1] = 0; 630 } 631 #endif 576 632 577 633 free( command_line ); … … 842 898 { 843 899 sub_process *pproc; 844 HANDLE childhand;845 DWORD wait_return;846 BOOL GetExitCodeResult;847 DWORD ierr;848 849 900 if (proc == NULL) 850 901 pproc = process_wait_for_any_private(); … … 856 907 return -1; 857 908 909 return process_file_io_private(proc, TRUE); 910 } 911 912 /* private function, avoid some kernel calls. (bird) */ 913 static long 914 process_file_io_private( 915 sub_process *pproc, 916 BOOL fNeedToWait) 917 { 918 HANDLE childhand; 919 DWORD wait_return; 920 BOOL GetExitCodeResult; 921 DWORD ierr; 922 858 923 childhand = (HANDLE) pproc->pid; 859 924 … … 877 942 878 943 /* 879 * Wait for the child process to exit 880 */ 881 882 wait_return = WaitForSingleObject(childhand, INFINITE);883 884 if (wait_return != WAIT_OBJECT_0) { 885 /* map_windows32_error_to_string(GetLastError());*/ 886 pproc->last_err = GetLastError();887 pproc->lerrno = E_SCALL;888 goto done2;944 * Wait for the child process to exit it we didn't do that already. 945 */ 946 if (fNeedToWait) { 947 wait_return = WaitForSingleObject(childhand, INFINITE); 948 if (wait_return != WAIT_OBJECT_0) { 949 /* map_windows32_error_to_string(GetLastError());*/ 950 pproc->last_err = GetLastError(); 951 pproc->lerrno = E_SCALL; 952 goto done2; 953 } 889 954 } 890 955 … … 1204 1269 char **envp) 1205 1270 { 1271 #ifndef KMK 1206 1272 HANDLE hIn; 1207 1273 HANDLE hOut; 1208 1274 HANDLE hErr; 1275 #endif 1209 1276 HANDLE hProcess; 1210 1277 … … 1213 1280 return INVALID_HANDLE_VALUE; 1214 1281 } 1282 #ifndef KMK 1215 1283 if (DuplicateHandle(GetCurrentProcess(), 1216 1284 GetStdHandle(STD_INPUT_HANDLE), … … 1251 1319 1252 1320 hProcess = process_init_fd(hIn, hOut, hErr); 1321 #else 1322 hProcess = process_init_fd(0, 0, 0); 1323 #endif /* !KMK */ 1253 1324 1254 1325 if (process_begin(hProcess, argv, envp, argv[0], NULL)) { … … 1259 1330 ((sub_process*) hProcess)->exit_code = process_last_err(hProcess); 1260 1331 1332 #ifndef KMK 1261 1333 /* close up unused handles */ 1262 1334 CloseHandle(hIn); 1263 1335 CloseHandle(hOut); 1264 1336 CloseHandle(hErr); 1337 #endif 1265 1338 } 1266 1339
Note:
See TracChangeset
for help on using the changeset viewer.