Changeset 3199 for trunk/src/kmk/kmkbuiltin/kSubmit.c
- Timestamp:
- Mar 28, 2018, 8:56:21 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/kSubmit.c
r3198 r3199 110 110 /** For overlapped read (have valid event semaphore). */ 111 111 OVERLAPPED OverlappedRead; 112 # ifdef CONFIG_NEW_WIN_CHILDREN 113 /** Standard output catcher (reused). */ 114 PWINCCWPIPE pStdOut; 115 /** Standard error catcher (reused). */ 116 PWINCCWPIPE pStdErr; 117 # endif 112 118 #else 113 119 /** The socket descriptor we use to talk to the kWorker process. */ … … 424 430 wchar_t wszPipeName[128]; 425 431 HANDLE hWorkerPipe; 426 SECURITY_ATTRIBUTES SecAttrs = { /*nLength:*/ sizeof(SecAttrs), /*pAttrs:*/ NULL, /*bInheritHandle:*/ TRUE };427 432 int iProcessorGroup = -1; /** @todo determine process group. */ 428 433 429 434 /* 430 * Create the bi-directional pipe . Worker end is marked inheritable, our end is not.435 * Create the bi-directional pipe with overlapping I/O enabled. 431 436 */ 432 437 if (s_fDenyRemoteClients == ~(DWORD)0) … … 441 446 65536 /*cbInBuffer*/, 442 447 0 /*cMsDefaultTimeout -> 50ms*/, 443 &SecAttrs /*inherit */);448 NULL /* pSecAttr - no inherit */); 444 449 if (hWorkerPipe != INVALID_HANDLE_VALUE) 445 450 { … … 519 524 BOOL afReplace[3] = { TRUE, FALSE, FALSE }; 520 525 HANDLE ahReplace[3] = { hWorkerPipe, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; 526 if (pWorker->pStdOut) 527 { 528 afReplace[1] = TRUE; 529 afReplace[2] = TRUE; 530 ahReplace[1] = pWorker->pStdOut->hPipeChild; 531 ahReplace[2] = pWorker->pStdErr->hPipeChild; 532 } 533 521 534 rc = nt_child_inject_standard_handles(ProcInfo.hProcess, afReplace, ahReplace, szErrMsg, sizeof(szErrMsg)); 522 535 if (rc == 0) … … 570 583 } 571 584 else 572 rc = errx(pCtx, -2, "CreateProcessW failed: %u (exe=% s cmdline=%s)",585 rc = errx(pCtx, -2, "CreateProcessW failed: %u (exe=%S cmdline=%S)", 573 586 GetLastError(), wszExecutable, wszCommandLine); 574 587 CloseHandle(pWorker->OverlappedRead.hEvent); … … 638 651 pWorker->OverlappedRead.hEvent = INVALID_HANDLE_VALUE; 639 652 653 if (pWorker->pStdOut) 654 MkWinChildcareWorkerDrainPipes(NULL, pWorker->pStdOut, pWorker->pStdErr); 655 640 656 /* It's probably shutdown already, if not give it 10 milliseconds before 641 657 we terminate it forcefully. */ … … 644 660 { 645 661 BOOL fRc = TerminateProcess(pWorker->hProcess, 127); 662 663 if (pWorker->pStdOut) 664 MkWinChildcareWorkerDrainPipes(NULL, pWorker->pStdOut, pWorker->pStdErr); 665 646 666 rcWait = WaitForSingleObject(pWorker->hProcess, 100); 647 667 if (rcWait != WAIT_OBJECT_0) 648 668 warnx(pCtx, "WaitForSingleObject returns %u (and TerminateProcess %d)", rcWait, fRc); 649 669 } 670 671 if (pWorker->pStdOut) 672 MkWinChildcareWorkerDrainPipes(NULL, pWorker->pStdOut, pWorker->pStdErr); 650 673 651 674 if (!CloseHandle(pWorker->hProcess)) … … 719 742 pWorker = (PWORKERINSTANCE)xcalloc(sizeof(*pWorker)); 720 743 pWorker->cBits = cBitsWorker; 721 if (kSubmitSpawnWorker(pCtx, pWorker, cVerbosity) == 0) 722 { 723 /* 724 * Insert it into the process ID hash table and idle list. 725 */ 726 size_t idxHash = KWORKER_PID_HASH(pWorker->pid); 727 pWorker->pNextPidHash = g_apPidHash[idxHash]; 728 g_apPidHash[idxHash] = pWorker; 729 730 kSubmitListAppend(&g_IdleList, pWorker); 731 return pWorker; 732 } 744 #if defined(CONFIG_NEW_WIN_CHILDREN) && defined(KBUILD_OS_WINDOWS) 745 if (output_sync != OUTPUT_SYNC_NONE) 746 { 747 pWorker->pStdOut = MkWinChildcareCreateWorkerPipe(1, g_uWorkerSeqNo << 1); 748 pWorker->pStdErr = MkWinChildcareCreateWorkerPipe(2, g_uWorkerSeqNo << 1); 749 } 750 if ( output_sync == OUTPUT_SYNC_NONE 751 || ( pWorker->pStdOut != NULL 752 && pWorker->pStdErr != NULL)) 753 #endif 754 { 755 if (kSubmitSpawnWorker(pCtx, pWorker, cVerbosity) == 0) 756 { 757 /* 758 * Insert it into the process ID hash table and idle list. 759 */ 760 size_t idxHash = KWORKER_PID_HASH(pWorker->pid); 761 pWorker->pNextPidHash = g_apPidHash[idxHash]; 762 g_apPidHash[idxHash] = pWorker; 763 764 kSubmitListAppend(&g_IdleList, pWorker); 765 return pWorker; 766 } 767 } 768 #if defined(CONFIG_NEW_WIN_CHILDREN) && defined(KBUILD_OS_WINDOWS) 769 if (pWorker->pStdErr) 770 MkWinChildcareDeleteWorkerPipe(pWorker->pStdErr); 771 if (pWorker->pStdOut) 772 MkWinChildcareDeleteWorkerPipe(pWorker->pStdOut); 773 #endif 733 774 734 775 free(pWorker); … … 1109 1150 } 1110 1151 # else 1111 if (MkWinChildCreateSubmit((intptr_t)pWorker->OverlappedRead.hEvent, pWorker, pPidSpawned) == 0) 1152 if (MkWinChildCreateSubmit((intptr_t)pWorker->OverlappedRead.hEvent, pWorker, 1153 pWorker->pStdOut, pWorker->pStdErr, pPidSpawned) == 0) 1112 1154 { /* likely */ } 1113 1155 else
Note:
See TracChangeset
for help on using the changeset viewer.