| 1440 | } |
| 1441 | |
| 1442 | void kwsysProcess_Kill(kwsysProcess* cp) |
| 1443 | { |
| 1444 | int i; |
| 1445 | |
| 1446 | /* Make sure we are executing a process. */ |
| 1447 | if (!cp || cp->State != kwsysProcess_State_Executing) { |
| 1448 | return; |
| 1449 | } |
| 1450 | |
| 1451 | /* First close the child exit report pipe write end to avoid causing a |
| 1452 | SIGPIPE when the child terminates and our signal handler tries to |
| 1453 | report it after we have already closed the read end. */ |
| 1454 | kwsysProcessCleanupDescriptor(&cp->SignalPipe); |
| 1455 | |
| 1456 | #if !defined(__APPLE__) |
| 1457 | /* Close all the pipe read ends. Do this before killing the |
| 1458 | children because Cygwin has problems killing processes that are |
| 1459 | blocking to wait for writing to their output pipes. */ |
| 1460 | kwsysProcessClosePipes(cp); |
| 1461 | #endif |
| 1462 | |
| 1463 | /* Kill the children. */ |
| 1464 | cp->Killed = 1; |
| 1465 | for (i = 0; i < cp->NumberOfCommands; ++i) { |
| 1466 | int status; |
| 1467 | if (cp->ForkPIDs[i]) { |
| 1468 | /* Kill the child. */ |
| 1469 | kwsysProcessKill(cp->ForkPIDs[i]); |
| 1470 | |
| 1471 | /* Reap the child. Keep trying until the call is not |
| 1472 | interrupted. */ |
| 1473 | while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR)) { |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | #if defined(__APPLE__) |
| 1479 | /* Close all the pipe read ends. Do this after killing the |
| 1480 | children because OS X has problems closing pipe read ends whose |
| 1481 | pipes are full and still have an open write end. */ |
| 1482 | kwsysProcessClosePipes(cp); |
| 1483 | #endif |
| 1484 | |
| 1485 | cp->CommandsLeft = 0; |
| 1486 | } |
| 1487 | |
| 1488 | /* Call the free() function with a pointer to volatile without causing |
| 1489 | compiler warnings. */ |
searching dependent graphs…