From 5ed8cef02f16010ac656770fbc5ddcfb0b8772fe Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Fri, 26 Oct 2007 13:20:56 +0000 Subject: [PATCH] Fix lwevent_set_events(). This function should only update the lwevent structure's event mask if the call to epoll_ctl() succeeds. This does, however, mean that the event mask cannot be changed if the lwevent instance is deactivated. --- src/liblwevent/350_fdparams.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/liblwevent/350_fdparams.c b/src/liblwevent/350_fdparams.c index 1e3fca1..5baa73c 100644 --- a/src/liblwevent/350_fdparams.c +++ b/src/liblwevent/350_fdparams.c @@ -44,19 +44,29 @@ int lwevent_get_autodestroy(const struct lwevent* ev) /* lwevent_set_events() * Calls epoll_ctl(EPOLL_CTL_MOD) to change the events associated with the object `ev'. Does not - * perform the call if the new events match the current events. If `old_events' is not null, stores - * the existing events before changing. Returns -1 if epoll_ctl fails. + * perform the call if the new events match the current events. Returns -1 if epoll_ctl fails. */ int lwevent_set_events(struct lwevent* ev, int events) { - if(events == ev->events) return 0; /* don't call epoll_ctl() if no change */ - return _lwevent_activate(EPOLL_CTL_MOD, ev); + struct epoll_event ee; + + /* don't call epoll_ctl() if no change */ + if(events == ev->events) return 0; + + /* try the modification */ + ee.events = events; + ee.data.ptr = ev; + if(TEMP_FAILURE_RETRY( epoll_ctl(lwevent_epoll_fd, EPOLL_CTL_MOD, ev->fd, &ee) )) return -1; + + /* update structure only if it succeeded */ + ev->events = events; + return 0; } - + /* lwevent_set_*() - * Changes attributes associated with `ev', possibly storing the old value. + * Changes attributes associated with `ev'. */ void lwevent_set_callback(struct lwevent* ev, lwevent_callback callback) {