X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-bus%2Fsd-event.c;h=a1baac52aaaa324a5b372d05583d30293ad18502;hb=ff0031069ffeb0ccda209297b6b39c4786ac770b;hp=94813950b8727179c3d4cac25e40ad6ff66af50e;hpb=15b38f936e257d14854f38bf39357b0b2a5c1e66;p=elogind.git diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c index 94813950b..a1baac52a 100644 --- a/src/libsystemd-bus/sd-event.c +++ b/src/libsystemd-bus/sd-event.c @@ -1569,12 +1569,21 @@ static int event_arm_timer( 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); } @@ -1596,7 +1605,7 @@ static int flush_timer(sd_event *e, int fd, uint32_t events, usec_t *next) { return -errno; } - if (ss != sizeof(x)) + if (_unlikely_(ss != sizeof(x))) return -EIO; if (next) @@ -1724,7 +1733,7 @@ static int process_signal(sd_event *e, uint32_t events) { return -errno; } - if (ss != sizeof(si)) + if (_unlikely_(ss != sizeof(si))) return -EIO; read_one = true; @@ -1977,7 +1986,7 @@ _public_ int sd_event_run(sd_event *e, uint64_t timeout) { 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; } @@ -2107,7 +2116,7 @@ _public_ int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec) { _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;