Cleanup: autoconf 'dirfd' detection
[lttng-tools.git] / src / common / fd-tracker / utils-epoll.c
CommitLineData
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
12struct create_args {
13 struct lttng_poll_event *events;
14 int size;
15 int flags;
16};
17
5c1f54d1 18static int open_epoll(void *data, int *out_fd)
184597e3
JG
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;
29end:
30 return ret;
31}
32
5c1f54d1 33static int close_epoll(void *data, int *in_fd)
184597e3
JG
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 */
5c1f54d1
JG
44int 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)
184597e3
JG
49{
50 int out_fd;
51 struct create_args create_args = {
52 .events = events,
53 .size = size,
54 .flags = flags,
55 };
56
5c1f54d1
JG
57 return fd_tracker_open_unsuspendable_fd(
58 tracker, &out_fd, &name, 1, open_epoll, &create_args);
184597e3
JG
59}
60
5c1f54d1
JG
61int fd_tracker_util_poll_clean(
62 struct fd_tracker *tracker, struct lttng_poll_event *events)
184597e3 63{
5c1f54d1
JG
64 return fd_tracker_close_unsuspendable_fd(
65 tracker, &events->epfd, 1, close_epoll, events);
184597e3 66}
This page took 0.039567 seconds and 4 git commands to generate.