]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Fix kqueue io_loop_get_wait_time usage
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 24 Oct 2016 07:13:42 +0000 (10:13 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Oct 2016 11:26:18 +0000 (14:26 +0300)
The code needs to take into consideration,
when there is no IO to be waited, but possibly
there is io_set_pending used, or just timeouts.

src/lib/ioloop-kqueue.c

index 881ce87eb2c2cf818d4b78b1f9559d885ab841b0..d4db5d48b3139eac22d4818122ab44d755be1761 100644 (file)
@@ -117,18 +117,26 @@ void io_loop_handler_run_internal(struct ioloop *ioloop)
        struct timespec ts;
        struct io_file *io;
        unsigned int events_count;
-       int ret, i;
+       int ret, i, msecs;
 
        /* get the time left for next timeout task */
-       io_loop_get_wait_time(ioloop, &tv);
+       msecs = io_loop_get_wait_time(ioloop, &tv);
        ts.tv_sec = tv.tv_sec;
        ts.tv_nsec = tv.tv_usec * 1000;
 
        /* wait for events */
        events = array_get_modifiable(&ctx->events, &events_count);
-       ret = kevent (ctx->kq, NULL, 0, events, events_count, &ts);
-       if (ret < 0 && errno != EINTR)
-               i_panic("kevent(): %m");
+
+       if (events_count > 0) {
+               ret = kevent (ctx->kq, NULL, 0, events, events_count, &ts);
+               if (ret < 0 && errno != EINTR)
+                       i_panic("kevent() failed: %m");
+       } else {
+               if (msecs < 0)
+                       i_panic("BUG: No IOs or timeouts set. Not waiting for infinity.");
+               usleep(msecs * 1000);
+               ret = 0;
+       }
 
        /* reference all IOs */
        for (i = 0; i < ret; i++) {