]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tevent: ignore fd events without flags in tevent_common_have_events()
authorStefan Metzmacher <metze@samba.org>
Fri, 20 Mar 2026 09:51:42 +0000 (10:51 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 30 Jul 2026 18:49:38 +0000 (18:49 +0000)
Allow callers to use tevent_add_fd() with flags=0 in order
to allocate the memory, but without waiting for any event.

This should not cause tevent_loop_wait() to loop forever
if such an fd event is the only event.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/tevent/tevent.c

index 12e1f407bc64b265cdb1ecc4366abe0e25b030f4..5440e1ac8c2416df6302448420dc917daf6099ef 100644 (file)
@@ -955,24 +955,35 @@ done:
 
 bool tevent_common_have_events(struct tevent_context *ev)
 {
-       if (ev->fd_events != NULL) {
-               if (ev->fd_events != ev->wakeup_fde) {
-                       return true;
+       struct tevent_fd *fde = NULL;
+
+       if (ev->timer_events != NULL ||
+           ev->immediate_events != NULL ||
+           ev->signal_events != NULL)
+       {
+               return true;
+       }
+
+       for (fde = ev->fd_events; fde != NULL; fde = fde->next) {
+               if (fde == ev->wakeup_fde) {
+                       /*
+                        * Just ignore the wakeup pipe event,
+                        * it should not let us loop forever.
+                        */
+                       continue;
                }
-               if (ev->fd_events->next != NULL) {
-                       return true;
+               if (fde->flags == 0) {
+                       /*
+                        * Disabled fd event should not
+                        * let us loop forever.
+                        */
+                       continue;
                }
 
-               /*
-                * At this point we just have the wakeup pipe event as
-                * the only fd_event. That one does not count as a
-                * regular event, so look at the other event types.
-                */
+               return true;
        }
 
-       return ((ev->timer_events != NULL) ||
-               (ev->immediate_events != NULL) ||
-               (ev->signal_events != NULL));
+       return false;
 }
 
 /*