* @brief Wait for and reap a child process status change * * @param[in] cur_thr Current thread context * @param[in] self_lwp Lightweight process (parent) waiting for the child * @param[in] pid Process ID to wait for (-1 for any child, -pgid for process group) * @param[in] options Wait options (WNOHANG, WUNTRACED, etc.) * @param[out] ustatus Pointer to store child exit status * @param[in,out
| 1525 | * - Calls _stats_and_reap_child if a matching child is found |
| 1526 | */ |
| 1527 | static sysret_t _wait_and_reap(rt_thread_t cur_thr, rt_lwp_t self_lwp, const pid_t pid, |
| 1528 | int options, int *ustatus, struct rusage *uru) |
| 1529 | { |
| 1530 | sysret_t rc; |
| 1531 | struct waitpid_handle handle; |
| 1532 | rt_lwp_t waker; |
| 1533 | |
| 1534 | /* wait for SIGCHLD or other async events */ |
| 1535 | handle.options = options; |
| 1536 | handle.waker_lwp = 0; |
| 1537 | rc = _wait_for_event(cur_thr, self_lwp, &handle, pid); |
| 1538 | |
| 1539 | waker = handle.waker_lwp; |
| 1540 | if (waker != RT_NULL) |
| 1541 | { |
| 1542 | rc = waker->pid; |
| 1543 | |
| 1544 | /* check out if any process exited */ |
| 1545 | LOG_D("%s: woken up by lwp=%d", __func__, waker->pid); |
| 1546 | _stats_and_reap_child(waker, cur_thr, self_lwp, ustatus, options, uru); |
| 1547 | } |
| 1548 | /** |
| 1549 | * else if (rc != RT_EOK) |
| 1550 | * unable to do a suspend, or wakeup unexpectedly |
| 1551 | * -> then returned a failure |
| 1552 | */ |
| 1553 | |
| 1554 | return rc; |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * @brief Wait for process termination and return status |
no test coverage detected