2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
10 #include "lttng-sessiond.h"
12 #include <common/utils.h>
16 * Quit pipe for all threads. This permits a single cancellation point
17 * for all threads when receiving an event on the pipe.
19 static int thread_quit_pipe
[2] = { -1, -1 };
22 * Init thread quit pipe.
24 * Return -1 on error or 0 if all pipes are created.
26 static int __init_thread_quit_pipe(int *a_pipe
)
32 PERROR("thread quit pipe");
36 for (i
= 0; i
< 2; i
++) {
37 ret
= fcntl(a_pipe
[i
], F_SETFD
, FD_CLOEXEC
);
48 int sessiond_init_thread_quit_pipe(void)
50 return __init_thread_quit_pipe(thread_quit_pipe
);
53 int sessiond_check_thread_quit_pipe(int fd
, uint32_t events
)
55 return (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
));
59 * Wait for a notification on the quit pipe (with a timeout).
61 * A timeout value of -1U means no timeout.
63 * Returns 1 if the caller should quit, 0 if the timeout was reached, and
64 * -1 if an error was encountered.
66 int sessiond_wait_for_quit_pipe(int timeout_ms
)
69 struct lttng_poll_event events
;
71 ret
= lttng_poll_create(&events
, 1, LTTNG_CLOEXEC
);
73 PERROR("Failed to initialize poll/epoll set");
77 ret
= lttng_poll_add(&events
, thread_quit_pipe
[0], LPOLLIN
| LPOLLERR
);
79 PERROR("Failed to add file descriptor to poll/epoll set");
83 ret
= lttng_poll_wait(&events
, timeout_ms
);
87 } else if (ret
< 0 && errno
!= EINTR
) {
89 PERROR("Failed to epoll()/poll() thread quit pipe");
92 /* Timeout reached. */
96 lttng_poll_clean(&events
);
101 int sessiond_notify_quit_pipe(void)
103 return notify_thread_pipe(thread_quit_pipe
[1]);
106 void sessiond_close_quit_pipe(void)
108 utils_close_pipe(thread_quit_pipe
);
112 int __sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
,
119 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
125 ret
= lttng_poll_add(events
, a_pipe
[0], LPOLLIN
| LPOLLERR
);
137 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
139 int sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
)
141 return __sessiond_set_thread_pollset(events
, size
, thread_quit_pipe
);
This page took 0.037314 seconds and 4 git commands to generate.