epoll/poll compat: expose interruptible API
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 16 May 2019 19:08:50 +0000 (15:08 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 5 Sep 2019 17:56:23 +0000 (13:56 -0400)
Some use of the epoll/poll wrapper require interruption
by signals to make the poll call return -1, errno EINTR.
Expose a new lttng_poll_wait_interruptible API for this
purpose.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/compat/compat-epoll.c
src/common/compat/compat-poll.c
src/common/compat/poll.h

index 6a781c7ae04034f321f974c244df6e43e01e58b3..794041726ad51226e331c511526c4ff95de128d5 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <stdbool.h>
 
 #include <common/error.h>
 #include <common/defaults.h>
@@ -241,7 +242,8 @@ error:
 /*
  * Wait on epoll set. This is a blocking call of timeout value.
  */
-int compat_epoll_wait(struct lttng_poll_event *events, int timeout)
+int compat_epoll_wait(struct lttng_poll_event *events, int timeout,
+               bool interruptible)
 {
        int ret;
        uint32_t new_size;
@@ -273,10 +275,11 @@ int compat_epoll_wait(struct lttng_poll_event *events, int timeout)
 
        do {
                ret = epoll_wait(events->epfd, events->events, events->nb_fd, timeout);
-       } while (ret == -1 && errno == EINTR);
+       } while (!interruptible && ret == -1 && errno == EINTR);
        if (ret < 0) {
-               /* At this point, every error is fatal */
-               PERROR("epoll_wait");
+               if (errno != EINTR) {
+                       PERROR("epoll_wait");
+               }
                goto error;
        }
 
index 254ce271e71c2f1b9249942e229b5a4b5b7fc82f..4ea23c17318e1439f36a94b134194d13b070e4de 100644 (file)
@@ -291,7 +291,8 @@ error:
 /*
  * Wait on poll() with timeout. Blocking call.
  */
-int compat_poll_wait(struct lttng_poll_event *events, int timeout)
+int compat_poll_wait(struct lttng_poll_event *events, int timeout,
+               bool interruptible)
 {
        int ret, active_fd_count;
        int idle_pfd_index = 0;
@@ -320,10 +321,11 @@ int compat_poll_wait(struct lttng_poll_event *events, int timeout)
 
        do {
                ret = poll(events->wait.events, events->wait.nb_fd, timeout);
-       } while (ret == -1 && errno == EINTR);
+       } while (!interruptible && ret == -1 && errno == EINTR);
        if (ret < 0) {
-               /* At this point, every error is fatal */
-               PERROR("poll wait");
+               if (errno != EINTR) {
+                       PERROR("poll wait");
+               }
                goto error;
        }
 
index 4b2fc5036843c5863047125a8c1d79085405b34f..0b3cb324341a225ab6ab33c588a170e6d9cc23c4 100644 (file)
@@ -150,9 +150,12 @@ static inline int compat_glibc_epoll_create(int size, int flags)
  * Wait on epoll set with the number of fd registered to the lttng_poll_event
  * data structure (events).
  */
-extern int compat_epoll_wait(struct lttng_poll_event *events, int timeout);
+extern int compat_epoll_wait(struct lttng_poll_event *events, int timeout,
+               bool interruptible);
 #define lttng_poll_wait(events, timeout) \
-       compat_epoll_wait(events, timeout)
+       compat_epoll_wait(events, timeout, false)
+#define lttng_poll_wait_interruptible(events, timeout) \
+       compat_epoll_wait(events, timeout, true)
 
 /*
  * Add a fd to the epoll set and resize the epoll_event structure if needed.
@@ -334,9 +337,12 @@ extern int compat_poll_create(struct lttng_poll_event *events, int size);
  * Wait on poll(2) event with nb_fd registered to the lttng_poll_event data
  * structure.
  */
-extern int compat_poll_wait(struct lttng_poll_event *events, int timeout);
+extern int compat_poll_wait(struct lttng_poll_event *events, int timeout,
+               bool interruptible);
 #define lttng_poll_wait(events, timeout) \
-       compat_poll_wait(events, timeout)
+       compat_poll_wait(events, timeout, false)
+#define lttng_poll_wait_interruptible(events, timeout) \
+       compat_poll_wait(events, timeout, true)
 
 /*
  * Add the fd to the pollfd structure. Resize if needed.
This page took 0.027796 seconds and 4 git commands to generate.