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