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

Function kwsysProcessCleanup

Source/kwsys/ProcessUNIX.c:1589–1651  ·  view source on GitHub ↗

Free all resources used by the given kwsysProcess instance that were allocated by kwsysProcess_Execute. */

Source from the content-addressed store, hash-verified

1587/* Free all resources used by the given kwsysProcess instance that were
1588 allocated by kwsysProcess_Execute. */
1589static void kwsysProcessCleanup(kwsysProcess* cp, int error)
1590{
1591 int i;
1592
1593 if (error) {
1594 /* We are cleaning up due to an error. Report the error message
1595 if one has not been provided already. */
1596 if (cp->ErrorMessage[0] == 0) {
1597 strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
1598 }
1599
1600 /* Set the error state. */
1601 cp->State = kwsysProcess_State_Error;
1602
1603 /* Kill any children already started. */
1604 if (cp->ForkPIDs) {
1605 int status;
1606 for (i = 0; i < cp->NumberOfCommands; ++i) {
1607 if (cp->ForkPIDs[i]) {
1608 /* Kill the child. */
1609 kwsysProcessKill(cp->ForkPIDs[i]);
1610
1611 /* Reap the child. Keep trying until the call is not
1612 interrupted. */
1613 while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) &&
1614 (errno == EINTR)) {
1615 }
1616 }
1617 }
1618 }
1619
1620 /* Restore the working directory. */
1621 if (cp->RealWorkingDirectory) {
1622 while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) {
1623 }
1624 }
1625 }
1626
1627 /* If not creating a detached child, remove this object from the
1628 global set of process objects that wish to be notified when a
1629 child exits. */
1630 if (!cp->OptionDetach) {
1631 kwsysProcessesRemove(cp);
1632 }
1633
1634 /* Free memory. */
1635 if (cp->ForkPIDs) {
1636 kwsysProcessVolatileFree(cp->ForkPIDs);
1637 cp->ForkPIDs = 0;
1638 }
1639 if (cp->RealWorkingDirectory) {
1640 free(cp->RealWorkingDirectory);
1641 cp->RealWorkingDirectory = 0;
1642 }
1643
1644 /* Close pipe handles. */
1645 for (i = 0; i < KWSYSPE_PIPE_COUNT; ++i) {
1646 kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);

Callers 3

kwsysProcess_ExecuteFunction · 0.70
kwsysProcess_DisownFunction · 0.70
kwsysProcess_WaitForExitFunction · 0.70

Calls 4

kwsysProcessVolatileFreeFunction · 0.85
kwsysProcessKillFunction · 0.70
kwsysProcessesRemoveFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…