From: Jérémie Galarneau Date: Fri, 5 May 2017 02:58:25 +0000 (-0400) Subject: Implement poll mask modification support in poll wrappers X-Git-Tag: v2.10.0-rc1~46 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=f057dfc322670467e14c661d625cec0747ce8a31;ds=sidebyside Implement poll mask modification support in poll wrappers Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/compat/compat-epoll.c b/src/common/compat/compat-epoll.c index 9c2688d33..dbaf68233 100644 --- a/src/common/compat/compat-epoll.c +++ b/src/common/compat/compat-epoll.c @@ -197,6 +197,47 @@ error: return -1; } +/* + * Set an fd's events. + */ +int compat_epoll_mod(struct lttng_poll_event *events, int fd, uint32_t req_events) +{ + int ret; + struct epoll_event ev; + + if (events == NULL || fd < 0 || events->nb_fd == 0) { + goto error; + } + + /* + * Zero struct epoll_event to ensure all representations of its + * union are zeroed. + */ + memset(&ev, 0, sizeof(ev)); + ev.events = req_events; + ev.data.fd = fd; + + ret = epoll_ctl(events->epfd, EPOLL_CTL_MOD, fd, &ev); + if (ret < 0) { + switch (errno) { + case ENOENT: + case EPERM: + /* Print PERROR and goto end not failing. Show must go on. */ + PERROR("epoll_ctl MOD"); + goto end; + default: + PERROR("epoll_ctl MOD fatal"); + goto error; + } + } + +end: + return 0; + +error: + return -1; +} + /* * Wait on epoll set. This is a blocking call of timeout value. */ diff --git a/src/common/compat/compat-poll.c b/src/common/compat/compat-poll.c index 7d4d0e133..2b459e42f 100644 --- a/src/common/compat/compat-poll.c +++ b/src/common/compat/compat-poll.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -196,6 +197,42 @@ error: return -1; } +/* + * Modify an fd's events.. + */ +int compat_poll_mod(struct lttng_poll_event *events, int fd, + uint32_t req_events) +{ + int ret, i; + bool fd_found = false; + struct compat_poll_event_array *current; + + if (events == NULL || events->current.events == NULL || fd < 0) { + ERR("Bad compat poll mod arguments"); + goto error; + } + + current = &events->current; + + for (i = 0; i < current->nb_fd; i++) { + if (current->events[i].fd == fd) { + fd_found = true; + current->events[i].events = req_events; + events->need_update = 1; + break; + } + } + + if (!fd_found) { + goto error; + } + + return 0; + +error: + return -1; +} + /* * Remove a fd from the pollfd structure. */ diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index 77c46a1d0..d4bd87f58 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -171,6 +171,14 @@ extern int compat_epoll_del(struct lttng_poll_event *events, int fd); #define lttng_poll_del(events, fd) \ compat_epoll_del(events, fd) +/* + * Modify an fd's events in the epoll set. + */ +extern int compat_epoll_mod(struct lttng_poll_event *events, + int fd, uint32_t req_events); +#define lttng_poll_mod(events, fd, req_events) \ + compat_epoll_add(events, fd, req_events) + /* * Set up the poll set limits variable poll_max_size */ @@ -347,6 +355,14 @@ extern int compat_poll_del(struct lttng_poll_event *events, int fd); #define lttng_poll_del(events, fd) \ compat_poll_del(events, fd) +/* + * Modify an fd's events in the epoll set. + */ +extern int compat_poll_mod(struct lttng_poll_event *events, + int fd, uint32_t req_events); +#define lttng_poll_mod(events, fd, req_events) \ + compat_poll_add(events, fd, req_events) + /* * Set up the poll set limits variable poll_max_size */