]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix exec issues on macOS
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 9 Dec 2022 14:30:07 +0000 (08:30 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 9 Dec 2022 14:30:07 +0000 (08:30 -0600)
This appears to be a behavioural difference between macOS and Linux, where waitid will non-deterministically return 0 or 1 even if the process has exited consistently.

src/lib/util/event.c

index b3df178206443dc15deafc0a7c02c5b5508a37d0..77256b1154d530134aee268667797e02543e218b 100644 (file)
@@ -1668,6 +1668,12 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS
        if (unlikely(kevent(el->kq, &evset, 1, NULL, 0, NULL) < 0)) {
                siginfo_t       info;
 
+               /*
+                *      Ensure we don't accidentally pick up the error
+                *      from kevent.
+                */
+               fr_strerror_clear();
+
                talloc_free(ev);
 
                /*
@@ -1684,8 +1690,16 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS
                 *      If we get a 0, then that's extremely strange
                 *      as adding the kevent failed for a reason
                 *      other than the process already having exited.
+                *
+                *      On Linux waitid will always return 1 to
+                *      indicate the process exited.
+                *
+                *      On macOS we seem to get a mix of 1 or 0,
+                *      even if the si_code is one of the values
+                *      we'd consider to indicate that the process
+                *      had completed.
                 */
-               if (waitid(P_PID, pid, &info, WEXITED | WNOHANG | WNOWAIT) > 0) {
+               if (waitid(P_PID, pid, &info, WEXITED | WNOHANG | WNOWAIT) >= 0) {
                        static fr_table_num_sorted_t const si_codes[] = {
                                { L("exited"),  CLD_EXITED },
                                { L("killed"),  CLD_KILLED },