Initialize a process control structure for kwsysProcess_Execute. */
| 1577 | |
| 1578 | /* Initialize a process control structure for kwsysProcess_Execute. */ |
| 1579 | int kwsysProcessInitialize(kwsysProcess* cp) |
| 1580 | { |
| 1581 | int i; |
| 1582 | /* Reset internal status flags. */ |
| 1583 | cp->TimeoutExpired = 0; |
| 1584 | cp->Terminated = 0; |
| 1585 | cp->Killed = 0; |
| 1586 | |
| 1587 | free(cp->ProcessResults); |
| 1588 | /* Allocate process result information for each process. */ |
| 1589 | cp->ProcessResults = (kwsysProcessResults*)malloc( |
| 1590 | sizeof(kwsysProcessResults) * (cp->NumberOfCommands)); |
| 1591 | if (!cp->ProcessResults) { |
| 1592 | return 0; |
| 1593 | } |
| 1594 | ZeroMemory(cp->ProcessResults, |
| 1595 | sizeof(kwsysProcessResults) * cp->NumberOfCommands); |
| 1596 | for (i = 0; i < cp->NumberOfCommands; i++) { |
| 1597 | cp->ProcessResults[i].ExitException = kwsysProcess_Exception_None; |
| 1598 | cp->ProcessResults[i].State = kwsysProcess_StateByIndex_Starting; |
| 1599 | cp->ProcessResults[i].ExitCode = 1; |
| 1600 | cp->ProcessResults[i].ExitValue = 1; |
| 1601 | strcpy(cp->ProcessResults[i].ExitExceptionString, "No exception"); |
| 1602 | } |
| 1603 | |
| 1604 | /* Allocate process information for each process. */ |
| 1605 | free(cp->ProcessInformation); |
| 1606 | cp->ProcessInformation = (PROCESS_INFORMATION*)malloc( |
| 1607 | sizeof(PROCESS_INFORMATION) * cp->NumberOfCommands); |
| 1608 | if (!cp->ProcessInformation) { |
| 1609 | return 0; |
| 1610 | } |
| 1611 | ZeroMemory(cp->ProcessInformation, |
| 1612 | sizeof(PROCESS_INFORMATION) * cp->NumberOfCommands); |
| 1613 | free(cp->CommandExitCodes); |
| 1614 | cp->CommandExitCodes = (DWORD*)malloc(sizeof(DWORD) * cp->NumberOfCommands); |
| 1615 | if (!cp->CommandExitCodes) { |
| 1616 | return 0; |
| 1617 | } |
| 1618 | ZeroMemory(cp->CommandExitCodes, sizeof(DWORD) * cp->NumberOfCommands); |
| 1619 | |
| 1620 | /* Allocate event wait array. The first event is cp->Full, the rest |
| 1621 | are the process termination events. */ |
| 1622 | cp->ProcessEvents = |
| 1623 | (PHANDLE)malloc(sizeof(HANDLE) * (cp->NumberOfCommands + 1)); |
| 1624 | if (!cp->ProcessEvents) { |
| 1625 | return 0; |
| 1626 | } |
| 1627 | ZeroMemory(cp->ProcessEvents, sizeof(HANDLE) * (cp->NumberOfCommands + 1)); |
| 1628 | cp->ProcessEvents[0] = cp->Full; |
| 1629 | cp->ProcessEventsLength = cp->NumberOfCommands + 1; |
| 1630 | |
| 1631 | /* Allocate space to save the real working directory of this process. */ |
| 1632 | if (cp->WorkingDirectory) { |
| 1633 | cp->RealWorkingDirectoryLength = GetCurrentDirectoryW(0, 0); |
| 1634 | if (cp->RealWorkingDirectoryLength > 0) { |
| 1635 | cp->RealWorkingDirectory = |
| 1636 | malloc(cp->RealWorkingDirectoryLength * sizeof(wchar_t)); |
no outgoing calls
no test coverage detected
searching dependent graphs…