Commit | Line | Data |
---|---|---|
184597e3 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
184597e3 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
184597e3 | 5 | * |
184597e3 JG |
6 | */ |
7 | ||
8 | #include <common/compat/poll.h> | |
9 | ||
10 | #include "utils.h" | |
11 | ||
0060607b MJ |
12 | #if HAVE_EPOLL |
13 | ||
14 | struct create_args { | |
15 | struct lttng_poll_event *events; | |
16 | int size; | |
17 | int flags; | |
18 | }; | |
19 | ||
20 | static int open_epoll(void *data, int *out_fd) | |
21 | { | |
22 | int ret; | |
e032c6fd | 23 | struct create_args *args = (create_args *) data; |
0060607b MJ |
24 | |
25 | ret = lttng_poll_create(args->events, args->size, args->flags); | |
26 | if (ret < 0) { | |
27 | goto end; | |
28 | } | |
29 | ||
30 | *out_fd = args->events->epfd; | |
31 | end: | |
32 | return ret; | |
33 | } | |
34 | ||
35 | static int close_epoll(void *data, int *in_fd) | |
36 | { | |
37 | /* Will close the epfd. */ | |
38 | lttng_poll_clean((struct lttng_poll_event *) data); | |
39 | return 0; | |
40 | } | |
41 | ||
42 | /* | |
43 | * The epoll variant of the poll compat layer creates an unsuspendable fd which | |
44 | * must be tracked. | |
45 | */ | |
46 | int fd_tracker_util_poll_create(struct fd_tracker *tracker, | |
47 | const char *name, | |
48 | struct lttng_poll_event *events, | |
49 | int size, | |
50 | int flags) | |
51 | { | |
52 | int out_fd; | |
53 | struct create_args create_args = { | |
54 | .events = events, | |
55 | .size = size, | |
56 | .flags = flags, | |
57 | }; | |
58 | ||
59 | return fd_tracker_open_unsuspendable_fd( | |
60 | tracker, &out_fd, &name, 1, open_epoll, &create_args); | |
61 | } | |
62 | ||
63 | int fd_tracker_util_poll_clean( | |
64 | struct fd_tracker *tracker, struct lttng_poll_event *events) | |
65 | { | |
66 | return fd_tracker_close_unsuspendable_fd( | |
67 | tracker, &events->epfd, 1, close_epoll, events); | |
68 | } | |
69 | ||
70 | #else /* HAVE_EPOLL */ | |
71 | ||
184597e3 JG |
72 | /* |
73 | * The epoll variant of the poll compat layer creates an unsuspendable fd which | |
74 | * must be tracked. | |
75 | */ | |
5c1f54d1 JG |
76 | int fd_tracker_util_poll_create(struct fd_tracker *tracker, |
77 | const char *name, | |
78 | struct lttng_poll_event *events, | |
79 | int size, | |
80 | int flags) | |
184597e3 JG |
81 | { |
82 | return lttng_poll_create(events, size, flags); | |
83 | } | |
84 | ||
5c1f54d1 JG |
85 | int fd_tracker_util_poll_clean( |
86 | struct fd_tracker *tracker, struct lttng_poll_event *events) | |
184597e3 JG |
87 | { |
88 | lttng_poll_clean(events); | |
89 | return 0; | |
90 | } | |
0060607b MJ |
91 | |
92 | #endif /* !HAVE_EPOLL */ |