MCPcopy Create free account
hub / github.com/Kitware/CMake / kwsysProcessInitialize

Function kwsysProcessInitialize

Source/kwsys/ProcessUNIX.c:1505–1585  ·  view source on GitHub ↗

Initialize a process control structure for kwsysProcess_Execute. */

Source from the content-addressed store, hash-verified

1503
1504/* Initialize a process control structure for kwsysProcess_Execute. */
1505static int kwsysProcessInitialize(kwsysProcess* cp)
1506{
1507 int i;
1508 pid_t volatile* oldForkPIDs;
1509 for (i = 0; i < KWSYSPE_PIPE_COUNT; ++i) {
1510 cp->PipeReadEnds[i] = -1;
1511 }
1512 for (i = 0; i < 3; ++i) {
1513 cp->PipeChildStd[i] = -1;
1514 }
1515 cp->SignalPipe = -1;
1516 cp->SelectError = 0;
1517 cp->StartTime.tv_sec = -1;
1518 cp->StartTime.tv_usec = -1;
1519 cp->TimeoutTime.tv_sec = -1;
1520 cp->TimeoutTime.tv_usec = -1;
1521 cp->TimeoutExpired = 0;
1522 cp->PipesLeft = 0;
1523 cp->CommandsLeft = 0;
1524#if KWSYSPE_USE_SELECT
1525 FD_ZERO(&cp->PipeSet); // NOLINT(readability-isolate-declaration)
1526#endif
1527 cp->State = kwsysProcess_State_Starting;
1528 cp->Killed = 0;
1529 cp->ErrorMessage[0] = 0;
1530
1531 oldForkPIDs = cp->ForkPIDs;
1532 cp->ForkPIDs = (pid_t volatile*)malloc(sizeof(pid_t volatile) *
1533 (size_t)(cp->NumberOfCommands));
1534 kwsysProcessVolatileFree(oldForkPIDs);
1535 if (!cp->ForkPIDs) {
1536 return 0;
1537 }
1538 for (i = 0; i < cp->NumberOfCommands; ++i) {
1539 cp->ForkPIDs[i] = 0; /* can't use memset due to volatile */
1540 }
1541
1542 free(cp->CommandExitCodes);
1543 cp->CommandExitCodes =
1544 (int*)malloc(sizeof(int) * (size_t)(cp->NumberOfCommands));
1545 if (!cp->CommandExitCodes) {
1546 return 0;
1547 }
1548 memset(cp->CommandExitCodes, 0,
1549 sizeof(int) * (size_t)(cp->NumberOfCommands));
1550
1551 /* Allocate process result information for each process. */
1552 free(cp->ProcessResults);
1553 cp->ProcessResults = (kwsysProcessResults*)malloc(
1554 sizeof(kwsysProcessResults) * (size_t)(cp->NumberOfCommands));
1555 if (!cp->ProcessResults) {
1556 return 0;
1557 }
1558 memset(cp->ProcessResults, 0,
1559 sizeof(kwsysProcessResults) * (size_t)(cp->NumberOfCommands));
1560 for (i = 0; i < cp->NumberOfCommands; i++) {
1561 cp->ProcessResults[i].ExitException = kwsysProcess_Exception_None;
1562 cp->ProcessResults[i].State = kwsysProcess_StateByIndex_Starting;

Callers 1

kwsysProcess_ExecuteFunction · 0.70

Calls 1

kwsysProcessVolatileFreeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…