return 0;
}
-static int process_io(sd_event *e, sd_event_source *s, uint32_t events) {
+static int process_io(sd_event *e, sd_event_source *s, uint32_t revents) {
assert(e);
assert(s);
assert(s->type == SOURCE_IO);
- s->io.revents = events;
+ /* If the event source was already pending, we just OR in the
+ * new revents, otherwise we reset the value. The ORing is
+ * necessary to handle EPOLLONESHOT events properly where
+ * readability might happen independently of writability, and
+ * we need to keep track of both */
+
+ if (s->pending)
+ s->io.revents |= revents;
+ else
+ s->io.revents = revents;
return source_set_pending(s, true);
}
return -errno;
}
- if (ss != sizeof(x))
+ if (_unlikely_(ss != sizeof(x)))
return -EIO;
if (next)
return -errno;
}
- if (ss != sizeof(si))
+ if (_unlikely_(ss != sizeof(si)))
return -EIO;
read_one = true;
m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max,
timeout == (uint64_t) -1 ? -1 : (int) ((timeout + USEC_PER_MSEC - 1) / USEC_PER_MSEC));
if (m < 0) {
- r = errno == EAGAIN || errno == EINTR ? 0 : -errno;
+ r = errno == EAGAIN || errno == EINTR ? 1 : -errno;
goto finish;
}
p = event_next_pending(e);
if (!p) {
- r = 0;
+ r = 1;
goto finish;
}
_public_ int sd_event_default(sd_event **ret) {
- static __thread sd_event *default_event = NULL;
+ static thread_local sd_event *default_event = NULL;
sd_event *e;
int r;
if (b) {
struct epoll_event ev = {};
- const char *env;
- env = getenv("WATCHDOG_USEC");
- if (!env)
- return false;
-
- r = safe_atou64(env, &e->watchdog_period);
- if (r < 0)
+ r = sd_watchdog_enabled(false, &e->watchdog_period);
+ if (r <= 0)
return r;
- if (e->watchdog_period <= 0)
- return -EIO;
/* Issue first ping immediately */
sd_notify(false, "WATCHDOG=1");