common: move utils_create_lock_file to its own file
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
CommitLineData
826d496d 1/*
a4eb26f0 2 * Copyright (C) 2011 EfficiOS Inc.
ab5be9fa
MJ
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
fac6795d 5 *
ab5be9fa 6 * SPDX-License-Identifier: GPL-2.0-only
91d76f53 7 *
fac6795d
DG
8 */
9
6c1c0768 10#define _LGPL_SOURCE
fac6795d
DG
11#include <getopt.h>
12#include <grp.h>
13#include <limits.h>
0bb7724a 14#include <paths.h>
fac6795d
DG
15#include <pthread.h>
16#include <signal.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
331744e3 20#include <inttypes.h>
0fdd1e2c 21#include <sys/mman.h>
b73401da 22#include <sys/mount.h>
1e307fab 23#include <sys/resource.h>
fac6795d
DG
24#include <sys/socket.h>
25#include <sys/stat.h>
26#include <sys/types.h>
0fdd1e2c 27#include <sys/wait.h>
5c827ce0 28#include <urcu/uatomic.h>
fac6795d 29#include <unistd.h>
4f0b90ee 30#include <ctype.h>
fac6795d 31
990570ed 32#include <common/common.h>
d27c42b8 33#include <common/compat/socket.h>
e8fa9fb0 34#include <common/compat/getenv.h>
db758600
DG
35#include <common/defaults.h>
36#include <common/kernel-consumer/kernel-consumer.h>
50c8f484 37#include <common/futex.h>
00e2e675 38#include <common/relayd/relayd.h>
81b86775 39#include <common/utils.h>
cf7e5f00 40#include <common/lockfile.h>
e40c873f 41#include <common/path.h>
3ccdf997 42#include <common/daemonize.h>
f40ef1d5 43#include <common/config/session-config.h>
dcabc190 44#include <common/dynamic-buffer.h>
76fcf151 45#include <lttng/event-internal.h>
fac6795d 46
10a8a223 47#include "lttng-sessiond.h"
7972aab2 48#include "buffer-registry.h"
54d01ffb 49#include "channel.h"
2f77fc4b 50#include "cmd.h"
00e2e675 51#include "consumer.h"
099e26bd 52#include "context.h"
54d01ffb 53#include "event.h"
4771f025 54#include "kernel.h"
f1e16794 55#include "kernel-consumer.h"
0fdd1e2c 56#include "shm.h"
75018ab6 57#include "lttng-ust-ctl.h"
00e2e675 58#include "ust-consumer.h"
8e68d1c8 59#include "utils.h"
4063050c 60#include "fd-limit.h"
8782cc74 61#include "health-sessiond.h"
8ac94142 62#include "testpoint.h"
f9d2ba6a 63#include "notify-apps.h"
022d91ba 64#include "agent-thread.h"
fb198a11 65#include "save.h"
b3530820
JG
66#include "notification-thread.h"
67#include "notification-thread-commands.h"
db66e574 68#include "rotation-thread.h"
7c1d2758 69#include "agent.h"
5e97de00 70#include "ht-cleanup.h"
e6142f2e 71#include "sessiond-config.h"
8e319828 72#include "timer.h"
a3707772 73#include "thread.h"
917a718d 74#include "client.h"
5d1b0219 75#include "dispatch.h"
1785d7f2 76#include "register.h"
7649924e 77#include "manage-apps.h"
5b093681 78#include "manage-kernel.h"
ebaeda94 79
4fc83d94
PP
80static const char *help_msg =
81#ifdef LTTNG_EMBED_HELP
82#include <lttng-sessiond.8.h>
83#else
84NULL
85#endif
86;
87
fac6795d 88const char *progname;
c9cb3e7d 89static int lockfile_fd = -1;
a3bc3918 90static int opt_print_version;
3bd1e081 91
0bb7724a
DG
92/* Set to 1 when a SIGUSR1 signal is received. */
93static int recv_child_signal;
94
26296c48
JG
95/* Command line options */
96static const struct option long_options[] = {
0f5ea17c
JG
97 { "client-sock", required_argument, 0, 'c' },
98 { "apps-sock", required_argument, 0, 'a' },
99 { "kconsumerd-cmd-sock", required_argument, 0, '\0' },
100 { "kconsumerd-err-sock", required_argument, 0, '\0' },
101 { "ustconsumerd32-cmd-sock", required_argument, 0, '\0' },
102 { "ustconsumerd32-err-sock", required_argument, 0, '\0' },
103 { "ustconsumerd64-cmd-sock", required_argument, 0, '\0' },
104 { "ustconsumerd64-err-sock", required_argument, 0, '\0' },
105 { "consumerd32-path", required_argument, 0, '\0' },
106 { "consumerd32-libdir", required_argument, 0, '\0' },
107 { "consumerd64-path", required_argument, 0, '\0' },
108 { "consumerd64-libdir", required_argument, 0, '\0' },
109 { "daemonize", no_argument, 0, 'd' },
110 { "background", no_argument, 0, 'b' },
111 { "sig-parent", no_argument, 0, 'S' },
112 { "help", no_argument, 0, 'h' },
113 { "group", required_argument, 0, 'g' },
114 { "version", no_argument, 0, 'V' },
115 { "quiet", no_argument, 0, 'q' },
116 { "verbose", no_argument, 0, 'v' },
117 { "verbose-consumer", no_argument, 0, '\0' },
118 { "no-kernel", no_argument, 0, '\0' },
119 { "pidfile", required_argument, 0, 'p' },
120 { "agent-tcp-port", required_argument, 0, '\0' },
121 { "config", required_argument, 0, 'f' },
122 { "load", required_argument, 0, 'l' },
123 { "kmod-probes", required_argument, 0, '\0' },
124 { "extra-kmod-probes", required_argument, 0, '\0' },
26296c48
JG
125 { NULL, 0, 0, 0 }
126};
127
128/* Command line options to ignore from configuration file */
129static const char *config_ignore_options[] = { "help", "version", "config" };
1d4b027a 130
099e26bd
DG
131/*
132 * This pipe is used to inform the thread managing application communication
133 * that a command is queued and ready to be processed.
134 */
76d7553f 135static int apps_cmd_pipe[2] = { -1, -1 };
971a61c6 136static int apps_cmd_notify_pipe[2] = { -1, -1 };
099e26bd 137
099e26bd
DG
138/*
139 * UST registration command queue. This queue is tied with a futex and uses a N
140 * wakers / 1 waiter implemented and detailed in futex.c/.h
141 *
b22c5da8
DG
142 * The thread_registration_apps and thread_dispatch_ust_registration uses this
143 * queue along with the wait/wake scheme. The thread_manage_apps receives down
144 * the line new application socket and monitors it for any I/O error or clean
145 * close that triggers an unregistration of the application.
099e26bd
DG
146 */
147static struct ust_cmd_queue ust_cmd_queue;
148
97bc1426 149/*
a7333da7 150 * Section name to look for in the daemon configuration file.
97bc1426 151 */
a7333da7 152static const char * const config_section_name = "sessiond";
5e97de00 153
a7333da7
JG
154/* Am I root or not. Set to 1 if the daemon is running as root */
155static int is_root;
5eb91c98 156
099e26bd
DG
157/*
158 * Stop all threads by closing the thread quit pipe.
159 */
cf3af59e
MD
160static void stop_threads(void)
161{
5eb91c98
DG
162 int ret;
163
cf3af59e
MD
164 /* Stopping all threads */
165 DBG("Terminating all threads");
a7333da7 166 ret = sessiond_notify_quit_pipe();
5eb91c98
DG
167 if (ret < 0) {
168 ERR("write error on thread quit pipe");
169 }
cf3af59e
MD
170}
171
e975f9f8
DG
172/*
173 * Close every consumer sockets.
174 */
175static void close_consumer_sockets(void)
176{
177 int ret;
178
179 if (kconsumer_data.err_sock >= 0) {
180 ret = close(kconsumer_data.err_sock);
181 if (ret < 0) {
182 PERROR("kernel consumer err_sock close");
183 }
184 }
185 if (ustconsumer32_data.err_sock >= 0) {
186 ret = close(ustconsumer32_data.err_sock);
187 if (ret < 0) {
a76cbd9f 188 PERROR("UST consumerd32 err_sock close");
e975f9f8
DG
189 }
190 }
191 if (ustconsumer64_data.err_sock >= 0) {
192 ret = close(ustconsumer64_data.err_sock);
193 if (ret < 0) {
a76cbd9f 194 PERROR("UST consumerd64 err_sock close");
e975f9f8
DG
195 }
196 }
197 if (kconsumer_data.cmd_sock >= 0) {
198 ret = close(kconsumer_data.cmd_sock);
199 if (ret < 0) {
200 PERROR("kernel consumer cmd_sock close");
201 }
202 }
203 if (ustconsumer32_data.cmd_sock >= 0) {
204 ret = close(ustconsumer32_data.cmd_sock);
205 if (ret < 0) {
a76cbd9f 206 PERROR("UST consumerd32 cmd_sock close");
e975f9f8
DG
207 }
208 }
209 if (ustconsumer64_data.cmd_sock >= 0) {
210 ret = close(ustconsumer64_data.cmd_sock);
211 if (ret < 0) {
a76cbd9f 212 PERROR("UST consumerd64 cmd_sock close");
e975f9f8
DG
213 }
214 }
b3530820
JG
215 if (kconsumer_data.channel_monitor_pipe >= 0) {
216 ret = close(kconsumer_data.channel_monitor_pipe);
217 if (ret < 0) {
218 PERROR("kernel consumer channel monitor pipe close");
219 }
220 }
221 if (ustconsumer32_data.channel_monitor_pipe >= 0) {
222 ret = close(ustconsumer32_data.channel_monitor_pipe);
223 if (ret < 0) {
224 PERROR("UST consumerd32 channel monitor pipe close");
225 }
226 }
227 if (ustconsumer64_data.channel_monitor_pipe >= 0) {
228 ret = close(ustconsumer64_data.channel_monitor_pipe);
229 if (ret < 0) {
230 PERROR("UST consumerd64 channel monitor pipe close");
231 }
232 }
e975f9f8
DG
233}
234
4e4714cb
JR
235/*
236 * Wait on consumer process termination.
237 *
238 * Need to be called with the consumer data lock held or from a context
239 * ensuring no concurrent access to data (e.g: cleanup).
240 */
241static void wait_consumer(struct consumer_data *consumer_data)
242{
243 pid_t ret;
244 int status;
245
246 if (consumer_data->pid <= 0) {
247 return;
248 }
249
250 DBG("Waiting for complete teardown of consumerd (PID: %d)",
251 consumer_data->pid);
252 ret = waitpid(consumer_data->pid, &status, 0);
253 if (ret == -1) {
254 PERROR("consumerd waitpid pid: %d", consumer_data->pid)
1640c24c 255 } else if (!WIFEXITED(status)) {
4e4714cb
JR
256 ERR("consumerd termination with error: %d",
257 WEXITSTATUS(ret));
258 }
259 consumer_data->pid = 0;
260}
261
fac6795d 262/*
4a15001e 263 * Cleanup the session daemon's data structures.
fac6795d 264 */
4a15001e 265static void sessiond_cleanup(void)
fac6795d 266{
ef599319 267 int ret;
e32d7f27 268 struct ltt_session_list *session_list = session_get_list();
fac6795d 269
4a15001e 270 DBG("Cleanup sessiond");
e07ae692 271
4e449f3f
MD
272 /*
273 * Close the thread quit pipe. It has already done its job,
274 * since we are now called.
275 */
a7333da7 276 sessiond_close_quit_pipe();
971a61c6
JG
277 utils_close_pipe(apps_cmd_pipe);
278 utils_close_pipe(apps_cmd_notify_pipe);
5b093681 279 utils_close_pipe(kernel_poll_pipe);
2f77fc4b 280
c9a2957d
JG
281 ret = remove(config.pid_file_path.value);
282 if (ret < 0) {
283 PERROR("remove pidfile %s", config.pid_file_path.value);
35f90c40
DG
284 }
285
e6142f2e
JG
286 DBG("Removing sessiond and consumerd content of directory %s",
287 config.rundir.value);
8c6c56c2
MD
288
289 /* sessiond */
e6142f2e
JG
290 DBG("Removing %s", config.pid_file_path.value);
291 (void) unlink(config.pid_file_path.value);
8c6c56c2 292
e6142f2e
JG
293 DBG("Removing %s", config.agent_port_file_path.value);
294 (void) unlink(config.agent_port_file_path.value);
cd9290dd 295
8c6c56c2 296 /* kconsumerd */
e6142f2e
JG
297 DBG("Removing %s", kconsumer_data.err_unix_sock_path);
298 (void) unlink(kconsumer_data.err_unix_sock_path);
299
300 DBG("Removing directory %s", config.kconsumerd_path.value);
301 (void) rmdir(config.kconsumerd_path.value);
8c6c56c2
MD
302
303 /* ust consumerd 32 */
e6142f2e
JG
304 DBG("Removing %s", config.consumerd32_err_unix_sock_path.value);
305 (void) unlink(config.consumerd32_err_unix_sock_path.value);
306
307 DBG("Removing directory %s", config.consumerd32_path.value);
308 (void) rmdir(config.consumerd32_path.value);
8c6c56c2
MD
309
310 /* ust consumerd 64 */
e6142f2e
JG
311 DBG("Removing %s", config.consumerd64_err_unix_sock_path.value);
312 (void) unlink(config.consumerd64_err_unix_sock_path.value);
313
314 DBG("Removing directory %s", config.consumerd64_path.value);
315 (void) rmdir(config.consumerd64_path.value);
5461b305 316
99d688f2 317 pthread_mutex_destroy(&session_list->lock);
273ea72c 318
6a4e4039
JG
319 DBG("Cleaning up all agent apps");
320 agent_app_ht_clean();
099e26bd 321 DBG("Closing all UST sockets");
56fff090 322 ust_app_clean_list();
7972aab2 323 buffer_reg_destroy_registries();
099e26bd 324
0787fc4b
MD
325 close_consumer_sockets();
326
327 wait_consumer(&kconsumer_data);
328 wait_consumer(&ustconsumer64_data);
329 wait_consumer(&ustconsumer32_data);
330
e6142f2e 331 if (is_root && !config.no_kernel) {
7d268848 332 cleanup_kernel_tracer();
2f50c8a3 333 }
2f77fc4b 334
c9cb3e7d
JG
335 /*
336 * We do NOT rmdir rundir because there are other processes
337 * using it, for instance lttng-relayd, which can start in
338 * parallel with this teardown.
339 */
4a15001e
MD
340}
341
342/*
343 * Cleanup the daemon's option data structures.
344 */
345static void sessiond_cleanup_options(void)
346{
347 DBG("Cleaning up options");
348
e6142f2e 349 sessiond_config_fini(&config);
c9cb3e7d 350
7567352f 351 run_as_destroy_worker();
fac6795d
DG
352}
353
917a718d 354static int string_match(const char *str1, const char *str2)
54d01ffb 355{
917a718d 356 return (str1 && str2) && !strcmp(str1, str2);
54d01ffb
DG
357}
358
00e2e675 359/*
917a718d
JG
360 * Take an option from the getopt output and set it in the right variable to be
361 * used later.
36b588ed 362 *
917a718d 363 * Return 0 on success else a negative value.
00e2e675 364 */
917a718d 365static int set_option(int opt, const char *arg, const char *optname)
00e2e675 366{
917a718d 367 int ret = 0;
fac6795d 368
c0232ea5 369 if (string_match(optname, "client-sock") || opt == 'c') {
66b2ce8e
JG
370 if (!arg || *arg == '\0') {
371 ret = -EINVAL;
372 goto end;
373 }
e8fa9fb0
MD
374 if (lttng_is_setuid_setgid()) {
375 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
376 "-c, --client-sock");
377 } else {
e6142f2e
JG
378 config_string_set(&config.client_unix_sock_path,
379 strdup(arg));
380 if (!config.client_unix_sock_path.value) {
381 ret = -ENOMEM;
382 PERROR("strdup");
383 }
e8fa9fb0 384 }
c0232ea5 385 } else if (string_match(optname, "apps-sock") || opt == 'a') {
66b2ce8e
JG
386 if (!arg || *arg == '\0') {
387 ret = -EINVAL;
388 goto end;
389 }
e8fa9fb0
MD
390 if (lttng_is_setuid_setgid()) {
391 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
392 "-a, --apps-sock");
393 } else {
e6142f2e
JG
394 config_string_set(&config.apps_unix_sock_path,
395 strdup(arg));
396 if (!config.apps_unix_sock_path.value) {
397 ret = -ENOMEM;
398 PERROR("strdup");
399 }
e8fa9fb0 400 }
c0232ea5 401 } else if (string_match(optname, "daemonize") || opt == 'd') {
e6142f2e 402 config.daemonize = true;
c0232ea5 403 } else if (string_match(optname, "background") || opt == 'b') {
e6142f2e 404 config.background = true;
c0232ea5 405 } else if (string_match(optname, "group") || opt == 'g') {
66b2ce8e
JG
406 if (!arg || *arg == '\0') {
407 ret = -EINVAL;
408 goto end;
409 }
e8fa9fb0
MD
410 if (lttng_is_setuid_setgid()) {
411 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
412 "-g, --group");
413 } else {
e6142f2e
JG
414 config_string_set(&config.tracing_group_name,
415 strdup(arg));
416 if (!config.tracing_group_name.value) {
e8fa9fb0 417 ret = -ENOMEM;
e6142f2e 418 PERROR("strdup");
e8fa9fb0 419 }
db322c4d 420 }
c0232ea5 421 } else if (string_match(optname, "help") || opt == 'h') {
4fc83d94 422 ret = utils_show_help(8, "lttng-sessiond", help_msg);
8190767e 423 if (ret) {
4fc83d94 424 ERR("Cannot show --help for `lttng-sessiond`");
8190767e
PP
425 perror("exec");
426 }
427 exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);
c0232ea5 428 } else if (string_match(optname, "version") || opt == 'V') {
a3bc3918 429 opt_print_version = 1;
c0232ea5 430 } else if (string_match(optname, "sig-parent") || opt == 'S') {
e6142f2e 431 config.sig_parent = true;
c0232ea5 432 } else if (string_match(optname, "kconsumerd-err-sock")) {
66b2ce8e
JG
433 if (!arg || *arg == '\0') {
434 ret = -EINVAL;
435 goto end;
436 }
e8fa9fb0
MD
437 if (lttng_is_setuid_setgid()) {
438 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
439 "--kconsumerd-err-sock");
440 } else {
e6142f2e
JG
441 config_string_set(&config.kconsumerd_err_unix_sock_path,
442 strdup(arg));
443 if (!config.kconsumerd_err_unix_sock_path.value) {
444 ret = -ENOMEM;
445 PERROR("strdup");
446 }
e8fa9fb0 447 }
c0232ea5 448 } else if (string_match(optname, "kconsumerd-cmd-sock")) {
66b2ce8e
JG
449 if (!arg || *arg == '\0') {
450 ret = -EINVAL;
451 goto end;
452 }
e8fa9fb0
MD
453 if (lttng_is_setuid_setgid()) {
454 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
455 "--kconsumerd-cmd-sock");
456 } else {
e6142f2e
JG
457 config_string_set(&config.kconsumerd_cmd_unix_sock_path,
458 strdup(arg));
459 if (!config.kconsumerd_cmd_unix_sock_path.value) {
460 ret = -ENOMEM;
461 PERROR("strdup");
462 }
e8fa9fb0 463 }
c0232ea5 464 } else if (string_match(optname, "ustconsumerd64-err-sock")) {
66b2ce8e
JG
465 if (!arg || *arg == '\0') {
466 ret = -EINVAL;
467 goto end;
468 }
e8fa9fb0
MD
469 if (lttng_is_setuid_setgid()) {
470 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
471 "--ustconsumerd64-err-sock");
472 } else {
e6142f2e
JG
473 config_string_set(&config.consumerd64_err_unix_sock_path,
474 strdup(arg));
475 if (!config.consumerd64_err_unix_sock_path.value) {
476 ret = -ENOMEM;
477 PERROR("strdup");
478 }
e8fa9fb0 479 }
c0232ea5 480 } else if (string_match(optname, "ustconsumerd64-cmd-sock")) {
66b2ce8e
JG
481 if (!arg || *arg == '\0') {
482 ret = -EINVAL;
483 goto end;
484 }
e8fa9fb0
MD
485 if (lttng_is_setuid_setgid()) {
486 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
487 "--ustconsumerd64-cmd-sock");
488 } else {
e6142f2e
JG
489 config_string_set(&config.consumerd64_cmd_unix_sock_path,
490 strdup(arg));
491 if (!config.consumerd64_cmd_unix_sock_path.value) {
492 ret = -ENOMEM;
493 PERROR("strdup");
494 }
e8fa9fb0 495 }
c0232ea5 496 } else if (string_match(optname, "ustconsumerd32-err-sock")) {
66b2ce8e
JG
497 if (!arg || *arg == '\0') {
498 ret = -EINVAL;
499 goto end;
500 }
e8fa9fb0
MD
501 if (lttng_is_setuid_setgid()) {
502 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
503 "--ustconsumerd32-err-sock");
504 } else {
e6142f2e
JG
505 config_string_set(&config.consumerd32_err_unix_sock_path,
506 strdup(arg));
507 if (!config.consumerd32_err_unix_sock_path.value) {
508 ret = -ENOMEM;
509 PERROR("strdup");
510 }
e8fa9fb0 511 }
c0232ea5 512 } else if (string_match(optname, "ustconsumerd32-cmd-sock")) {
66b2ce8e
JG
513 if (!arg || *arg == '\0') {
514 ret = -EINVAL;
515 goto end;
516 }
e8fa9fb0
MD
517 if (lttng_is_setuid_setgid()) {
518 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
519 "--ustconsumerd32-cmd-sock");
520 } else {
e6142f2e
JG
521 config_string_set(&config.consumerd32_cmd_unix_sock_path,
522 strdup(arg));
523 if (!config.consumerd32_cmd_unix_sock_path.value) {
524 ret = -ENOMEM;
525 PERROR("strdup");
526 }
e8fa9fb0 527 }
c0232ea5 528 } else if (string_match(optname, "no-kernel")) {
e6142f2e 529 config.no_kernel = true;
c0232ea5 530 } else if (string_match(optname, "quiet") || opt == 'q') {
6d9a9c65 531 config.quiet = true;
c0232ea5 532 } else if (string_match(optname, "verbose") || opt == 'v') {
26296c48
JG
533 /* Verbose level can increase using multiple -v */
534 if (arg) {
13755a18 535 /* Value obtained from config file */
e6142f2e 536 config.verbose = config_parse_value(arg);
26296c48 537 } else {
13755a18 538 /* -v used on command line */
e6142f2e 539 config.verbose++;
26296c48 540 }
13755a18 541 /* Clamp value to [0, 3] */
e6142f2e
JG
542 config.verbose = config.verbose < 0 ? 0 :
543 (config.verbose <= 3 ? config.verbose : 3);
c0232ea5 544 } else if (string_match(optname, "verbose-consumer")) {
26296c48 545 if (arg) {
e6142f2e 546 config.verbose_consumer = config_parse_value(arg);
26296c48 547 } else {
e6142f2e 548 config.verbose_consumer++;
26296c48 549 }
c0232ea5 550 } else if (string_match(optname, "consumerd32-path")) {
66b2ce8e
JG
551 if (!arg || *arg == '\0') {
552 ret = -EINVAL;
553 goto end;
554 }
e8fa9fb0
MD
555 if (lttng_is_setuid_setgid()) {
556 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
557 "--consumerd32-path");
558 } else {
e6142f2e
JG
559 config_string_set(&config.consumerd32_bin_path,
560 strdup(arg));
561 if (!config.consumerd32_bin_path.value) {
e8fa9fb0
MD
562 PERROR("strdup");
563 ret = -ENOMEM;
564 }
db322c4d 565 }
c0232ea5 566 } else if (string_match(optname, "consumerd32-libdir")) {
66b2ce8e
JG
567 if (!arg || *arg == '\0') {
568 ret = -EINVAL;
569 goto end;
570 }
e8fa9fb0
MD
571 if (lttng_is_setuid_setgid()) {
572 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
573 "--consumerd32-libdir");
574 } else {
e6142f2e
JG
575 config_string_set(&config.consumerd32_lib_dir,
576 strdup(arg));
577 if (!config.consumerd32_lib_dir.value) {
e8fa9fb0
MD
578 PERROR("strdup");
579 ret = -ENOMEM;
580 }
db322c4d 581 }
c0232ea5 582 } else if (string_match(optname, "consumerd64-path")) {
66b2ce8e
JG
583 if (!arg || *arg == '\0') {
584 ret = -EINVAL;
585 goto end;
586 }
e8fa9fb0
MD
587 if (lttng_is_setuid_setgid()) {
588 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
589 "--consumerd64-path");
590 } else {
e6142f2e
JG
591 config_string_set(&config.consumerd64_bin_path,
592 strdup(arg));
593 if (!config.consumerd64_bin_path.value) {
e8fa9fb0
MD
594 PERROR("strdup");
595 ret = -ENOMEM;
596 }
db322c4d 597 }
c0232ea5 598 } else if (string_match(optname, "consumerd64-libdir")) {
66b2ce8e
JG
599 if (!arg || *arg == '\0') {
600 ret = -EINVAL;
601 goto end;
602 }
e8fa9fb0
MD
603 if (lttng_is_setuid_setgid()) {
604 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
605 "--consumerd64-libdir");
606 } else {
e6142f2e
JG
607 config_string_set(&config.consumerd64_lib_dir,
608 strdup(arg));
609 if (!config.consumerd64_lib_dir.value) {
e8fa9fb0
MD
610 PERROR("strdup");
611 ret = -ENOMEM;
612 }
db322c4d 613 }
c0232ea5 614 } else if (string_match(optname, "pidfile") || opt == 'p') {
66b2ce8e
JG
615 if (!arg || *arg == '\0') {
616 ret = -EINVAL;
617 goto end;
618 }
e8fa9fb0
MD
619 if (lttng_is_setuid_setgid()) {
620 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
621 "-p, --pidfile");
622 } else {
e6142f2e
JG
623 config_string_set(&config.pid_file_path, strdup(arg));
624 if (!config.pid_file_path.value) {
e8fa9fb0
MD
625 PERROR("strdup");
626 ret = -ENOMEM;
627 }
db322c4d 628 }
c0232ea5 629 } else if (string_match(optname, "agent-tcp-port")) {
66b2ce8e
JG
630 if (!arg || *arg == '\0') {
631 ret = -EINVAL;
632 goto end;
633 }
e8fa9fb0
MD
634 if (lttng_is_setuid_setgid()) {
635 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
636 "--agent-tcp-port");
637 } else {
638 unsigned long v;
4d076222 639
e8fa9fb0
MD
640 errno = 0;
641 v = strtoul(arg, NULL, 0);
642 if (errno != 0 || !isdigit(arg[0])) {
643 ERR("Wrong value in --agent-tcp-port parameter: %s", arg);
644 return -1;
645 }
646 if (v == 0 || v >= 65535) {
647 ERR("Port overflow in --agent-tcp-port parameter: %s", arg);
648 return -1;
649 }
2288467f
JG
650 config.agent_tcp_port.begin = config.agent_tcp_port.end = (int) v;
651 DBG3("Agent TCP port set to non default: %i", (int) v);
26296c48 652 }
c0232ea5 653 } else if (string_match(optname, "load") || opt == 'l') {
66b2ce8e
JG
654 if (!arg || *arg == '\0') {
655 ret = -EINVAL;
656 goto end;
657 }
e8fa9fb0
MD
658 if (lttng_is_setuid_setgid()) {
659 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
660 "-l, --load");
661 } else {
e6142f2e
JG
662 config_string_set(&config.load_session_path, strdup(arg));
663 if (!config.load_session_path.value) {
e8fa9fb0
MD
664 PERROR("strdup");
665 ret = -ENOMEM;
666 }
ef367a93 667 }
c0232ea5 668 } else if (string_match(optname, "kmod-probes")) {
66b2ce8e
JG
669 if (!arg || *arg == '\0') {
670 ret = -EINVAL;
671 goto end;
672 }
e8fa9fb0
MD
673 if (lttng_is_setuid_setgid()) {
674 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
675 "--kmod-probes");
676 } else {
e6142f2e
JG
677 config_string_set(&config.kmod_probes_list, strdup(arg));
678 if (!config.kmod_probes_list.value) {
e8fa9fb0
MD
679 PERROR("strdup");
680 ret = -ENOMEM;
681 }
c9d42407 682 }
c0232ea5 683 } else if (string_match(optname, "extra-kmod-probes")) {
66b2ce8e
JG
684 if (!arg || *arg == '\0') {
685 ret = -EINVAL;
686 goto end;
687 }
e8fa9fb0
MD
688 if (lttng_is_setuid_setgid()) {
689 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
690 "--extra-kmod-probes");
691 } else {
e6142f2e
JG
692 config_string_set(&config.kmod_extra_probes_list,
693 strdup(arg));
694 if (!config.kmod_extra_probes_list.value) {
e8fa9fb0
MD
695 PERROR("strdup");
696 ret = -ENOMEM;
697 }
db322c4d 698 }
c0232ea5
JG
699 } else if (string_match(optname, "config") || opt == 'f') {
700 /* This is handled in set_options() thus silent skip. */
701 goto end;
702 } else {
26296c48
JG
703 /* Unknown option or other error.
704 * Error is printed by getopt, just return */
705 ret = -1;
706 }
707
f3dd7ce7 708end:
c5d350b2
JG
709 if (ret == -EINVAL) {
710 const char *opt_name = "unknown";
711 int i;
712
713 for (i = 0; i < sizeof(long_options) / sizeof(struct option);
714 i++) {
715 if (opt == long_options[i].val) {
716 opt_name = long_options[i].name;
717 break;
718 }
719 }
720
721 WARN("Invalid argument provided for option \"%s\", using default value.",
722 opt_name);
723 }
f3dd7ce7 724
26296c48
JG
725 return ret;
726}
727
728/*
729 * config_entry_handler_cb used to handle options read from a config file.
f40ef1d5 730 * See config_entry_handler_cb comment in common/config/session-config.h for the
26296c48
JG
731 * return value conventions.
732 */
733static int config_entry_handler(const struct config_entry *entry, void *unused)
734{
735 int ret = 0, i;
736
737 if (!entry || !entry->name || !entry->value) {
738 ret = -EINVAL;
739 goto end;
740 }
741
742 /* Check if the option is to be ignored */
743 for (i = 0; i < sizeof(config_ignore_options) / sizeof(char *); i++) {
744 if (!strcmp(entry->name, config_ignore_options[i])) {
745 goto end;
746 }
747 }
748
749 for (i = 0; i < (sizeof(long_options) / sizeof(struct option)) - 1;
750 i++) {
751
752 /* Ignore if not fully matched. */
753 if (strcmp(entry->name, long_options[i].name)) {
754 continue;
755 }
756
757 /*
758 * If the option takes no argument on the command line, we have to
759 * check if the value is "true". We support non-zero numeric values,
760 * true, on and yes.
761 */
762 if (!long_options[i].has_arg) {
763 ret = config_parse_value(entry->value);
764 if (ret <= 0) {
765 if (ret) {
766 WARN("Invalid configuration value \"%s\" for option %s",
767 entry->value, entry->name);
768 }
769 /* False, skip boolean config option. */
770 goto end;
4d076222 771 }
26296c48
JG
772 }
773
774 ret = set_option(long_options[i].val, entry->value, entry->name);
775 goto end;
776 }
777
778 WARN("Unrecognized option \"%s\" in daemon configuration file.", entry->name);
779
780end:
781 return ret;
782}
783
a3bc3918
JR
784static void print_version(void) {
785 fprintf(stdout, "%s\n", VERSION);
786}
787
26296c48
JG
788/*
789 * daemon configuration loading and argument parsing
790 */
791static int set_options(int argc, char **argv)
792{
793 int ret = 0, c = 0, option_index = 0;
794 int orig_optopt = optopt, orig_optind = optind;
795 char *optstring;
12c5f50a 796 char *config_path = NULL;
26296c48
JG
797
798 optstring = utils_generate_optstring(long_options,
799 sizeof(long_options) / sizeof(struct option));
800 if (!optstring) {
801 ret = -ENOMEM;
802 goto end;
803 }
804
805 /* Check for the --config option */
806 while ((c = getopt_long(argc, argv, optstring, long_options,
807 &option_index)) != -1) {
808 if (c == '?') {
809 ret = -EINVAL;
810 goto end;
811 } else if (c != 'f') {
812 /* if not equal to --config option. */
813 continue;
814 }
815
e8fa9fb0
MD
816 if (lttng_is_setuid_setgid()) {
817 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
818 "-f, --config");
819 } else {
12c5f50a 820 free(config_path);
e8fa9fb0
MD
821 config_path = utils_expand_path(optarg);
822 if (!config_path) {
823 ERR("Failed to resolve path: %s", optarg);
824 }
26296c48
JG
825 }
826 }
827
828 ret = config_get_section_entries(config_path, config_section_name,
829 config_entry_handler, NULL);
830 if (ret) {
831 if (ret > 0) {
832 ERR("Invalid configuration option at line %i", ret);
833 ret = -1;
834 }
835 goto end;
836 }
837
838 /* Reset getopt's global state */
839 optopt = orig_optopt;
840 optind = orig_optind;
841 while (1) {
c0232ea5
JG
842 option_index = -1;
843 /*
844 * getopt_long() will not set option_index if it encounters a
845 * short option.
846 */
847 c = getopt_long(argc, argv, optstring, long_options,
848 &option_index);
26296c48 849 if (c == -1) {
4d076222
DG
850 break;
851 }
26296c48 852
c0232ea5
JG
853 /*
854 * Pass NULL as the long option name if popt left the index
855 * unset.
856 */
857 ret = set_option(c, optarg,
858 option_index < 0 ? NULL :
859 long_options[option_index].name);
26296c48
JG
860 if (ret < 0) {
861 break;
fac6795d
DG
862 }
863 }
864
26296c48 865end:
12c5f50a 866 free(config_path);
26296c48
JG
867 free(optstring);
868 return ret;
fac6795d
DG
869}
870
f472090a
JG
871/*
872 * Create lockfile using the rundir and return its fd.
873 */
874static int create_lockfile(void)
875{
876 return utils_create_lock_file(config.lock_file_path.value);
877}
878
fac6795d 879/*
54d01ffb
DG
880 * Check if the global socket is available, and if a daemon is answering at the
881 * other side. If yes, error is returned.
f472090a
JG
882 *
883 * Also attempts to create and hold the lock file.
fac6795d 884 */
cf3af59e 885static int check_existing_daemon(void)
fac6795d 886{
f472090a
JG
887 int ret = 0;
888
7d8234d9 889 /* Is there anybody out there ? */
099e26bd 890 if (lttng_session_daemon_alive()) {
f472090a
JG
891 ret = -EEXIST;
892 goto end;
099e26bd 893 }
b09c7c76 894
f472090a
JG
895 lockfile_fd = create_lockfile();
896 if (lockfile_fd < 0) {
897 ret = -EEXIST;
898 goto end;
899 }
900end:
901 return ret;
902}
903
904static void sessiond_cleanup_lock_file(void)
905{
906 int ret;
907
908 /*
909 * Cleanup lock file by deleting it and finaly closing it which will
910 * release the file system lock.
911 */
912 if (lockfile_fd >= 0) {
913 ret = remove(config.lock_file_path.value);
914 if (ret < 0) {
915 PERROR("remove lock file");
916 }
917 ret = close(lockfile_fd);
918 if (ret < 0) {
919 PERROR("close lock file");
920 }
921 }
fac6795d
DG
922}
923
fac6795d 924/*
d063d709 925 * Set the tracing group gid onto the client socket.
5e16da05 926 *
d063d709 927 * Race window between mkdir and chown is OK because we are going from more
d1613cf5 928 * permissive (root.root) to less permissive (root.tracing).
fac6795d 929 */
be040666 930static int set_permissions(char *rundir)
fac6795d
DG
931{
932 int ret;
996b65c8 933 gid_t gid;
fac6795d 934
28ab59d0
JR
935 ret = utils_get_group_id(config.tracing_group_name.value, true, &gid);
936 if (ret) {
937 /* Default to root group. */
938 gid = 0;
939 }
fac6795d 940
d6f42150 941 /* Set lttng run dir */
be040666 942 ret = chown(rundir, 0, gid);
d6f42150 943 if (ret < 0) {
be040666 944 ERR("Unable to set group on %s", rundir);
76d7553f 945 PERROR("chown");
d6f42150
DG
946 }
947
6c71277b
MD
948 /*
949 * Ensure all applications and tracing group can search the run
950 * dir. Allow everyone to read the directory, since it does not
951 * buy us anything to hide its content.
952 */
953 ret = chmod(rundir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
d1613cf5
JN
954 if (ret < 0) {
955 ERR("Unable to set permissions on %s", rundir);
76d7553f 956 PERROR("chmod");
d1613cf5
JN
957 }
958
d6f42150 959 /* lttng client socket path */
e6142f2e 960 ret = chown(config.client_unix_sock_path.value, 0, gid);
fac6795d 961 if (ret < 0) {
e6142f2e 962 ERR("Unable to set group on %s", config.client_unix_sock_path.value);
76d7553f 963 PERROR("chown");
d6f42150
DG
964 }
965
3bd1e081 966 /* kconsumer error socket path */
6c71277b 967 ret = chown(kconsumer_data.err_unix_sock_path, 0, 0);
d6f42150 968 if (ret < 0) {
3bd1e081 969 ERR("Unable to set group on %s", kconsumer_data.err_unix_sock_path);
76d7553f 970 PERROR("chown");
3bd1e081
MD
971 }
972
7753dea8 973 /* 64-bit ustconsumer error socket path */
6c71277b 974 ret = chown(ustconsumer64_data.err_unix_sock_path, 0, 0);
7753dea8
MD
975 if (ret < 0) {
976 ERR("Unable to set group on %s", ustconsumer64_data.err_unix_sock_path);
76d7553f 977 PERROR("chown");
7753dea8
MD
978 }
979
980 /* 32-bit ustconsumer compat32 error socket path */
6c71277b 981 ret = chown(ustconsumer32_data.err_unix_sock_path, 0, 0);
3bd1e081 982 if (ret < 0) {
7753dea8 983 ERR("Unable to set group on %s", ustconsumer32_data.err_unix_sock_path);
76d7553f 984 PERROR("chown");
fac6795d
DG
985 }
986
d6f42150 987 DBG("All permissions are set");
e07ae692 988
fac6795d
DG
989 return ret;
990}
991
d6f42150 992/*
d063d709 993 * Create the lttng run directory needed for all global sockets and pipe.
d6f42150 994 */
e6142f2e 995static int create_lttng_rundir(void)
d6f42150
DG
996{
997 int ret;
998
e6142f2e 999 DBG3("Creating LTTng run directory: %s", config.rundir.value);
67e40797 1000
e6142f2e 1001 ret = mkdir(config.rundir.value, S_IRWXU);
d6f42150 1002 if (ret < 0) {
b1f11e69 1003 if (errno != EEXIST) {
e6142f2e 1004 ERR("Unable to create %s", config.rundir.value);
b1f11e69
DG
1005 goto error;
1006 } else {
1007 ret = 0;
1008 }
d6f42150
DG
1009 }
1010
1011error:
1012 return ret;
1013}
1014
1015/*
e6142f2e 1016 * Setup sockets and directory needed by the consumerds' communication with the
d063d709 1017 * session daemon.
d6f42150 1018 */
e6142f2e 1019static int set_consumer_sockets(struct consumer_data *consumer_data)
d6f42150
DG
1020{
1021 int ret;
e6142f2e 1022 char *path = NULL;
d6f42150 1023
6c71277b 1024 switch (consumer_data->type) {
7753dea8 1025 case LTTNG_CONSUMER_KERNEL:
e6142f2e 1026 path = config.kconsumerd_path.value;
7753dea8
MD
1027 break;
1028 case LTTNG_CONSUMER64_UST:
e6142f2e 1029 path = config.consumerd64_path.value;
7753dea8
MD
1030 break;
1031 case LTTNG_CONSUMER32_UST:
e6142f2e 1032 path = config.consumerd32_path.value;
7753dea8
MD
1033 break;
1034 default:
1035 ERR("Consumer type unknown");
1036 ret = -EINVAL;
1037 goto error;
d6f42150 1038 }
e6142f2e 1039 assert(path);
d6f42150 1040
67e40797
DG
1041 DBG2("Creating consumer directory: %s", path);
1042
6c71277b 1043 ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP);
e7e1ef17
JR
1044 if (ret < 0 && errno != EEXIST) {
1045 PERROR("mkdir");
1046 ERR("Failed to create %s", path);
1047 goto error;
d6f42150 1048 }
6c71277b 1049 if (is_root) {
28ab59d0
JR
1050 gid_t gid;
1051
1052 ret = utils_get_group_id(config.tracing_group_name.value, true,
1053 &gid);
1054 if (ret) {
1055 /* Default to root group. */
1056 gid = 0;
1057 }
1058
1059 ret = chown(path, 0, gid);
6c71277b
MD
1060 if (ret < 0) {
1061 ERR("Unable to set group on %s", path);
1062 PERROR("chown");
1063 goto error;
1064 }
1065 }
d6f42150 1066
e6142f2e 1067 /* Create the consumerd error unix socket */
3bd1e081
MD
1068 consumer_data->err_sock =
1069 lttcomm_create_unix_sock(consumer_data->err_unix_sock_path);
1070 if (consumer_data->err_sock < 0) {
1071 ERR("Create unix sock failed: %s", consumer_data->err_unix_sock_path);
d6f42150
DG
1072 ret = -1;
1073 goto error;
1074 }
1075
a24f05ab
MD
1076 /*
1077 * Set the CLOEXEC flag. Return code is useless because either way, the
1078 * show must go on.
1079 */
1080 ret = utils_set_fd_cloexec(consumer_data->err_sock);
1081 if (ret < 0) {
1082 PERROR("utils_set_fd_cloexec");
1083 /* continue anyway */
1084 }
1085
d6f42150 1086 /* File permission MUST be 660 */
3bd1e081 1087 ret = chmod(consumer_data->err_unix_sock_path,
54d01ffb 1088 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
d6f42150 1089 if (ret < 0) {
3bd1e081 1090 ERR("Set file permissions failed: %s", consumer_data->err_unix_sock_path);
67e40797 1091 PERROR("chmod");
d6f42150
DG
1092 goto error;
1093 }
1094
1095error:
1096 return ret;
1097}
1098
fac6795d 1099/*
d063d709 1100 * Signal handler for the daemon
cf3af59e 1101 *
54d01ffb
DG
1102 * Simply stop all worker threads, leaving main() return gracefully after
1103 * joining all threads and calling cleanup().
fac6795d
DG
1104 */
1105static void sighandler(int sig)
1106{
1107 switch (sig) {
cf3af59e 1108 case SIGINT:
af87c45a 1109 DBG("SIGINT caught");
cf3af59e
MD
1110 stop_threads();
1111 break;
1112 case SIGTERM:
af87c45a 1113 DBG("SIGTERM caught");
cf3af59e
MD
1114 stop_threads();
1115 break;
0bb7724a
DG
1116 case SIGUSR1:
1117 CMM_STORE_SHARED(recv_child_signal, 1);
1118 break;
cf3af59e
MD
1119 default:
1120 break;
fac6795d 1121 }
fac6795d
DG
1122}
1123
1124/*
d063d709 1125 * Setup signal handler for :
1d4b027a 1126 * SIGINT, SIGTERM, SIGPIPE
fac6795d 1127 */
1d4b027a 1128static int set_signal_handler(void)
fac6795d 1129{
1d4b027a
DG
1130 int ret = 0;
1131 struct sigaction sa;
1132 sigset_t sigset;
fac6795d 1133
1d4b027a 1134 if ((ret = sigemptyset(&sigset)) < 0) {
76d7553f 1135 PERROR("sigemptyset");
1d4b027a
DG
1136 return ret;
1137 }
d6f42150 1138
1d4b027a
DG
1139 sa.sa_mask = sigset;
1140 sa.sa_flags = 0;
0072e5e2
MD
1141
1142 sa.sa_handler = sighandler;
1d4b027a 1143 if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) {
76d7553f 1144 PERROR("sigaction");
1d4b027a 1145 return ret;
d6f42150
DG
1146 }
1147
1d4b027a 1148 if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) {
76d7553f 1149 PERROR("sigaction");
1d4b027a 1150 return ret;
d6f42150 1151 }
aaf26714 1152
0072e5e2 1153 if ((ret = sigaction(SIGUSR1, &sa, NULL)) < 0) {
76d7553f 1154 PERROR("sigaction");
1d4b027a 1155 return ret;
8c0faa1d
DG
1156 }
1157
0072e5e2
MD
1158 sa.sa_handler = SIG_IGN;
1159 if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) {
0bb7724a
DG
1160 PERROR("sigaction");
1161 return ret;
1162 }
1163
1164 DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
1d4b027a
DG
1165
1166 return ret;
fac6795d
DG
1167}
1168
f3ed775e 1169/*
d063d709 1170 * Set open files limit to unlimited. This daemon can open a large number of
514bb9f0 1171 * file descriptors in order to consume multiple kernel traces.
f3ed775e
DG
1172 */
1173static void set_ulimit(void)
1174{
1175 int ret;
1176 struct rlimit lim;
1177
514bb9f0 1178 /* The kernel does not allow an infinite limit for open files */
f3ed775e
DG
1179 lim.rlim_cur = 65535;
1180 lim.rlim_max = 65535;
1181
1182 ret = setrlimit(RLIMIT_NOFILE, &lim);
1183 if (ret < 0) {
76d7553f 1184 PERROR("failed to set open files limit");
f3ed775e
DG
1185 }
1186}
1187
4a15001e 1188static int write_pidfile(void)
35f90c40 1189{
e6142f2e 1190 return utils_create_pid_file(getpid(), config.pid_file_path.value);
35f90c40
DG
1191}
1192
e6142f2e
JG
1193static int set_clock_plugin_env(void)
1194{
1195 int ret = 0;
1196 char *env_value = NULL;
cd9290dd 1197
e6142f2e
JG
1198 if (!config.lttng_ust_clock_plugin.value) {
1199 goto end;
1200 }
1201
1202 ret = asprintf(&env_value, "LTTNG_UST_CLOCK_PLUGIN=%s",
1203 config.lttng_ust_clock_plugin.value);
cd9290dd 1204 if (ret < 0) {
e6142f2e
JG
1205 PERROR("asprintf");
1206 goto end;
cd9290dd
DG
1207 }
1208
e6142f2e
JG
1209 ret = putenv(env_value);
1210 if (ret) {
1211 free(env_value);
1212 PERROR("putenv of LTTNG_UST_CLOCK_PLUGIN");
1213 goto end;
1214 }
cd9290dd 1215
e6142f2e
JG
1216 DBG("Updated LTTNG_UST_CLOCK_PLUGIN environment variable to \"%s\"",
1217 config.lttng_ust_clock_plugin.value);
1218end:
4a15001e 1219 return ret;
ef367a93
JG
1220}
1221
99d688f2
JG
1222static void destroy_all_sessions_and_wait(void)
1223{
1224 struct ltt_session *session, *tmp;
1225 struct ltt_session_list *session_list;
1226
1227 session_list = session_get_list();
1228 DBG("Initiating destruction of all sessions");
1229
1230 if (!session_list) {
1231 return;
1232 }
1233
99d688f2
JG
1234 session_lock_list();
1235 /* Initiate the destruction of all sessions. */
1236 cds_list_for_each_entry_safe(session, tmp,
1237 &session_list->head, list) {
1238 if (!session_get(session)) {
1239 continue;
1240 }
1241
1242 session_lock(session);
1243 if (session->destroyed) {
1244 goto unlock_session;
1245 }
63763958 1246 (void) cmd_stop_trace(session);
3e3665b8
JG
1247 (void) cmd_destroy_session(session, notification_thread_handle,
1248 NULL);
99d688f2
JG
1249 unlock_session:
1250 session_unlock(session);
1251 session_put(session);
1252 }
1253 session_unlock_list();
1254
1255 /* Wait for the destruction of all sessions to complete. */
1256 DBG("Waiting for the destruction of all sessions to complete");
1257 session_list_wait_empty();
1258 DBG("Destruction of all sessions completed");
1259}
1260
929f71ec
JG
1261static int run_as_worker_post_fork_cleanup(void *data)
1262{
1263 struct sessiond_config *sessiond_config = data;
1264
1265 sessiond_config_fini(sessiond_config);
1266 return 0;
1267}
1268
1269static int launch_run_as_worker(const char *procname)
1270{
1271 /*
1272 * Clean-up before forking the run-as worker. Any dynamically
1273 * allocated memory of which the worker is not aware will
1274 * be leaked as the process forks a run-as worker (and performs
1275 * no exec*()). The same would apply to any opened fd.
1276 */
1277 return run_as_create_worker(procname, run_as_worker_post_fork_cleanup,
1278 &config);
1279}
1280
52a0e931
JG
1281static void sessiond_uuid_log(void)
1282{
c70636a7 1283 char uuid_str[LTTNG_UUID_STR_LEN];
52a0e931
JG
1284
1285 lttng_uuid_to_str(sessiond_uuid, uuid_str);
1286 DBG("Starting lttng-sessiond {%s}", uuid_str);
1287}
1288
fac6795d
DG
1289/*
1290 * main
1291 */
1292int main(int argc, char **argv)
1293{
4a15001e 1294 int ret = 0, retval = 0;
e6142f2e 1295 const char *env_app_timeout;
b3530820
JG
1296 struct lttng_pipe *ust32_channel_monitor_pipe = NULL,
1297 *ust64_channel_monitor_pipe = NULL,
1298 *kernel_channel_monitor_pipe = NULL;
a3707772 1299 struct lttng_thread *ht_cleanup_thread = NULL;
bc26e826 1300 struct timer_thread_parameters timer_thread_parameters;
64d9b072
JG
1301 /* Rotation thread handle. */
1302 struct rotation_thread_handle *rotation_thread_handle = NULL;
d086f507
JD
1303 /* Queue of rotation jobs populated by the sessiond-timer. */
1304 struct rotation_thread_timer_queue *rotation_timer_queue = NULL;
917a718d 1305 struct lttng_thread *client_thread = NULL;
4a91420c 1306 struct lttng_thread *notification_thread = NULL;
bd9addf7 1307 struct lttng_thread *register_apps_thread = NULL;
fac6795d 1308
335a95b7
MD
1309 init_kernel_workarounds();
1310
f6a9efaa
DG
1311 rcu_register_thread();
1312
4a15001e
MD
1313 if (set_signal_handler()) {
1314 retval = -1;
1315 goto exit_set_signal_handler;
0bb7724a
DG
1316 }
1317
92816cc3 1318 if (timer_signal_init()) {
d086f507
JD
1319 retval = -1;
1320 goto exit_set_signal_handler;
1321 }
1322
12744796
DG
1323 page_size = sysconf(_SC_PAGESIZE);
1324 if (page_size < 0) {
1325 PERROR("sysconf _SC_PAGESIZE");
1326 page_size = LONG_MAX;
1327 WARN("Fallback page size to %ld", page_size);
1328 }
1329
e6142f2e
JG
1330 ret = sessiond_config_init(&config);
1331 if (ret) {
1332 retval = -1;
1333 goto exit_set_signal_handler;
1334 }
1335
2788b494
JR
1336 /*
1337 * Init config from environment variables.
1338 * Command line option override env configuration per-doc. Do env first.
1339 */
1340 sessiond_config_apply_env_config(&config);
1341
4a15001e
MD
1342 /*
1343 * Parse arguments and load the daemon configuration file.
1344 *
1345 * We have an exit_options exit path to free memory reserved by
1346 * set_options. This is needed because the rest of sessiond_cleanup()
1347 * depends on ht_cleanup_thread, which depends on lttng_daemonize, which
1348 * depends on set_options.
1349 */
fac6795d 1350 progname = argv[0];
4a15001e
MD
1351 if (set_options(argc, argv)) {
1352 retval = -1;
1353 goto exit_options;
fac6795d
DG
1354 }
1355
e6142f2e
JG
1356 /*
1357 * Resolve all paths received as arguments, configuration option, or
1358 * through environment variable as absolute paths. This is necessary
1359 * since daemonizing causes the sessiond's current working directory
1360 * to '/'.
1361 */
1362 ret = sessiond_config_resolve_paths(&config);
1363 if (ret) {
1364 goto exit_options;
1365 }
1366
1367 /* Apply config. */
1368 lttng_opt_verbose = config.verbose;
1369 lttng_opt_quiet = config.quiet;
1370 kconsumer_data.err_unix_sock_path =
1371 config.kconsumerd_err_unix_sock_path.value;
1372 kconsumer_data.cmd_unix_sock_path =
1373 config.kconsumerd_cmd_unix_sock_path.value;
1374 ustconsumer32_data.err_unix_sock_path =
1375 config.consumerd32_err_unix_sock_path.value;
1376 ustconsumer32_data.cmd_unix_sock_path =
1377 config.consumerd32_cmd_unix_sock_path.value;
1378 ustconsumer64_data.err_unix_sock_path =
1379 config.consumerd64_err_unix_sock_path.value;
1380 ustconsumer64_data.cmd_unix_sock_path =
1381 config.consumerd64_cmd_unix_sock_path.value;
1382 set_clock_plugin_env();
1383
1384 sessiond_config_log(&config);
52a0e931 1385 sessiond_uuid_log();
e6142f2e 1386
a3bc3918
JR
1387 if (opt_print_version) {
1388 print_version();
1389 retval = 0;
1390 goto exit_options;
1391 }
1392
f472090a
JG
1393 if (create_lttng_rundir()) {
1394 retval = -1;
1395 goto exit_options;
1396 }
1397
1398 /* Abort launch if a session daemon is already running. */
1399 if (check_existing_daemon()) {
1400 ERR("A session daemon is already running.");
1401 retval = -1;
1402 goto exit_options;
1403 }
1404
fac6795d 1405 /* Daemonize */
e6142f2e 1406 if (config.daemonize || config.background) {
ceed52b5
MD
1407 int i;
1408
72dd7491 1409 ret = lttng_daemonize(&child_ppid, &recv_child_signal,
e6142f2e 1410 !config.background);
53094c05 1411 if (ret < 0) {
4a15001e
MD
1412 retval = -1;
1413 goto exit_options;
53094c05 1414 }
0bb7724a 1415
ceed52b5 1416 /*
0bb7724a 1417 * We are in the child. Make sure all other file descriptors are
4a15001e 1418 * closed, in case we are called with more opened file
f472090a 1419 * descriptors than the standard ones and the lock file.
ceed52b5
MD
1420 */
1421 for (i = 3; i < sysconf(_SC_OPEN_MAX); i++) {
f472090a
JG
1422 if (i == lockfile_fd) {
1423 continue;
1424 }
ceed52b5
MD
1425 (void) close(i);
1426 }
1427 }
1428
929f71ec 1429 if (launch_run_as_worker(argv[0]) < 0) {
7567352f
MD
1430 goto exit_create_run_as_worker_cleanup;
1431 }
1432
4a15001e
MD
1433 /*
1434 * Starting from here, we can create threads. This needs to be after
1435 * lttng_daemonize due to RCU.
1436 */
1437
1438 /*
1439 * Initialize the health check subsystem. This call should set the
1440 * appropriate time values.
1441 */
1442 health_sessiond = health_app_create(NR_HEALTH_SESSIOND_TYPES);
1443 if (!health_sessiond) {
1444 PERROR("health_app_create error");
1445 retval = -1;
0d64e8fb 1446 goto stop_threads;
4a15001e
MD
1447 }
1448
4a15001e 1449 /* Create thread to clean up RCU hash tables */
a3707772
JG
1450 ht_cleanup_thread = launch_ht_cleanup_thread();
1451 if (!ht_cleanup_thread) {
4a15001e 1452 retval = -1;
0d64e8fb 1453 goto stop_threads;
4a15001e
MD
1454 }
1455
ceed52b5 1456 /* Create thread quit pipe */
a7333da7 1457 if (sessiond_init_thread_quit_pipe()) {
4a15001e 1458 retval = -1;
0d64e8fb 1459 goto stop_threads;
fac6795d
DG
1460 }
1461
1462 /* Check if daemon is UID = 0 */
1463 is_root = !getuid();
fac6795d 1464 if (is_root) {
67e40797 1465 /* Create global run dir with root access */
67e40797 1466
b3530820
JG
1467 kernel_channel_monitor_pipe = lttng_pipe_open(0);
1468 if (!kernel_channel_monitor_pipe) {
1469 ERR("Failed to create kernel consumer channel monitor pipe");
1470 retval = -1;
0d64e8fb 1471 goto stop_threads;
b3530820
JG
1472 }
1473 kconsumer_data.channel_monitor_pipe =
1474 lttng_pipe_release_writefd(
1475 kernel_channel_monitor_pipe);
1476 if (kconsumer_data.channel_monitor_pipe < 0) {
1477 retval = -1;
0d64e8fb 1478 goto stop_threads;
b3530820 1479 }
fac6795d
DG
1480 }
1481
5c827ce0
DG
1482 /* Set consumer initial state */
1483 kernel_consumerd_state = CONSUMER_STOPPED;
1484 ust_consumerd_state = CONSUMER_STOPPED;
1485
b3530820
JG
1486 ust32_channel_monitor_pipe = lttng_pipe_open(0);
1487 if (!ust32_channel_monitor_pipe) {
1488 ERR("Failed to create 32-bit user space consumer channel monitor pipe");
1489 retval = -1;
0d64e8fb 1490 goto stop_threads;
b3530820
JG
1491 }
1492 ustconsumer32_data.channel_monitor_pipe = lttng_pipe_release_writefd(
1493 ust32_channel_monitor_pipe);
1494 if (ustconsumer32_data.channel_monitor_pipe < 0) {
1495 retval = -1;
0d64e8fb 1496 goto stop_threads;
b3530820 1497 }
62c43103 1498
d086f507 1499 /*
92816cc3
JG
1500 * The rotation_thread_timer_queue structure is shared between the
1501 * sessiond timer thread and the rotation thread. The main thread keeps
1502 * its ownership and destroys it when both threads have been joined.
d086f507 1503 */
92816cc3 1504 rotation_timer_queue = rotation_thread_timer_queue_create();
d086f507
JD
1505 if (!rotation_timer_queue) {
1506 retval = -1;
0d64e8fb 1507 goto stop_threads;
d086f507 1508 }
bc26e826
JG
1509 timer_thread_parameters.rotation_thread_job_queue =
1510 rotation_timer_queue;
67e40797 1511
b3530820
JG
1512 ust64_channel_monitor_pipe = lttng_pipe_open(0);
1513 if (!ust64_channel_monitor_pipe) {
1514 ERR("Failed to create 64-bit user space consumer channel monitor pipe");
1515 retval = -1;
0d64e8fb 1516 goto stop_threads;
b3530820
JG
1517 }
1518 ustconsumer64_data.channel_monitor_pipe = lttng_pipe_release_writefd(
1519 ust64_channel_monitor_pipe);
1520 if (ustconsumer64_data.channel_monitor_pipe < 0) {
1521 retval = -1;
0d64e8fb 1522 goto stop_threads;
b3530820 1523 }
847177cd 1524
1427f9b2
DG
1525 /*
1526 * Init UST app hash table. Alloc hash table before this point since
1527 * cleanup() can get called after that point.
1528 */
4a15001e 1529 if (ust_app_ht_alloc()) {
ddbeb0f6 1530 ERR("Failed to allocate UST app hash table");
4a15001e 1531 retval = -1;
0d64e8fb 1532 goto stop_threads;
4a15001e 1533 }
1427f9b2 1534
6a4e4039
JG
1535 /*
1536 * Initialize agent app hash table. We allocate the hash table here
1537 * since cleanup() can get called after this point.
1538 */
1539 if (agent_app_ht_alloc()) {
1540 ERR("Failed to allocate Agent app hash table");
4a15001e 1541 retval = -1;
0d64e8fb 1542 goto stop_threads;
f20baf8e
DG
1543 }
1544
a88df331
DG
1545 /*
1546 * These actions must be executed as root. We do that *after* setting up
1547 * the sockets path because we MUST make the check for another daemon using
1548 * those paths *before* trying to set the kernel consumer sockets and init
1549 * kernel tracer.
1550 */
1551 if (is_root) {
e6142f2e 1552 if (set_consumer_sockets(&kconsumer_data)) {
4a15001e 1553 retval = -1;
0d64e8fb 1554 goto stop_threads;
7753dea8
MD
1555 }
1556
a88df331 1557 /* Setup kernel tracer */
e6142f2e 1558 if (!config.no_kernel) {
4fba7219
DG
1559 init_kernel_tracer();
1560 }
a88df331
DG
1561
1562 /* Set ulimit for open files */
1563 set_ulimit();
fac6795d 1564 }
4063050c
MD
1565 /* init lttng_fd tracking must be done after set_ulimit. */
1566 lttng_fd_init();
fac6795d 1567
e6142f2e 1568 if (set_consumer_sockets(&ustconsumer64_data)) {
4a15001e 1569 retval = -1;
0d64e8fb 1570 goto stop_threads;
67e40797
DG
1571 }
1572
e6142f2e 1573 if (set_consumer_sockets(&ustconsumer32_data)) {
4a15001e 1574 retval = -1;
0d64e8fb 1575 goto stop_threads;
67e40797
DG
1576 }
1577
5b8719f5 1578 /* Get parent pid if -S, --sig-parent is specified. */
e6142f2e 1579 if (config.sig_parent) {
5b8719f5
DG
1580 ppid = getppid();
1581 }
1582
7a485870 1583 /* Setup the kernel pipe for waking up the kernel thread */
e6142f2e 1584 if (is_root && !config.no_kernel) {
4a15001e
MD
1585 if (utils_create_pipe_cloexec(kernel_poll_pipe)) {
1586 retval = -1;
0d64e8fb 1587 goto stop_threads;
6620da75 1588 }
7a485870
DG
1589 }
1590
099e26bd 1591 /* Setup the thread apps communication pipe. */
4a15001e
MD
1592 if (utils_create_pipe_cloexec(apps_cmd_pipe)) {
1593 retval = -1;
0d64e8fb 1594 goto stop_threads;
099e26bd
DG
1595 }
1596
d0b96690 1597 /* Setup the thread apps notify communication pipe. */
4a15001e
MD
1598 if (utils_create_pipe_cloexec(apps_cmd_notify_pipe)) {
1599 retval = -1;
0d64e8fb 1600 goto stop_threads;
d0b96690
DG
1601 }
1602
7972aab2
DG
1603 /* Initialize global buffer per UID and PID registry. */
1604 buffer_reg_init_uid_registry();
1605 buffer_reg_init_pid_registry();
1606
099e26bd 1607 /* Init UST command queue. */
8bdee6e2 1608 cds_wfcq_init(&ust_cmd_queue.head, &ust_cmd_queue.tail);
099e26bd 1609
2f77fc4b 1610 cmd_init();
00e2e675 1611
ae9e45b3
DG
1612 /* Check for the application socket timeout env variable. */
1613 env_app_timeout = getenv(DEFAULT_APP_SOCKET_TIMEOUT_ENV);
1614 if (env_app_timeout) {
e6142f2e 1615 config.app_socket_timeout = atoi(env_app_timeout);
ae9e45b3 1616 } else {
e6142f2e 1617 config.app_socket_timeout = DEFAULT_APP_SOCKET_RW_TIMEOUT;
ae9e45b3
DG
1618 }
1619
4a15001e
MD
1620 ret = write_pidfile();
1621 if (ret) {
1622 ERR("Error in write_pidfile");
1623 retval = -1;
0d64e8fb 1624 goto stop_threads;
4a15001e 1625 }
35f90c40 1626
554831e7
MD
1627 /* Initialize communication library */
1628 lttcomm_init();
4a15001e 1629 /* Initialize TCP timeout values */
d831c249 1630 lttcomm_inet_init();
554831e7 1631
12b4fb37 1632 /* Create health-check thread. */
173fca4f 1633 if (!launch_health_management_thread()) {
4a15001e 1634 retval = -1;
0d64e8fb 1635 goto stop_threads;
44a5e5eb
DG
1636 }
1637
b3530820
JG
1638 /* notification_thread_data acquires the pipes' read side. */
1639 notification_thread_handle = notification_thread_handle_create(
1640 ust32_channel_monitor_pipe,
1641 ust64_channel_monitor_pipe,
c8a9de5a 1642 kernel_channel_monitor_pipe);
b3530820
JG
1643 if (!notification_thread_handle) {
1644 retval = -1;
1645 ERR("Failed to create notification thread shared data");
0d64e8fb 1646 goto stop_threads;
b3530820
JG
1647 }
1648
1649 /* Create notification thread. */
4a91420c
JG
1650 notification_thread = launch_notification_thread(
1651 notification_thread_handle);
1652 if (!notification_thread) {
b3530820 1653 retval = -1;
0d64e8fb 1654 goto stop_threads;
b3530820
JG
1655 }
1656
d086f507 1657 /* Create timer thread. */
bc26e826 1658 if (!launch_timer_thread(&timer_thread_parameters)) {
d086f507 1659 retval = -1;
0d64e8fb 1660 goto stop_threads;
d086f507 1661 }
d086f507 1662
db66e574
JD
1663 /* rotation_thread_data acquires the pipes' read side. */
1664 rotation_thread_handle = rotation_thread_handle_create(
90936dcf 1665 rotation_timer_queue,
c8a9de5a 1666 notification_thread_handle);
db66e574
JD
1667 if (!rotation_thread_handle) {
1668 retval = -1;
1669 ERR("Failed to create rotation thread shared data");
1670 stop_threads();
0d64e8fb 1671 goto stop_threads;
db66e574 1672 }
db66e574
JD
1673
1674 /* Create rotation thread. */
64d9b072 1675 if (!launch_rotation_thread(rotation_thread_handle)) {
db66e574 1676 retval = -1;
0d64e8fb 1677 goto stop_threads;
db66e574
JD
1678 }
1679
cf3af59e 1680 /* Create thread to manage the client socket */
917a718d
JG
1681 client_thread = launch_client_thread();
1682 if (!client_thread) {
4a15001e 1683 retval = -1;
0d64e8fb 1684 goto stop_threads;
cf3af59e 1685 }
fac6795d 1686
308df7bb
JG
1687 /* Set credentials of the client socket and rundir */
1688 if (is_root && set_permissions(config.rundir.value)) {
1689 retval = -1;
1690 goto stop_threads;
1691 }
1692
5d1b0219
JG
1693 if (!launch_ust_dispatch_thread(&ust_cmd_queue, apps_cmd_pipe[1],
1694 apps_cmd_notify_pipe[1])) {
4a15001e 1695 retval = -1;
0d64e8fb 1696 goto stop_threads;
099e26bd
DG
1697 }
1698
1699 /* Create thread to manage application registration. */
bd9addf7
JG
1700 register_apps_thread = launch_application_registration_thread(
1701 &ust_cmd_queue);
1702 if (!register_apps_thread) {
4a15001e 1703 retval = -1;
0d64e8fb 1704 goto stop_threads;
099e26bd
DG
1705 }
1706
cf3af59e 1707 /* Create thread to manage application socket */
7649924e 1708 if (!launch_application_management_thread(apps_cmd_pipe[0])) {
4a15001e 1709 retval = -1;
0d64e8fb 1710 goto stop_threads;
d0b96690
DG
1711 }
1712
1713 /* Create thread to manage application notify socket */
971a61c6 1714 if (!launch_application_notification_thread(apps_cmd_notify_pipe[0])) {
4a15001e 1715 retval = -1;
0d64e8fb 1716 goto stop_threads;
cf3af59e 1717 }
fac6795d 1718
8a7e4590
JG
1719 /* Create agent management thread. */
1720 if (!launch_agent_management_thread()) {
4a15001e 1721 retval = -1;
0d64e8fb 1722 goto stop_threads;
4d076222
DG
1723 }
1724
6620da75 1725 /* Don't start this thread if kernel tracing is not requested nor root */
e6142f2e 1726 if (is_root && !config.no_kernel) {
6620da75 1727 /* Create kernel thread to manage kernel event */
5b093681 1728 if (!launch_kernel_management_thread(kernel_poll_pipe[0])) {
4a15001e 1729 retval = -1;
0d64e8fb 1730 goto stop_threads;
6620da75 1731 }
ef367a93 1732 }
7a485870 1733
3316b9d6
JG
1734 /* Load sessions. */
1735 ret = config_load_session(config.load_session_path.value,
1736 NULL, 1, 1, NULL);
4a15001e 1737 if (ret) {
3316b9d6 1738 ERR("Session load failed: %s", error_get_str(ret));
4a15001e 1739 retval = -1;
0d64e8fb 1740 goto stop_threads;
4a15001e
MD
1741 }
1742
3316b9d6
JG
1743 /* Initialization completed. */
1744 sessiond_signal_parents();
1745
4a15001e
MD
1746 /*
1747 * This is where we start awaiting program completion (e.g. through
1748 * signal that asks threads to teardown).
1749 */
1750
99d688f2 1751 /* Initiate teardown once activity occurs on the quit pipe. */
2d54bfb6 1752 sessiond_wait_for_quit_pipe(-1);
917a718d 1753
0d64e8fb 1754stop_threads:
917a718d
JG
1755 /*
1756 * Ensure that the client thread is no longer accepting new commands,
1757 * which could cause new sessions to be created.
1758 */
0d64e8fb
JG
1759 if (client_thread) {
1760 lttng_thread_shutdown(client_thread);
917a718d 1761 lttng_thread_put(client_thread);
917a718d
JG
1762 }
1763
99d688f2 1764 destroy_all_sessions_and_wait();
0d64e8fb 1765
bd9addf7
JG
1766 if (register_apps_thread) {
1767 lttng_thread_shutdown(register_apps_thread);
1768 lttng_thread_put(register_apps_thread);
1769 }
a3707772 1770 lttng_thread_list_shutdown_orphans();
917a718d 1771
4d62fbf8
MD
1772 /*
1773 * Wait for all pending call_rcu work to complete before tearing
1774 * down data structures. call_rcu worker may be trying to
1775 * perform lookups in those structures.
1776 */
1777 rcu_barrier();
4a15001e
MD
1778 /*
1779 * sessiond_cleanup() is called when no other thread is running, except
1780 * the ht_cleanup thread, which is needed to destroy the hash tables.
1781 */
1782 rcu_thread_online();
1783 sessiond_cleanup();
06f525de 1784
4a91420c
JG
1785 if (notification_thread) {
1786 lttng_thread_shutdown(notification_thread);
1787 lttng_thread_put(notification_thread);
1788 }
1789
c4d5de9d
JG
1790 /*
1791 * Ensure all prior call_rcu are done. call_rcu callbacks may push
1792 * hash tables to the ht_cleanup thread. Therefore, we ensure that
1793 * the queue is empty before shutting down the clean-up thread.
1794 */
1795 rcu_barrier();
1796
a3707772
JG
1797 if (ht_cleanup_thread) {
1798 lttng_thread_shutdown(ht_cleanup_thread);
1799 lttng_thread_put(ht_cleanup_thread);
1800 }
1801
64d9b072
JG
1802 rcu_thread_offline();
1803 rcu_unregister_thread();
1804
1805 if (rotation_thread_handle) {
1806 rotation_thread_handle_destroy(rotation_thread_handle);
1807 }
1808
d086f507
JD
1809 /*
1810 * After the rotation and timer thread have quit, we can safely destroy
1811 * the rotation_timer_queue.
1812 */
92816cc3 1813 rotation_thread_timer_queue_destroy(rotation_timer_queue);
c8a9de5a
JG
1814 /*
1815 * The teardown of the notification system is performed after the
1816 * session daemon's teardown in order to allow it to be notified
1817 * of the active session and channels at the moment of the teardown.
1818 */
1819 if (notification_thread_handle) {
1820 notification_thread_handle_destroy(notification_thread_handle);
1821 }
b3530820
JG
1822 lttng_pipe_destroy(ust32_channel_monitor_pipe);
1823 lttng_pipe_destroy(ust64_channel_monitor_pipe);
1824 lttng_pipe_destroy(kernel_channel_monitor_pipe);
4a15001e 1825
9bc2ec5f
JR
1826 if (health_sessiond) {
1827 health_app_destroy(health_sessiond);
1828 }
7567352f 1829exit_create_run_as_worker_cleanup:
4a15001e 1830exit_options:
f472090a 1831 sessiond_cleanup_lock_file();
4a15001e
MD
1832 sessiond_cleanup_options();
1833
1834exit_set_signal_handler:
1835 if (!retval) {
cf3af59e 1836 exit(EXIT_SUCCESS);
4a15001e
MD
1837 } else {
1838 exit(EXIT_FAILURE);
67e40797 1839 }
fac6795d 1840}
This page took 0.362638 seconds and 4 git commands to generate.