]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
More docs for EVFILT_PROC in event.c
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 28 Aug 2021 16:44:22 +0000 (11:44 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 28 Aug 2021 16:44:22 +0000 (11:44 -0500)
src/lib/util/event.c

index 5dfc3ae54e0546db45195c71f4a5d27fa898d47f..280650367de49f1d34ce71df8a4de5c2842ab05d 100644 (file)
@@ -1571,9 +1571,9 @@ int fr_event_timer_delete(fr_event_timer_t const **ev_p)
 static int _event_pid_free(fr_event_pid_t *ev)
 {
        struct kevent evset;
-       if (ev->parent) *ev->parent = NULL;
 
-       if (ev->pid == 0) return 0; /* already deleted from kevent */
+       if (ev->parent) *ev->parent = NULL;
+       if (ev->pid < 0) return 0; /* already deleted from kevent */
 
        EV_SET(&evset, ev->pid, EVFILT_PROC, EV_DELETE, NOTE_EXIT, 0, ev);
 
@@ -1618,6 +1618,10 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS
        ev->line = line;
 #endif
 
+       /*
+        *      macOS only, on FreeBSD NOTE_EXIT always provides
+        *      the status anyway.
+        */
 #ifndef NOTE_EXITSTATUS
 #define NOTE_EXITSTATUS (0)
 #endif
@@ -2106,7 +2110,21 @@ void fr_event_service(fr_event_list_t *el)
                        uctx = pev->uctx;
 
                        pev->pid = 0; /* so we won't hit kevent again when it's freed */
-                       talloc_free(pev); /* delete the event before calling it */
+
+                       /*
+                        *      Delete the event before calling it.
+                        *
+                        *      This also sets the parent pointer
+                        *      to NULL, so the thing that started
+                        *      monitoring the process knows the
+                        *      handle is no longer valid.
+                        *
+                        *      EVFILT_PROC NOTE_EXIT events are always
+                        *      oneshot no matter what flags we pass,
+                        *      so we're just reflecting the state of
+                        *      the kqueue.
+                        */
+                       talloc_free(pev);
 
                        if (callback) callback(el, pid, (int) el->events[i].data, uctx);
                }