| 1 | /* |
| 2 | * Copyright (C) 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License, version 2 only, as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | |
| 18 | #include <common/compat/poll.h> |
| 19 | |
| 20 | #include "utils.h" |
| 21 | |
| 22 | struct create_args { |
| 23 | struct lttng_poll_event *events; |
| 24 | int size; |
| 25 | int flags; |
| 26 | }; |
| 27 | |
| 28 | static |
| 29 | int open_epoll(void *data, int *out_fd) |
| 30 | { |
| 31 | int ret; |
| 32 | struct create_args *args = data; |
| 33 | |
| 34 | ret = lttng_poll_create(args->events, args->size, args->flags); |
| 35 | if (ret < 0) { |
| 36 | goto end; |
| 37 | } |
| 38 | |
| 39 | *out_fd = args->events->epfd; |
| 40 | end: |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static |
| 45 | int close_epoll(void *data, int *in_fd) |
| 46 | { |
| 47 | /* Will close the epfd. */ |
| 48 | lttng_poll_clean((struct lttng_poll_event *) data); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * The epoll variant of the poll compat layer creates an unsuspendable fd which |
| 54 | * must be tracked. |
| 55 | */ |
| 56 | int fd_tracker_util_poll_create(struct fd_tracker *tracker, const char *name, |
| 57 | struct lttng_poll_event *events, int size, int flags) |
| 58 | { |
| 59 | int out_fd; |
| 60 | struct create_args create_args = { |
| 61 | .events = events, |
| 62 | .size = size, |
| 63 | .flags = flags, |
| 64 | }; |
| 65 | |
| 66 | return fd_tracker_open_unsuspendable_fd(tracker, &out_fd, &name, 1, |
| 67 | open_epoll, &create_args); |
| 68 | } |
| 69 | |
| 70 | int fd_tracker_util_poll_clean(struct fd_tracker *tracker, |
| 71 | struct lttng_poll_event *events) |
| 72 | { |
| 73 | return fd_tracker_close_unsuspendable_fd(tracker, &events->epfd, 1, |
| 74 | close_epoll, events); |
| 75 | } |