| 1134 | } |
| 1135 | |
| 1136 | static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, |
| 1137 | kwsysProcessWaitData* wd) |
| 1138 | { |
| 1139 | int i; |
| 1140 | kwsysProcessTimeNative timeoutLength; |
| 1141 | |
| 1142 | #if KWSYSPE_USE_SELECT |
| 1143 | int numReady = 0; |
| 1144 | int max = -1; |
| 1145 | kwsysProcessTimeNative* timeout = 0; |
| 1146 | |
| 1147 | /* Check for any open pipes with data reported ready by the last |
| 1148 | call to select. According to "man select_tut" we must deal |
| 1149 | with all descriptors reported by a call to select before |
| 1150 | passing them to another select call. */ |
| 1151 | for (i = 0; i < KWSYSPE_PIPE_COUNT; ++i) { |
| 1152 | if (cp->PipeReadEnds[i] >= 0 && |
| 1153 | FD_ISSET(cp->PipeReadEnds[i], &cp->PipeSet)) { |
| 1154 | kwsysProcess_ssize_t n; |
| 1155 | |
| 1156 | /* We are handling this pipe now. Remove it from the set. */ |
| 1157 | FD_CLR(cp->PipeReadEnds[i], &cp->PipeSet); |
| 1158 | |
| 1159 | /* The pipe is ready to read without blocking. Keep trying to |
| 1160 | read until the operation is not interrupted. */ |
| 1161 | while (((n = read(cp->PipeReadEnds[i], cp->PipeBuffer, |
| 1162 | KWSYSPE_PIPE_BUFFER_SIZE)) < 0) && |
| 1163 | (errno == EINTR)) { |
| 1164 | } |
| 1165 | if (n > 0) { |
| 1166 | /* We have data on this pipe. */ |
| 1167 | if (i == KWSYSPE_PIPE_SIGNAL) { |
| 1168 | /* A child process has terminated. */ |
| 1169 | kwsysProcessDestroy(cp); |
| 1170 | } else if (data && length) { |
| 1171 | /* Report this data. */ |
| 1172 | *data = cp->PipeBuffer; |
| 1173 | *length = (int)(n); |
| 1174 | switch (i) { |
| 1175 | case KWSYSPE_PIPE_STDOUT: |
| 1176 | wd->PipeId = kwsysProcess_Pipe_STDOUT; |
| 1177 | break; |
| 1178 | case KWSYSPE_PIPE_STDERR: |
| 1179 | wd->PipeId = kwsysProcess_Pipe_STDERR; |
| 1180 | break; |
| 1181 | default: |
| 1182 | break; |
| 1183 | } |
| 1184 | return 1; |
| 1185 | } |
| 1186 | } else if (n < 0 && errno == EAGAIN) { |
| 1187 | /* No data are really ready. The select call lied. See the |
| 1188 | "man select" page on Linux for cases when this occurs. */ |
| 1189 | } else { |
| 1190 | /* We are done reading from this pipe. */ |
| 1191 | kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]); |
| 1192 | --cp->PipesLeft; |
| 1193 | } |
no test coverage detected
searching dependent graphs…