summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibuv/src/unix/kqueue.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-06-21 18:01:52 (GMT)
committerBrad King <brad.king@kitware.com>2024-06-21 19:01:15 (GMT)
commit7e3519e705b7df884eecd81d097f640fd61f52a4 (patch)
tree7812ddbe4727a068076744e8734540b76a16ea22 /Utilities/cmlibuv/src/unix/kqueue.c
parentcdc901797ac4ce0d1feeec454ecdd29e8ef5d4ff (diff)
downloadCMake-7e3519e705b7df884eecd81d097f640fd61f52a4.zip
CMake-7e3519e705b7df884eecd81d097f640fd61f52a4.tar.gz
CMake-7e3519e705b7df884eecd81d097f640fd61f52a4.tar.bz2
libuv: macos: reap child processes more reliably when using kqueue
Backport libuv commit `42cc412c4a` (darwin,process: feed kevent the signal to reap children, 2023-02-01, `v1.45.0~55`) from libuv PR 3893. Fixes: #25839
Diffstat (limited to 'Utilities/cmlibuv/src/unix/kqueue.c')
-rw-r--r--Utilities/cmlibuv/src/unix/kqueue.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/Utilities/cmlibuv/src/unix/kqueue.c b/Utilities/cmlibuv/src/unix/kqueue.c
index 5dac76a..581c552 100644
--- a/Utilities/cmlibuv/src/unix/kqueue.c
+++ b/Utilities/cmlibuv/src/unix/kqueue.c
@@ -235,6 +235,9 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
ARRAY_SIZE(events),
timeout == -1 ? NULL : &spec);
+ if (nfds == -1)
+ assert(errno == EINTR);
+
if (pset != NULL)
pthread_sigmask(SIG_UNBLOCK, pset, NULL);
@@ -242,36 +245,26 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
* operating system didn't reschedule our process while in the syscall.
*/
- SAVE_ERRNO(uv__update_time(loop));
-
- if (nfds == 0) {
- if (reset_timeout != 0) {
- timeout = user_timeout;
- reset_timeout = 0;
- if (timeout == -1)
- continue;
- if (timeout > 0)
- goto update_timeout;
+ uv__update_time(loop);
+
+ if (nfds == 0 || nfds == -1) {
+ /* If kqueue is empty or interrupted, we might still have children ready
+ * to reap immediately. */
+ if (loop->flags & UV_LOOP_REAP_CHILDREN) {
+ loop->flags &= ~UV_LOOP_REAP_CHILDREN;
+ uv__wait_children(loop);
+ assert((reset_timeout == 0 ? timeout : user_timeout) == 0);
+ return; /* Equivalent to fall-through behavior. */
}
- assert(timeout != -1);
- return;
- }
-
- if (nfds == -1) {
- if (errno != EINTR)
- abort();
-
if (reset_timeout != 0) {
timeout = user_timeout;
reset_timeout = 0;
- }
-
- if (timeout == 0)
+ } else if (nfds == 0) {
+ /* Reached the user timeout value. */
+ assert(timeout != -1);
return;
-
- if (timeout == -1)
- continue;
+ }
/* Interrupted by a signal. Update timeout and poll again. */
goto update_timeout;
@@ -423,13 +416,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
return;
}
+update_timeout:
if (timeout == 0)
return;
if (timeout == -1)
continue;
-update_timeout:
assert(timeout > 0);
diff = loop->time - base;