]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
event-waitid: When waitid returns 0, info isn't initialised so we can't check it
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 5 Apr 2023 01:16:36 +0000 (19:16 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 5 Apr 2023 01:21:54 +0000 (19:21 -0600)
src/lib/util/event.c

index 5d908a2e52249fc7d7734d3a7c5bfde883a7ed90..42fe96339693e8e236d8457c1fb4069e33fa1501 100644 (file)
@@ -1767,6 +1767,7 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS
         */
        if (unlikely(kevent(el->kq, &evset, 1, NULL, 0, NULL) < 0)) {
                siginfo_t       info;
+               int ret;
 
                /*
                 *      Ensure we don't accidentally pick up the error
@@ -1799,7 +1800,8 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS
                 *      we'd consider to indicate that the process
                 *      had completed.
                 */
-               if (waitid(P_PID, pid, &info, WEXITED | WNOHANG | WNOWAIT) >= 0) {
+               ret = waitid(P_PID, pid, &info, WEXITED | WNOHANG | WNOWAIT);
+               if (ret > 0) {
                        static fr_table_num_sorted_t const si_codes[] = {
                                { L("exited"),  CLD_EXITED },
                                { L("killed"),  CLD_KILLED },
@@ -1838,6 +1840,7 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS
                                 *      because they were not yet yielded,
                                 *      leading to hangs.
                                 */
+                       early_exit:
                                if (fr_event_user_insert(ev, el, &ev->early_exit.ev, true, _fr_event_pid_early_exit, ev) < 0) {
                                        fr_strerror_printf_push("Failed adding wait for PID %ld, and failed adding "
                                                                "backup user event", (long) pid);
@@ -1854,6 +1857,18 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS
 
                                goto error;
                        }
+               /*
+                *      Failed adding waiter for process, but process has not completed...
+                *
+                *      This weird, but seems to happen on macOS ocassionally.
+                *
+                *      Add an event to run early exit...
+                *
+                *      Man pages for waitid say if it returns 0 the info struct can be in
+                *      a nondeterministic state, so there's nothing more to do.
+                */
+               } else if (ret == 0) {
+                       goto early_exit;
                } else {
                        /*
                        *       Print this error here, so that the caller gets