2 * Copyright (C) 2011 EfficiOS Inc.
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.hpp"
12 #include <common/utils.hpp>
16 * Quit pipe for the main thread. This is used by signal handlers to start the
17 * shutdown sequence of the main thread which will tear down the other threads
18 * in the appropriate order.
20 static int main_quit_pipe
[2] = { -1, -1 };
23 * Init main quit pipe.
25 * Return -1 on error or 0 if all pipes are created.
27 int sessiond_init_main_quit_pipe(void)
31 ret
= pipe(main_quit_pipe
);
33 PERROR("main quit pipe");
37 for (i
= 0; i
< 2; i
++) {
38 ret
= fcntl(main_quit_pipe
[i
], F_SETFD
, FD_CLOEXEC
);
40 PERROR("fcntl main_quit_pipe");
50 * Wait for a notification on the main quit pipe (with a timeout).
52 * A timeout value of -1U means no timeout.
54 * Returns 1 if the caller should quit, 0 if the timeout was reached, and
55 * -1 if an error was encountered.
57 int sessiond_wait_for_main_quit_pipe(int timeout_ms
)
60 struct lttng_poll_event events
;
62 ret
= lttng_poll_create(&events
, 1, LTTNG_CLOEXEC
);
64 PERROR("Failed to initialize poll/epoll set");
68 ret
= lttng_poll_add(&events
, main_quit_pipe
[0], LPOLLIN
);
70 PERROR("Failed to add file descriptor to poll/epoll set");
74 ret
= lttng_poll_wait(&events
, timeout_ms
);
78 } else if (ret
< 0 && errno
!= EINTR
) {
80 PERROR("Failed to epoll()/poll() main quit pipe");
83 /* Timeout reached. */
87 lttng_poll_clean(&events
);
92 int sessiond_notify_main_quit_pipe(void)
94 return notify_thread_pipe(main_quit_pipe
[1]);
97 void sessiond_close_main_quit_pipe(void)
99 utils_close_pipe(main_quit_pipe
);
103 * Create a poll set with O_CLOEXEC and add the main quit pipe to the set.
105 int sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
)
109 LTTNG_ASSERT(events
);
111 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
116 /* Add main quit pipe */
117 ret
= lttng_poll_add(events
, main_quit_pipe
[0], LPOLLIN
);
This page took 0.034095 seconds and 4 git commands to generate.