From 4e333c516577531471229a7be23ddd213bdf2ff8 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 2 May 2014 14:57:36 -0600 Subject: [PATCH] Fix non-blocking mode. We only want to exit the event loop when poll() or select() returns 0 and there are no active events. This fixes a problem on some systems where the last buffer was not being written when the command exited. --- common/event.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/event.c b/common/event.c index f1fdf14cd..db8023168 100644 --- a/common/event.c +++ b/common/event.c @@ -286,6 +286,11 @@ rescan: TAILQ_INSERT_TAIL(&base->active, ev, active_entries); SET(ev->flags, SUDO_EVQ_ACTIVE); } + if (ISSET(flags, SUDO_EVLOOP_NONBLOCK)) { + /* If nonblocking, return immediately if no active events. */ + if (TAILQ_EMPTY(&base->active)) + goto done; + } break; default: /* I/O events active, sudo_ev_scan_impl() already added them. */ @@ -333,7 +338,7 @@ rescan: SET(base->flags, SUDO_EVBASE_GOT_EXIT); goto done; } - if (flags & (SUDO_EVLOOP_ONCE | SUDO_EVLOOP_NONBLOCK)) + if (ISSET(flags, SUDO_EVLOOP_ONCE)) break; } done: