Sync ax_have_epoll.m4 with autoconf-archive
[lttng-tools.git] / src / common / fd-tracker / utils-epoll.c
CommitLineData
184597e3
JG
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
22struct create_args {
23 struct lttng_poll_event *events;
24 int size;
25 int flags;
26};
27
5c1f54d1 28static int open_epoll(void *data, int *out_fd)
184597e3
JG
29{
30 int ret;
31 struct create_args *args = data;
32
33 ret = lttng_poll_create(args->events, args->size, args->flags);
34 if (ret < 0) {
35 goto end;
36 }
37
38 *out_fd = args->events->epfd;
39end:
40 return ret;
41}
42
5c1f54d1 43static int close_epoll(void *data, int *in_fd)
184597e3
JG
44{
45 /* Will close the epfd. */
46 lttng_poll_clean((struct lttng_poll_event *) data);
47 return 0;
48}
49
50/*
51 * The epoll variant of the poll compat layer creates an unsuspendable fd which
52 * must be tracked.
53 */
5c1f54d1
JG
54int fd_tracker_util_poll_create(struct fd_tracker *tracker,
55 const char *name,
56 struct lttng_poll_event *events,
57 int size,
58 int flags)
184597e3
JG
59{
60 int out_fd;
61 struct create_args create_args = {
62 .events = events,
63 .size = size,
64 .flags = flags,
65 };
66
5c1f54d1
JG
67 return fd_tracker_open_unsuspendable_fd(
68 tracker, &out_fd, &name, 1, open_epoll, &create_args);
184597e3
JG
69}
70
5c1f54d1
JG
71int fd_tracker_util_poll_clean(
72 struct fd_tracker *tracker, struct lttng_poll_event *events)
184597e3 73{
5c1f54d1
JG
74 return fd_tracker_close_unsuspendable_fd(
75 tracker, &events->epfd, 1, close_epoll, events);
184597e3 76}
This page took 0.02522 seconds and 4 git commands to generate.