From: Stefan Metzmacher Date: Fri, 20 Mar 2026 09:51:42 +0000 (+0100) Subject: tevent: ignore fd events without flags in tevent_common_have_events() X-Git-Tag: tevent-0.17.2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=30bf2ec711b6aa4fa72ea2e526fcf904085db8bf;p=thirdparty%2Fsamba.git tevent: ignore fd events without flags in tevent_common_have_events() 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 Reviewed-by: Volker Lendecke --- diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 12e1f407bc6..5440e1ac8c2 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -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; } /*