event-rule: introduce event-rule kprobe
[lttng-tools.git] / src / common / fd-tracker / utils-epoll.c
1 /*
2 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #include <common/compat/poll.h>
9
10 #include "utils.h"
11
12 struct create_args {
13 struct lttng_poll_event *events;
14 int size;
15 int flags;
16 };
17
18 static int open_epoll(void *data, int *out_fd)
19 {
20 int ret;
21 struct create_args *args = data;
22
23 ret = lttng_poll_create(args->events, args->size, args->flags);
24 if (ret < 0) {
25 goto end;
26 }
27
28 *out_fd = args->events->epfd;
29 end:
30 return ret;
31 }
32
33 static int close_epoll(void *data, int *in_fd)
34 {
35 /* Will close the epfd. */
36 lttng_poll_clean((struct lttng_poll_event *) data);
37 return 0;
38 }
39
40 /*
41 * The epoll variant of the poll compat layer creates an unsuspendable fd which
42 * must be tracked.
43 */
44 int fd_tracker_util_poll_create(struct fd_tracker *tracker,
45 const char *name,
46 struct lttng_poll_event *events,
47 int size,
48 int flags)
49 {
50 int out_fd;
51 struct create_args create_args = {
52 .events = events,
53 .size = size,
54 .flags = flags,
55 };
56
57 return fd_tracker_open_unsuspendable_fd(
58 tracker, &out_fd, &name, 1, open_epoll, &create_args);
59 }
60
61 int fd_tracker_util_poll_clean(
62 struct fd_tracker *tracker, struct lttng_poll_event *events)
63 {
64 return fd_tracker_close_unsuspendable_fd(
65 tracker, &events->epfd, 1, close_epoll, events);
66 }
This page took 0.032136 seconds and 5 git commands to generate.