Clarify limitations of the --syscall flag with enable-event command
[lttng-tools.git] / src / common / compat / poll.h
index 2cfad9a25fa1c7e0339ff8e810796c58f1b5b552..b019b42c09ff12f81dfc92a12c6872e318f678ea 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef _LTT_POLL_H
 #define _LTT_POLL_H
 
+#include <assert.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -42,9 +43,7 @@ extern unsigned int poll_max_size;
  */
 static inline void __lttng_poll_free(void *events)
 {
-       if (events) {
-               free(events);
-       }
+       free(events);
 }
 
 /*
@@ -84,6 +83,19 @@ struct compat_epoll_event {
 };
 #define lttng_poll_event compat_epoll_event
 
+static inline int __lttng_epoll_get_prev_fd(struct lttng_poll_event *events,
+               int index, uint32_t nb_fd)
+{
+       assert(events);
+       assert(index != nb_fd);
+
+       if (index == 0 || nb_fd == 0) {
+               return -1;
+       } else {
+               return events->events[index - 1].data.fd;
+       }
+}
+
 /*
  * For the following calls, consider 'e' to be a lttng_poll_event pointer and i
  * being the index of the events array.
@@ -92,6 +104,8 @@ struct compat_epoll_event {
 #define LTTNG_POLL_GETEV(e, i) LTTNG_REF(e)->events[i].events
 #define LTTNG_POLL_GETNB(e) LTTNG_REF(e)->nb_fd
 #define LTTNG_POLL_GETSZ(e) LTTNG_REF(e)->events_size
+#define LTTNG_POLL_GET_PREV_FD(e, i, nb_fd) \
+       __lttng_epoll_get_prev_fd(LTTNG_REF(e), i, nb_fd)
 
 /*
  * Create the epoll set. No memory allocation is done here.
@@ -144,6 +158,17 @@ static inline void lttng_poll_reset(struct lttng_poll_event *events)
        }
 }
 
+/*
+ * Initialize an already allocated poll event data structure. For epoll(), the
+ * epfd is set to -1 to indicate that it's not usable.
+ */
+static inline void lttng_poll_init(struct lttng_poll_event *events)
+{
+       memset(events, 0, sizeof(struct lttng_poll_event));
+       /* Set fd to -1 so if clean before created, we don't close 0. */
+       events->epfd = -1;
+}
+
 /*
  * Clean the events structure of a lttng_poll_event. It's the caller
  * responsability to free the lttng_poll_event memory.
@@ -152,13 +177,18 @@ static inline void lttng_poll_clean(struct lttng_poll_event *events)
 {
        int ret;
 
-       if (events) {
+       if (!events) {
+               return;
+       }
+
+       if (events->epfd >= 0) {
                ret = close(events->epfd);
                if (ret) {
                        perror("close");
                }
-               __lttng_poll_free((void *) events->events);
        }
+
+       __lttng_poll_free((void *) events->events);
 }
 
 #else  /* HAVE_EPOLL */
@@ -229,6 +259,19 @@ struct compat_poll_event {
 };
 #define lttng_poll_event compat_poll_event
 
+static inline int __lttng_poll_get_prev_fd(struct lttng_poll_event *events,
+               int index, uint32_t nb_fd)
+{
+       assert(events);
+       assert(index != nb_fd);
+
+       if (index == 0 || nb_fd == 0) {
+               return -1;
+       } else {
+               return events->current.events[index - 1].fd;
+       }
+}
+
 /*
  * For the following calls, consider 'e' to be a lttng_poll_event pointer and i
  * being the index of the events array.
@@ -237,6 +280,8 @@ struct compat_poll_event {
 #define LTTNG_POLL_GETEV(e, i) LTTNG_REF(e)->wait.events[i].revents
 #define LTTNG_POLL_GETNB(e) LTTNG_REF(e)->wait.nb_fd
 #define LTTNG_POLL_GETSZ(e) LTTNG_REF(e)->wait.events_size
+#define LTTNG_POLL_GET_PREV_FD(e, i, nb_fd) \
+       __lttng_poll_get_prev_fd(LTTNG_REF(e), i, nb_fd)
 
 /*
  * Create a pollfd structure of size 'size'.
@@ -283,6 +328,14 @@ extern void compat_poll_set_max_size(void);
 static inline void lttng_poll_reset(struct lttng_poll_event *events)
 {}
 
+/*
+ * Initialize an already allocated poll event data structure.
+ */
+static inline void lttng_poll_init(struct lttng_poll_event *events)
+{
+       memset(events, 0, sizeof(struct lttng_poll_event));
+}
+
 /*
  * Clean the events structure of a lttng_poll_event. It's the caller
  * responsability to free the lttng_poll_event memory.
This page took 0.02401 seconds and 4 git commands to generate.