From: Arran Cudbard-Bell Date: Fri, 9 Dec 2022 14:30:07 +0000 (-0600) Subject: Fix exec issues on macOS X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=888649bd3224478450f3db699b4c4c2e290f1a92;p=thirdparty%2Ffreeradius-server.git Fix exec issues on macOS 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. --- diff --git a/src/lib/util/event.c b/src/lib/util/event.c index b3df1782064..77256b1154d 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -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 },