| 1684 | } |
| 1685 | |
| 1686 | DWORD kwsysProcessCreate(kwsysProcess* cp, int index, |
| 1687 | kwsysProcessCreateInformation* si) |
| 1688 | { |
| 1689 | DWORD creationFlags; |
| 1690 | DWORD error = ERROR_SUCCESS; |
| 1691 | |
| 1692 | /* Check if we are currently exiting. */ |
| 1693 | if (!kwsysTryEnterCreateProcessSection()) { |
| 1694 | /* The Ctrl handler is currently working on exiting our process. Rather |
| 1695 | than return an error code, which could cause incorrect conclusions to be |
| 1696 | reached by the caller, we simply hang. (For example, a CMake try_run |
| 1697 | configure step might cause the project to configure wrong.) */ |
| 1698 | Sleep(INFINITE); |
| 1699 | } |
| 1700 | |
| 1701 | /* Create the child in a suspended state so we can wait until all |
| 1702 | children have been created before running any one. */ |
| 1703 | creationFlags = CREATE_SUSPENDED; |
| 1704 | if (cp->CreateProcessGroup) { |
| 1705 | creationFlags |= CREATE_NEW_PROCESS_GROUP; |
| 1706 | } |
| 1707 | |
| 1708 | /* Create inherited copies of the handles. */ |
| 1709 | (error = kwsysProcessCreateChildHandle(&si->StartupInfo.hStdInput, |
| 1710 | si->hStdInput, 1)) || |
| 1711 | (error = kwsysProcessCreateChildHandle(&si->StartupInfo.hStdOutput, |
| 1712 | si->hStdOutput, 0)) || |
| 1713 | (error = kwsysProcessCreateChildHandle(&si->StartupInfo.hStdError, |
| 1714 | si->hStdError, 0)) || |
| 1715 | /* Create the process. */ |
| 1716 | (!CreateProcessW(0, cp->Commands[index], 0, 0, TRUE, creationFlags, 0, 0, |
| 1717 | &si->StartupInfo, &cp->ProcessInformation[index]) && |
| 1718 | (error = GetLastError())); |
| 1719 | |
| 1720 | /* Close the inherited copies of the handles. */ |
| 1721 | if (si->StartupInfo.hStdInput != si->hStdInput) { |
| 1722 | kwsysProcessCleanupHandle(&si->StartupInfo.hStdInput); |
| 1723 | } |
| 1724 | if (si->StartupInfo.hStdOutput != si->hStdOutput) { |
| 1725 | kwsysProcessCleanupHandle(&si->StartupInfo.hStdOutput); |
| 1726 | } |
| 1727 | if (si->StartupInfo.hStdError != si->hStdError) { |
| 1728 | kwsysProcessCleanupHandle(&si->StartupInfo.hStdError); |
| 1729 | } |
| 1730 | |
| 1731 | /* Add the process to the global list of processes. */ |
| 1732 | if (!error && |
| 1733 | !kwsysProcessesAdd(cp->ProcessInformation[index].hProcess, |
| 1734 | cp->ProcessInformation[index].dwProcessId, |
| 1735 | cp->CreateProcessGroup)) { |
| 1736 | /* This failed for some reason. Kill the suspended process. */ |
| 1737 | TerminateProcess(cp->ProcessInformation[index].hProcess, 1); |
| 1738 | /* And clean up... */ |
| 1739 | kwsysProcessCleanupHandle(&cp->ProcessInformation[index].hProcess); |
| 1740 | kwsysProcessCleanupHandle(&cp->ProcessInformation[index].hThread); |
| 1741 | strcpy(cp->ErrorMessage, "kwsysProcessesAdd function failed"); |
| 1742 | error = ERROR_NOT_ENOUGH_MEMORY; /* Most likely reason. */ |
| 1743 | } |
no test coverage detected
searching dependent graphs…