Fix: libcompat is now part of libcommon
[lttng-tools.git] / src / common / compat / compat-epoll.c
index 58f50cc94dd83e33448ca31ebdb2fd2594fee88a..cf92c63b405044ad767cc579c04297fb50362f5a 100644 (file)
@@ -67,6 +67,7 @@ error:
 /*
  * Create epoll set and allocate returned events structure.
  */
+LTTNG_HIDDEN
 int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
 {
        int ret;
@@ -76,8 +77,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 */
@@ -118,6 +120,7 @@ error:
 /*
  * Add a fd to the epoll set with requesting events.
  */
+LTTNG_HIDDEN
 int compat_epoll_add(struct lttng_poll_event *events, int fd, uint32_t req_events)
 {
        int ret;
@@ -165,6 +168,7 @@ error:
 /*
  * Remove a fd from the epoll set.
  */
+LTTNG_HIDDEN
 int compat_epoll_del(struct lttng_poll_event *events, int fd)
 {
        int ret;
@@ -196,9 +200,52 @@ error:
        return -1;
 }
 
+/*
+ * Set an fd's events.
+ */
+LTTNG_HIDDEN
+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.
  */
+LTTNG_HIDDEN
 int compat_epoll_wait(struct lttng_poll_event *events, int timeout)
 {
        int ret;
@@ -208,7 +255,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;
@@ -252,6 +298,7 @@ error:
 /*
  * Setup poll set maximum size.
  */
+LTTNG_HIDDEN
 int compat_epoll_set_max_size(void)
 {
        int ret, fd, retval = 0;
@@ -260,7 +307,15 @@ int compat_epoll_set_max_size(void)
 
        fd = open(COMPAT_EPOLL_PROC_PATH, O_RDONLY);
        if (fd < 0) {
-               retval = -1;
+               /*
+                * Failing on opening [1] is not an error per see. [1] was
+                * introduced in Linux 2.6.28 but epoll is available since
+                * 2.5.44. Hence, goto end and set a default value without
+                * setting an error return value.
+                *
+                * [1] /proc/sys/fs/epoll/max_user_watches
+                */
+               retval = 0;
                goto end;
        }
 
This page took 0.031725 seconds and 5 git commands to generate.