Implement poll mask modification support in poll wrappers
[lttng-tools.git] / src / common / compat / compat-epoll.c
index 5d6153b64d075b5da4dc9881680be992e6018b6f..dbaf6823364eb5e4444ba536ac0291300a527a0a 100644 (file)
@@ -15,7 +15,6 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <assert.h>
 #include <fcntl.h>
@@ -24,7 +23,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <config.h>
 
 #include <common/error.h>
 #include <common/defaults.h>
@@ -78,8 +76,9 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
        }
 
        if (!poll_max_size) {
-               ERR("poll_max_size not initialized yet");
-               goto error;
+               if (lttng_poll_set_max_size()) {
+                       goto error;
+               }
        }
 
        /* Don't bust the limit here */
@@ -198,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.
  */
@@ -210,7 +250,6 @@ int compat_epoll_wait(struct lttng_poll_event *events, int timeout)
                ERR("Wrong arguments in compat_epoll_wait");
                goto error;
        }
-       assert(events->nb_fd >= 0);
 
        if (events->nb_fd == 0) {
                errno = EINVAL;
This page took 0.02569 seconds and 4 git commands to generate.