| 1888 | } |
| 1889 | |
| 1890 | static void kwsysProcessDestroy(kwsysProcess* cp) |
| 1891 | { |
| 1892 | /* A child process has terminated. Reap it if it is one handled by |
| 1893 | this object. */ |
| 1894 | int i; |
| 1895 | /* Temporarily disable signals that access ForkPIDs. We don't want them to |
| 1896 | read a reaped PID, and writes to ForkPIDs are not atomic. */ |
| 1897 | sigset_t mask; |
| 1898 | sigset_t old_mask; |
| 1899 | sigemptyset(&mask); |
| 1900 | sigaddset(&mask, SIGINT); |
| 1901 | sigaddset(&mask, SIGTERM); |
| 1902 | if (sigprocmask(SIG_BLOCK, &mask, &old_mask) < 0) { |
| 1903 | return; |
| 1904 | } |
| 1905 | |
| 1906 | for (i = 0; i < cp->NumberOfCommands; ++i) { |
| 1907 | if (cp->ForkPIDs[i]) { |
| 1908 | int result; |
| 1909 | while (((result = waitpid(cp->ForkPIDs[i], &cp->CommandExitCodes[i], |
| 1910 | WNOHANG)) < 0) && |
| 1911 | (errno == EINTR)) { |
| 1912 | } |
| 1913 | if (result > 0) { |
| 1914 | /* This child has terminated. */ |
| 1915 | cp->ForkPIDs[i] = 0; |
| 1916 | if (--cp->CommandsLeft == 0) { |
| 1917 | /* All children have terminated. Close the signal pipe |
| 1918 | write end so that no more notifications are sent to this |
| 1919 | object. */ |
| 1920 | kwsysProcessCleanupDescriptor(&cp->SignalPipe); |
| 1921 | |
| 1922 | /* TODO: Once the children have terminated, switch |
| 1923 | WaitForData to use a non-blocking read to get the |
| 1924 | rest of the data from the pipe. This is needed when |
| 1925 | grandchildren keep the output pipes open. */ |
| 1926 | } |
| 1927 | } else if (result < 0 && cp->State != kwsysProcess_State_Error) { |
| 1928 | /* Unexpected error. Report the first time this happens. */ |
| 1929 | strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE); |
| 1930 | cp->State = kwsysProcess_State_Error; |
| 1931 | } |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | /* Re-enable signals. */ |
| 1936 | sigprocmask(SIG_SETMASK, &old_mask, 0); |
| 1937 | } |
| 1938 | |
| 1939 | static int kwsysProcessSetupOutputPipeFile(int* p, char const* name) |
| 1940 | { |
no test coverage detected
searching dependent graphs…