From f057dfc322670467e14c661d625cec0747ce8a31 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 4 May 2017 22:58:25 -0400 Subject: [PATCH] Implement poll mask modification support in poll wrappers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/common/compat/compat-epoll.c | 41 ++++++++++++++++++++++++++++++++ src/common/compat/compat-poll.c | 37 ++++++++++++++++++++++++++++ src/common/compat/poll.h | 16 +++++++++++++ 3 files changed, 94 insertions(+) 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 */ -- 2.34.1