| 1338 | } |
| 1339 | |
| 1340 | int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout) |
| 1341 | { |
| 1342 | int prPipe = 0; |
| 1343 | |
| 1344 | /* Make sure we are executing a process. */ |
| 1345 | if (!cp || cp->State != kwsysProcess_State_Executing) { |
| 1346 | return 1; |
| 1347 | } |
| 1348 | |
| 1349 | /* Wait for all the pipes to close. Ignore all data. */ |
| 1350 | while ((prPipe = kwsysProcess_WaitForData(cp, 0, 0, userTimeout)) > 0) { |
| 1351 | if (prPipe == kwsysProcess_Pipe_Timeout) { |
| 1352 | return 0; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | /* Check if there was an error in one of the waitpid calls. */ |
| 1357 | if (cp->State == kwsysProcess_State_Error) { |
| 1358 | /* The error message is already in its buffer. Tell |
| 1359 | kwsysProcessCleanup to not create it. */ |
| 1360 | kwsysProcessCleanup(cp, 0); |
| 1361 | return 1; |
| 1362 | } |
| 1363 | |
| 1364 | /* Check whether the child reported an error invoking the process. */ |
| 1365 | if (cp->SelectError) { |
| 1366 | /* The error message is already in its buffer. Tell |
| 1367 | kwsysProcessCleanup to not create it. */ |
| 1368 | kwsysProcessCleanup(cp, 0); |
| 1369 | cp->State = kwsysProcess_State_Error; |
| 1370 | return 1; |
| 1371 | } |
| 1372 | /* Determine the outcome. */ |
| 1373 | if (cp->Killed) { |
| 1374 | /* We killed the child. */ |
| 1375 | cp->State = kwsysProcess_State_Killed; |
| 1376 | } else if (cp->TimeoutExpired) { |
| 1377 | /* The timeout expired. */ |
| 1378 | cp->State = kwsysProcess_State_Expired; |
| 1379 | } else { |
| 1380 | /* The children exited. Report the outcome of the child processes. */ |
| 1381 | for (prPipe = 0; prPipe < cp->NumberOfCommands; ++prPipe) { |
| 1382 | cp->ProcessResults[prPipe].ExitCode = cp->CommandExitCodes[prPipe]; |
| 1383 | if (WIFEXITED(cp->ProcessResults[prPipe].ExitCode)) { |
| 1384 | /* The child exited normally. */ |
| 1385 | cp->ProcessResults[prPipe].State = kwsysProcess_StateByIndex_Exited; |
| 1386 | cp->ProcessResults[prPipe].ExitException = kwsysProcess_Exception_None; |
| 1387 | cp->ProcessResults[prPipe].ExitValue = |
| 1388 | // NOLINTNEXTLINE(google-readability-casting) |
| 1389 | (int)WEXITSTATUS(cp->ProcessResults[prPipe].ExitCode); |
| 1390 | } else if (WIFSIGNALED(cp->ProcessResults[prPipe].ExitCode)) { |
| 1391 | /* The child received an unhandled signal. */ |
| 1392 | cp->ProcessResults[prPipe].State = kwsysProcess_State_Exception; |
| 1393 | kwsysProcessSetExitExceptionByIndex( |
| 1394 | // NOLINTNEXTLINE(google-readability-casting) |
| 1395 | cp, (int)WTERMSIG(cp->ProcessResults[prPipe].ExitCode), prPipe); |
| 1396 | } else { |
| 1397 | /* Error getting the child return code. */ |
searching dependent graphs…