Fix: sessiond: leak of config_path on duplicate --config option
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
CommitLineData
826d496d
MD
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
0fdd1e2c 3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
26296c48 4 * 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
fac6795d 5 *
d14d33bf
AM
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2 only,
8 * as published by the Free Software Foundation.
91d76f53 9 *
d14d33bf
AM
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
91d76f53 14 *
d14d33bf
AM
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
fac6795d
DG
18 */
19
6c1c0768 20#define _LGPL_SOURCE
fac6795d
DG
21#include <getopt.h>
22#include <grp.h>
23#include <limits.h>
0bb7724a 24#include <paths.h>
fac6795d
DG
25#include <pthread.h>
26#include <signal.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
331744e3 30#include <inttypes.h>
0fdd1e2c 31#include <sys/mman.h>
b73401da 32#include <sys/mount.h>
1e307fab 33#include <sys/resource.h>
fac6795d
DG
34#include <sys/socket.h>
35#include <sys/stat.h>
36#include <sys/types.h>
0fdd1e2c 37#include <sys/wait.h>
5c827ce0 38#include <urcu/uatomic.h>
fac6795d 39#include <unistd.h>
4f0b90ee 40#include <ctype.h>
fac6795d 41
990570ed 42#include <common/common.h>
d27c42b8 43#include <common/compat/socket.h>
e8fa9fb0 44#include <common/compat/getenv.h>
db758600
DG
45#include <common/defaults.h>
46#include <common/kernel-consumer/kernel-consumer.h>
50c8f484 47#include <common/futex.h>
00e2e675 48#include <common/relayd/relayd.h>
81b86775 49#include <common/utils.h>
3ccdf997 50#include <common/daemonize.h>
f40ef1d5 51#include <common/config/session-config.h>
dcabc190 52#include <common/dynamic-buffer.h>
76fcf151 53#include <lttng/event-internal.h>
fac6795d 54
10a8a223 55#include "lttng-sessiond.h"
7972aab2 56#include "buffer-registry.h"
54d01ffb 57#include "channel.h"
2f77fc4b 58#include "cmd.h"
00e2e675 59#include "consumer.h"
099e26bd 60#include "context.h"
54d01ffb 61#include "event.h"
4771f025 62#include "kernel.h"
f1e16794 63#include "kernel-consumer.h"
0fdd1e2c 64#include "shm.h"
b7340b1d 65#include "lttng-ust-ctl.h"
00e2e675 66#include "ust-consumer.h"
8e68d1c8 67#include "utils.h"
4063050c 68#include "fd-limit.h"
8782cc74 69#include "health-sessiond.h"
8ac94142 70#include "testpoint.h"
4ac33400 71#include "notify-apps.h"
022d91ba 72#include "agent-thread.h"
fb198a11 73#include "save.h"
b3530820
JG
74#include "notification-thread.h"
75#include "notification-thread-commands.h"
db66e574 76#include "rotation-thread.h"
7c1d2758 77#include "agent.h"
5e97de00 78#include "ht-cleanup.h"
e6142f2e 79#include "sessiond-config.h"
432b38d7 80#include "timer.h"
548468b9 81#include "thread.h"
050e613c 82#include "client.h"
dd5875e7 83#include "dispatch.h"
22b80785 84#include "register.h"
cdffb210 85#include "manage-apps.h"
45f6525f 86#include "manage-kernel.h"
ebaeda94 87
4fc83d94
PP
88static const char *help_msg =
89#ifdef LTTNG_EMBED_HELP
90#include <lttng-sessiond.8.h>
91#else
92NULL
93#endif
94;
95
fac6795d 96const char *progname;
c9cb3e7d 97static int lockfile_fd = -1;
3bd1e081 98
0bb7724a
DG
99/* Set to 1 when a SIGUSR1 signal is received. */
100static int recv_child_signal;
101
26296c48
JG
102/* Command line options */
103static const struct option long_options[] = {
0f5ea17c
JG
104 { "client-sock", required_argument, 0, 'c' },
105 { "apps-sock", required_argument, 0, 'a' },
106 { "kconsumerd-cmd-sock", required_argument, 0, '\0' },
107 { "kconsumerd-err-sock", required_argument, 0, '\0' },
108 { "ustconsumerd32-cmd-sock", required_argument, 0, '\0' },
109 { "ustconsumerd32-err-sock", required_argument, 0, '\0' },
110 { "ustconsumerd64-cmd-sock", required_argument, 0, '\0' },
111 { "ustconsumerd64-err-sock", required_argument, 0, '\0' },
112 { "consumerd32-path", required_argument, 0, '\0' },
113 { "consumerd32-libdir", required_argument, 0, '\0' },
114 { "consumerd64-path", required_argument, 0, '\0' },
115 { "consumerd64-libdir", required_argument, 0, '\0' },
116 { "daemonize", no_argument, 0, 'd' },
117 { "background", no_argument, 0, 'b' },
118 { "sig-parent", no_argument, 0, 'S' },
119 { "help", no_argument, 0, 'h' },
120 { "group", required_argument, 0, 'g' },
121 { "version", no_argument, 0, 'V' },
122 { "quiet", no_argument, 0, 'q' },
123 { "verbose", no_argument, 0, 'v' },
124 { "verbose-consumer", no_argument, 0, '\0' },
125 { "no-kernel", no_argument, 0, '\0' },
126 { "pidfile", required_argument, 0, 'p' },
127 { "agent-tcp-port", required_argument, 0, '\0' },
128 { "config", required_argument, 0, 'f' },
129 { "load", required_argument, 0, 'l' },
130 { "kmod-probes", required_argument, 0, '\0' },
131 { "extra-kmod-probes", required_argument, 0, '\0' },
26296c48
JG
132 { NULL, 0, 0, 0 }
133};
134
135/* Command line options to ignore from configuration file */
136static const char *config_ignore_options[] = { "help", "version", "config" };
1d4b027a 137
099e26bd
DG
138/*
139 * This pipe is used to inform the thread managing application communication
140 * that a command is queued and ready to be processed.
141 */
76d7553f 142static int apps_cmd_pipe[2] = { -1, -1 };
53c51aaa 143static int apps_cmd_notify_pipe[2] = { -1, -1 };
099e26bd 144
099e26bd
DG
145/*
146 * UST registration command queue. This queue is tied with a futex and uses a N
147 * wakers / 1 waiter implemented and detailed in futex.c/.h
148 *
b22c5da8
DG
149 * The thread_registration_apps and thread_dispatch_ust_registration uses this
150 * queue along with the wait/wake scheme. The thread_manage_apps receives down
151 * the line new application socket and monitors it for any I/O error or clean
152 * close that triggers an unregistration of the application.
099e26bd
DG
153 */
154static struct ust_cmd_queue ust_cmd_queue;
155
97bc1426 156/*
51bb4dbb 157 * Section name to look for in the daemon configuration file.
97bc1426 158 */
51bb4dbb 159static const char * const config_section_name = "sessiond";
5e97de00 160
51bb4dbb
JG
161/* Am I root or not. Set to 1 if the daemon is running as root */
162static int is_root;
5eb91c98 163
099e26bd
DG
164/*
165 * Stop all threads by closing the thread quit pipe.
166 */
cf3af59e
MD
167static void stop_threads(void)
168{
5eb91c98
DG
169 int ret;
170
cf3af59e
MD
171 /* Stopping all threads */
172 DBG("Terminating all threads");
51bb4dbb 173 ret = sessiond_notify_quit_pipe();
5eb91c98
DG
174 if (ret < 0) {
175 ERR("write error on thread quit pipe");
176 }
cf3af59e
MD
177}
178
e975f9f8
DG
179/*
180 * Close every consumer sockets.
181 */
182static void close_consumer_sockets(void)
183{
184 int ret;
185
186 if (kconsumer_data.err_sock >= 0) {
187 ret = close(kconsumer_data.err_sock);
188 if (ret < 0) {
189 PERROR("kernel consumer err_sock close");
190 }
191 }
192 if (ustconsumer32_data.err_sock >= 0) {
193 ret = close(ustconsumer32_data.err_sock);
194 if (ret < 0) {
a76cbd9f 195 PERROR("UST consumerd32 err_sock close");
e975f9f8
DG
196 }
197 }
198 if (ustconsumer64_data.err_sock >= 0) {
199 ret = close(ustconsumer64_data.err_sock);
200 if (ret < 0) {
a76cbd9f 201 PERROR("UST consumerd64 err_sock close");
e975f9f8
DG
202 }
203 }
204 if (kconsumer_data.cmd_sock >= 0) {
205 ret = close(kconsumer_data.cmd_sock);
206 if (ret < 0) {
207 PERROR("kernel consumer cmd_sock close");
208 }
209 }
210 if (ustconsumer32_data.cmd_sock >= 0) {
211 ret = close(ustconsumer32_data.cmd_sock);
212 if (ret < 0) {
a76cbd9f 213 PERROR("UST consumerd32 cmd_sock close");
e975f9f8
DG
214 }
215 }
216 if (ustconsumer64_data.cmd_sock >= 0) {
217 ret = close(ustconsumer64_data.cmd_sock);
218 if (ret < 0) {
a76cbd9f 219 PERROR("UST consumerd64 cmd_sock close");
e975f9f8
DG
220 }
221 }
b3530820
JG
222 if (kconsumer_data.channel_monitor_pipe >= 0) {
223 ret = close(kconsumer_data.channel_monitor_pipe);
224 if (ret < 0) {
225 PERROR("kernel consumer channel monitor pipe close");
226 }
227 }
228 if (ustconsumer32_data.channel_monitor_pipe >= 0) {
229 ret = close(ustconsumer32_data.channel_monitor_pipe);
230 if (ret < 0) {
231 PERROR("UST consumerd32 channel monitor pipe close");
232 }
233 }
234 if (ustconsumer64_data.channel_monitor_pipe >= 0) {
235 ret = close(ustconsumer64_data.channel_monitor_pipe);
236 if (ret < 0) {
237 PERROR("UST consumerd64 channel monitor pipe close");
238 }
239 }
e975f9f8
DG
240}
241
4e4714cb
JR
242/*
243 * Wait on consumer process termination.
244 *
245 * Need to be called with the consumer data lock held or from a context
246 * ensuring no concurrent access to data (e.g: cleanup).
247 */
248static void wait_consumer(struct consumer_data *consumer_data)
249{
250 pid_t ret;
251 int status;
252
253 if (consumer_data->pid <= 0) {
254 return;
255 }
256
257 DBG("Waiting for complete teardown of consumerd (PID: %d)",
258 consumer_data->pid);
259 ret = waitpid(consumer_data->pid, &status, 0);
260 if (ret == -1) {
261 PERROR("consumerd waitpid pid: %d", consumer_data->pid)
1640c24c 262 } else if (!WIFEXITED(status)) {
4e4714cb
JR
263 ERR("consumerd termination with error: %d",
264 WEXITSTATUS(ret));
265 }
266 consumer_data->pid = 0;
267}
268
fac6795d 269/*
4a15001e 270 * Cleanup the session daemon's data structures.
fac6795d 271 */
4a15001e 272static void sessiond_cleanup(void)
fac6795d 273{
ef599319 274 int ret;
48a86f68 275 struct ltt_session_list *session_list = session_get_list();
fac6795d 276
4a15001e 277 DBG("Cleanup sessiond");
e07ae692 278
4e449f3f
MD
279 /*
280 * Close the thread quit pipe. It has already done its job,
281 * since we are now called.
282 */
51bb4dbb 283 sessiond_close_quit_pipe();
53c51aaa
JG
284 utils_close_pipe(apps_cmd_pipe);
285 utils_close_pipe(apps_cmd_notify_pipe);
45f6525f 286 utils_close_pipe(kernel_poll_pipe);
2f77fc4b 287
c9a2957d
JG
288 ret = remove(config.pid_file_path.value);
289 if (ret < 0) {
290 PERROR("remove pidfile %s", config.pid_file_path.value);
35f90c40
DG
291 }
292
e6142f2e
JG
293 DBG("Removing sessiond and consumerd content of directory %s",
294 config.rundir.value);
8c6c56c2
MD
295
296 /* sessiond */
e6142f2e
JG
297 DBG("Removing %s", config.pid_file_path.value);
298 (void) unlink(config.pid_file_path.value);
8c6c56c2 299
e6142f2e
JG
300 DBG("Removing %s", config.agent_port_file_path.value);
301 (void) unlink(config.agent_port_file_path.value);
cd9290dd 302
8c6c56c2 303 /* kconsumerd */
e6142f2e
JG
304 DBG("Removing %s", kconsumer_data.err_unix_sock_path);
305 (void) unlink(kconsumer_data.err_unix_sock_path);
306
307 DBG("Removing directory %s", config.kconsumerd_path.value);
308 (void) rmdir(config.kconsumerd_path.value);
8c6c56c2
MD
309
310 /* ust consumerd 32 */
e6142f2e
JG
311 DBG("Removing %s", config.consumerd32_err_unix_sock_path.value);
312 (void) unlink(config.consumerd32_err_unix_sock_path.value);
313
314 DBG("Removing directory %s", config.consumerd32_path.value);
315 (void) rmdir(config.consumerd32_path.value);
8c6c56c2
MD
316
317 /* ust consumerd 64 */
e6142f2e
JG
318 DBG("Removing %s", config.consumerd64_err_unix_sock_path.value);
319 (void) unlink(config.consumerd64_err_unix_sock_path.value);
320
321 DBG("Removing directory %s", config.consumerd64_path.value);
322 (void) rmdir(config.consumerd64_path.value);
5461b305 323
6af972a2 324 pthread_mutex_destroy(&session_list->lock);
273ea72c 325
6a4e4039
JG
326 DBG("Cleaning up all agent apps");
327 agent_app_ht_clean();
099e26bd 328 DBG("Closing all UST sockets");
56fff090 329 ust_app_clean_list();
7972aab2 330 buffer_reg_destroy_registries();
099e26bd 331
caf7f341
MD
332 close_consumer_sockets();
333
334 wait_consumer(&kconsumer_data);
335 wait_consumer(&ustconsumer64_data);
336 wait_consumer(&ustconsumer32_data);
337
e6142f2e 338 if (is_root && !config.no_kernel) {
32e10baa 339 cleanup_kernel_tracer();
2f50c8a3 340 }
2f77fc4b 341
c9cb3e7d
JG
342 /*
343 * We do NOT rmdir rundir because there are other processes
344 * using it, for instance lttng-relayd, which can start in
345 * parallel with this teardown.
346 */
4a15001e
MD
347}
348
349/*
350 * Cleanup the daemon's option data structures.
351 */
352static void sessiond_cleanup_options(void)
353{
354 DBG("Cleaning up options");
355
e6142f2e 356 sessiond_config_fini(&config);
c9cb3e7d 357
7567352f 358 run_as_destroy_worker();
fac6795d
DG
359}
360
050e613c 361static int string_match(const char *str1, const char *str2)
54d01ffb 362{
050e613c 363 return (str1 && str2) && !strcmp(str1, str2);
54d01ffb
DG
364}
365
00e2e675 366/*
050e613c
JG
367 * Take an option from the getopt output and set it in the right variable to be
368 * used later.
36b588ed 369 *
050e613c 370 * Return 0 on success else a negative value.
00e2e675 371 */
050e613c 372static int set_option(int opt, const char *arg, const char *optname)
00e2e675 373{
050e613c 374 int ret = 0;
fac6795d 375
c0232ea5 376 if (string_match(optname, "client-sock") || opt == 'c') {
66b2ce8e
JG
377 if (!arg || *arg == '\0') {
378 ret = -EINVAL;
379 goto end;
380 }
e8fa9fb0
MD
381 if (lttng_is_setuid_setgid()) {
382 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
383 "-c, --client-sock");
384 } else {
e6142f2e
JG
385 config_string_set(&config.client_unix_sock_path,
386 strdup(arg));
387 if (!config.client_unix_sock_path.value) {
388 ret = -ENOMEM;
389 PERROR("strdup");
390 }
e8fa9fb0 391 }
c0232ea5 392 } else if (string_match(optname, "apps-sock") || opt == 'a') {
66b2ce8e
JG
393 if (!arg || *arg == '\0') {
394 ret = -EINVAL;
395 goto end;
396 }
e8fa9fb0
MD
397 if (lttng_is_setuid_setgid()) {
398 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
399 "-a, --apps-sock");
400 } else {
e6142f2e
JG
401 config_string_set(&config.apps_unix_sock_path,
402 strdup(arg));
403 if (!config.apps_unix_sock_path.value) {
404 ret = -ENOMEM;
405 PERROR("strdup");
406 }
e8fa9fb0 407 }
c0232ea5 408 } else if (string_match(optname, "daemonize") || opt == 'd') {
e6142f2e 409 config.daemonize = true;
c0232ea5 410 } else if (string_match(optname, "background") || opt == 'b') {
e6142f2e 411 config.background = true;
c0232ea5 412 } else if (string_match(optname, "group") || opt == 'g') {
66b2ce8e
JG
413 if (!arg || *arg == '\0') {
414 ret = -EINVAL;
415 goto end;
416 }
e8fa9fb0
MD
417 if (lttng_is_setuid_setgid()) {
418 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
419 "-g, --group");
420 } else {
e6142f2e
JG
421 config_string_set(&config.tracing_group_name,
422 strdup(arg));
423 if (!config.tracing_group_name.value) {
e8fa9fb0 424 ret = -ENOMEM;
e6142f2e 425 PERROR("strdup");
e8fa9fb0 426 }
db322c4d 427 }
c0232ea5 428 } else if (string_match(optname, "help") || opt == 'h') {
4fc83d94 429 ret = utils_show_help(8, "lttng-sessiond", help_msg);
8190767e 430 if (ret) {
4fc83d94 431 ERR("Cannot show --help for `lttng-sessiond`");
8190767e
PP
432 perror("exec");
433 }
434 exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);
c0232ea5 435 } else if (string_match(optname, "version") || opt == 'V') {
26296c48
JG
436 fprintf(stdout, "%s\n", VERSION);
437 exit(EXIT_SUCCESS);
c0232ea5 438 } else if (string_match(optname, "sig-parent") || opt == 'S') {
e6142f2e 439 config.sig_parent = true;
c0232ea5 440 } else if (string_match(optname, "kconsumerd-err-sock")) {
66b2ce8e
JG
441 if (!arg || *arg == '\0') {
442 ret = -EINVAL;
443 goto end;
444 }
e8fa9fb0
MD
445 if (lttng_is_setuid_setgid()) {
446 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
447 "--kconsumerd-err-sock");
448 } else {
e6142f2e
JG
449 config_string_set(&config.kconsumerd_err_unix_sock_path,
450 strdup(arg));
451 if (!config.kconsumerd_err_unix_sock_path.value) {
452 ret = -ENOMEM;
453 PERROR("strdup");
454 }
e8fa9fb0 455 }
c0232ea5 456 } else if (string_match(optname, "kconsumerd-cmd-sock")) {
66b2ce8e
JG
457 if (!arg || *arg == '\0') {
458 ret = -EINVAL;
459 goto end;
460 }
e8fa9fb0
MD
461 if (lttng_is_setuid_setgid()) {
462 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
463 "--kconsumerd-cmd-sock");
464 } else {
e6142f2e
JG
465 config_string_set(&config.kconsumerd_cmd_unix_sock_path,
466 strdup(arg));
467 if (!config.kconsumerd_cmd_unix_sock_path.value) {
468 ret = -ENOMEM;
469 PERROR("strdup");
470 }
e8fa9fb0 471 }
c0232ea5 472 } else if (string_match(optname, "ustconsumerd64-err-sock")) {
66b2ce8e
JG
473 if (!arg || *arg == '\0') {
474 ret = -EINVAL;
475 goto end;
476 }
e8fa9fb0
MD
477 if (lttng_is_setuid_setgid()) {
478 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
479 "--ustconsumerd64-err-sock");
480 } else {
e6142f2e
JG
481 config_string_set(&config.consumerd64_err_unix_sock_path,
482 strdup(arg));
483 if (!config.consumerd64_err_unix_sock_path.value) {
484 ret = -ENOMEM;
485 PERROR("strdup");
486 }
e8fa9fb0 487 }
c0232ea5 488 } else if (string_match(optname, "ustconsumerd64-cmd-sock")) {
66b2ce8e
JG
489 if (!arg || *arg == '\0') {
490 ret = -EINVAL;
491 goto end;
492 }
e8fa9fb0
MD
493 if (lttng_is_setuid_setgid()) {
494 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
495 "--ustconsumerd64-cmd-sock");
496 } else {
e6142f2e
JG
497 config_string_set(&config.consumerd64_cmd_unix_sock_path,
498 strdup(arg));
499 if (!config.consumerd64_cmd_unix_sock_path.value) {
500 ret = -ENOMEM;
501 PERROR("strdup");
502 }
e8fa9fb0 503 }
c0232ea5 504 } else if (string_match(optname, "ustconsumerd32-err-sock")) {
66b2ce8e
JG
505 if (!arg || *arg == '\0') {
506 ret = -EINVAL;
507 goto end;
508 }
e8fa9fb0
MD
509 if (lttng_is_setuid_setgid()) {
510 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
511 "--ustconsumerd32-err-sock");
512 } else {
e6142f2e
JG
513 config_string_set(&config.consumerd32_err_unix_sock_path,
514 strdup(arg));
515 if (!config.consumerd32_err_unix_sock_path.value) {
516 ret = -ENOMEM;
517 PERROR("strdup");
518 }
e8fa9fb0 519 }
c0232ea5 520 } else if (string_match(optname, "ustconsumerd32-cmd-sock")) {
66b2ce8e
JG
521 if (!arg || *arg == '\0') {
522 ret = -EINVAL;
523 goto end;
524 }
e8fa9fb0
MD
525 if (lttng_is_setuid_setgid()) {
526 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
527 "--ustconsumerd32-cmd-sock");
528 } else {
e6142f2e
JG
529 config_string_set(&config.consumerd32_cmd_unix_sock_path,
530 strdup(arg));
531 if (!config.consumerd32_cmd_unix_sock_path.value) {
532 ret = -ENOMEM;
533 PERROR("strdup");
534 }
e8fa9fb0 535 }
c0232ea5 536 } else if (string_match(optname, "no-kernel")) {
e6142f2e 537 config.no_kernel = true;
c0232ea5 538 } else if (string_match(optname, "quiet") || opt == 'q') {
6d9a9c65 539 config.quiet = true;
c0232ea5 540 } else if (string_match(optname, "verbose") || opt == 'v') {
26296c48
JG
541 /* Verbose level can increase using multiple -v */
542 if (arg) {
13755a18 543 /* Value obtained from config file */
e6142f2e 544 config.verbose = config_parse_value(arg);
26296c48 545 } else {
13755a18 546 /* -v used on command line */
e6142f2e 547 config.verbose++;
26296c48 548 }
13755a18 549 /* Clamp value to [0, 3] */
e6142f2e
JG
550 config.verbose = config.verbose < 0 ? 0 :
551 (config.verbose <= 3 ? config.verbose : 3);
c0232ea5 552 } else if (string_match(optname, "verbose-consumer")) {
26296c48 553 if (arg) {
e6142f2e 554 config.verbose_consumer = config_parse_value(arg);
26296c48 555 } else {
e6142f2e 556 config.verbose_consumer++;
26296c48 557 }
c0232ea5 558 } else if (string_match(optname, "consumerd32-path")) {
66b2ce8e
JG
559 if (!arg || *arg == '\0') {
560 ret = -EINVAL;
561 goto end;
562 }
e8fa9fb0
MD
563 if (lttng_is_setuid_setgid()) {
564 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
565 "--consumerd32-path");
566 } else {
e6142f2e
JG
567 config_string_set(&config.consumerd32_bin_path,
568 strdup(arg));
569 if (!config.consumerd32_bin_path.value) {
e8fa9fb0
MD
570 PERROR("strdup");
571 ret = -ENOMEM;
572 }
db322c4d 573 }
c0232ea5 574 } else if (string_match(optname, "consumerd32-libdir")) {
66b2ce8e
JG
575 if (!arg || *arg == '\0') {
576 ret = -EINVAL;
577 goto end;
578 }
e8fa9fb0
MD
579 if (lttng_is_setuid_setgid()) {
580 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
581 "--consumerd32-libdir");
582 } else {
e6142f2e
JG
583 config_string_set(&config.consumerd32_lib_dir,
584 strdup(arg));
585 if (!config.consumerd32_lib_dir.value) {
e8fa9fb0
MD
586 PERROR("strdup");
587 ret = -ENOMEM;
588 }
db322c4d 589 }
c0232ea5 590 } else if (string_match(optname, "consumerd64-path")) {
66b2ce8e
JG
591 if (!arg || *arg == '\0') {
592 ret = -EINVAL;
593 goto end;
594 }
e8fa9fb0
MD
595 if (lttng_is_setuid_setgid()) {
596 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
597 "--consumerd64-path");
598 } else {
e6142f2e
JG
599 config_string_set(&config.consumerd64_bin_path,
600 strdup(arg));
601 if (!config.consumerd64_bin_path.value) {
e8fa9fb0
MD
602 PERROR("strdup");
603 ret = -ENOMEM;
604 }
db322c4d 605 }
c0232ea5 606 } else if (string_match(optname, "consumerd64-libdir")) {
66b2ce8e
JG
607 if (!arg || *arg == '\0') {
608 ret = -EINVAL;
609 goto end;
610 }
e8fa9fb0
MD
611 if (lttng_is_setuid_setgid()) {
612 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
613 "--consumerd64-libdir");
614 } else {
e6142f2e
JG
615 config_string_set(&config.consumerd64_lib_dir,
616 strdup(arg));
617 if (!config.consumerd64_lib_dir.value) {
e8fa9fb0
MD
618 PERROR("strdup");
619 ret = -ENOMEM;
620 }
db322c4d 621 }
c0232ea5 622 } else if (string_match(optname, "pidfile") || opt == 'p') {
66b2ce8e
JG
623 if (!arg || *arg == '\0') {
624 ret = -EINVAL;
625 goto end;
626 }
e8fa9fb0
MD
627 if (lttng_is_setuid_setgid()) {
628 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
629 "-p, --pidfile");
630 } else {
e6142f2e
JG
631 config_string_set(&config.pid_file_path, strdup(arg));
632 if (!config.pid_file_path.value) {
e8fa9fb0
MD
633 PERROR("strdup");
634 ret = -ENOMEM;
635 }
db322c4d 636 }
c0232ea5 637 } else if (string_match(optname, "agent-tcp-port")) {
66b2ce8e
JG
638 if (!arg || *arg == '\0') {
639 ret = -EINVAL;
640 goto end;
641 }
e8fa9fb0
MD
642 if (lttng_is_setuid_setgid()) {
643 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
644 "--agent-tcp-port");
645 } else {
646 unsigned long v;
4d076222 647
e8fa9fb0
MD
648 errno = 0;
649 v = strtoul(arg, NULL, 0);
650 if (errno != 0 || !isdigit(arg[0])) {
651 ERR("Wrong value in --agent-tcp-port parameter: %s", arg);
652 return -1;
653 }
654 if (v == 0 || v >= 65535) {
655 ERR("Port overflow in --agent-tcp-port parameter: %s", arg);
656 return -1;
657 }
2288467f
JG
658 config.agent_tcp_port.begin = config.agent_tcp_port.end = (int) v;
659 DBG3("Agent TCP port set to non default: %i", (int) v);
26296c48 660 }
c0232ea5 661 } else if (string_match(optname, "load") || opt == 'l') {
66b2ce8e
JG
662 if (!arg || *arg == '\0') {
663 ret = -EINVAL;
664 goto end;
665 }
e8fa9fb0
MD
666 if (lttng_is_setuid_setgid()) {
667 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
668 "-l, --load");
669 } else {
e6142f2e
JG
670 config_string_set(&config.load_session_path, strdup(arg));
671 if (!config.load_session_path.value) {
e8fa9fb0
MD
672 PERROR("strdup");
673 ret = -ENOMEM;
674 }
ef367a93 675 }
c0232ea5 676 } else if (string_match(optname, "kmod-probes")) {
66b2ce8e
JG
677 if (!arg || *arg == '\0') {
678 ret = -EINVAL;
679 goto end;
680 }
e8fa9fb0
MD
681 if (lttng_is_setuid_setgid()) {
682 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
683 "--kmod-probes");
684 } else {
e6142f2e
JG
685 config_string_set(&config.kmod_probes_list, strdup(arg));
686 if (!config.kmod_probes_list.value) {
e8fa9fb0
MD
687 PERROR("strdup");
688 ret = -ENOMEM;
689 }
c9d42407 690 }
c0232ea5 691 } else if (string_match(optname, "extra-kmod-probes")) {
66b2ce8e
JG
692 if (!arg || *arg == '\0') {
693 ret = -EINVAL;
694 goto end;
695 }
e8fa9fb0
MD
696 if (lttng_is_setuid_setgid()) {
697 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
698 "--extra-kmod-probes");
699 } else {
e6142f2e
JG
700 config_string_set(&config.kmod_extra_probes_list,
701 strdup(arg));
702 if (!config.kmod_extra_probes_list.value) {
e8fa9fb0
MD
703 PERROR("strdup");
704 ret = -ENOMEM;
705 }
db322c4d 706 }
c0232ea5
JG
707 } else if (string_match(optname, "config") || opt == 'f') {
708 /* This is handled in set_options() thus silent skip. */
709 goto end;
710 } else {
26296c48
JG
711 /* Unknown option or other error.
712 * Error is printed by getopt, just return */
713 ret = -1;
714 }
715
f3dd7ce7 716end:
c5d350b2
JG
717 if (ret == -EINVAL) {
718 const char *opt_name = "unknown";
719 int i;
720
721 for (i = 0; i < sizeof(long_options) / sizeof(struct option);
722 i++) {
723 if (opt == long_options[i].val) {
724 opt_name = long_options[i].name;
725 break;
726 }
727 }
728
729 WARN("Invalid argument provided for option \"%s\", using default value.",
730 opt_name);
731 }
f3dd7ce7 732
26296c48
JG
733 return ret;
734}
735
736/*
737 * config_entry_handler_cb used to handle options read from a config file.
f40ef1d5 738 * See config_entry_handler_cb comment in common/config/session-config.h for the
26296c48
JG
739 * return value conventions.
740 */
741static int config_entry_handler(const struct config_entry *entry, void *unused)
742{
743 int ret = 0, i;
744
745 if (!entry || !entry->name || !entry->value) {
746 ret = -EINVAL;
747 goto end;
748 }
749
750 /* Check if the option is to be ignored */
751 for (i = 0; i < sizeof(config_ignore_options) / sizeof(char *); i++) {
752 if (!strcmp(entry->name, config_ignore_options[i])) {
753 goto end;
754 }
755 }
756
757 for (i = 0; i < (sizeof(long_options) / sizeof(struct option)) - 1;
758 i++) {
759
760 /* Ignore if not fully matched. */
761 if (strcmp(entry->name, long_options[i].name)) {
762 continue;
763 }
764
765 /*
766 * If the option takes no argument on the command line, we have to
767 * check if the value is "true". We support non-zero numeric values,
768 * true, on and yes.
769 */
770 if (!long_options[i].has_arg) {
771 ret = config_parse_value(entry->value);
772 if (ret <= 0) {
773 if (ret) {
774 WARN("Invalid configuration value \"%s\" for option %s",
775 entry->value, entry->name);
776 }
777 /* False, skip boolean config option. */
778 goto end;
4d076222 779 }
26296c48
JG
780 }
781
782 ret = set_option(long_options[i].val, entry->value, entry->name);
783 goto end;
784 }
785
786 WARN("Unrecognized option \"%s\" in daemon configuration file.", entry->name);
787
788end:
789 return ret;
790}
791
792/*
793 * daemon configuration loading and argument parsing
794 */
795static int set_options(int argc, char **argv)
796{
797 int ret = 0, c = 0, option_index = 0;
798 int orig_optopt = optopt, orig_optind = optind;
799 char *optstring;
3b7acd37 800 char *config_path = NULL;
26296c48
JG
801
802 optstring = utils_generate_optstring(long_options,
803 sizeof(long_options) / sizeof(struct option));
804 if (!optstring) {
805 ret = -ENOMEM;
806 goto end;
807 }
808
809 /* Check for the --config option */
810 while ((c = getopt_long(argc, argv, optstring, long_options,
811 &option_index)) != -1) {
812 if (c == '?') {
813 ret = -EINVAL;
814 goto end;
815 } else if (c != 'f') {
816 /* if not equal to --config option. */
817 continue;
818 }
819
e8fa9fb0
MD
820 if (lttng_is_setuid_setgid()) {
821 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
822 "-f, --config");
823 } else {
3b7acd37 824 free(config_path);
e8fa9fb0
MD
825 config_path = utils_expand_path(optarg);
826 if (!config_path) {
827 ERR("Failed to resolve path: %s", optarg);
828 }
26296c48
JG
829 }
830 }
831
832 ret = config_get_section_entries(config_path, config_section_name,
833 config_entry_handler, NULL);
834 if (ret) {
835 if (ret > 0) {
836 ERR("Invalid configuration option at line %i", ret);
837 ret = -1;
838 }
839 goto end;
840 }
841
842 /* Reset getopt's global state */
843 optopt = orig_optopt;
844 optind = orig_optind;
845 while (1) {
c0232ea5
JG
846 option_index = -1;
847 /*
848 * getopt_long() will not set option_index if it encounters a
849 * short option.
850 */
851 c = getopt_long(argc, argv, optstring, long_options,
852 &option_index);
26296c48 853 if (c == -1) {
4d076222
DG
854 break;
855 }
26296c48 856
c0232ea5
JG
857 /*
858 * Pass NULL as the long option name if popt left the index
859 * unset.
860 */
861 ret = set_option(c, optarg,
862 option_index < 0 ? NULL :
863 long_options[option_index].name);
26296c48
JG
864 if (ret < 0) {
865 break;
fac6795d
DG
866 }
867 }
868
26296c48 869end:
3b7acd37 870 free(config_path);
26296c48
JG
871 free(optstring);
872 return ret;
fac6795d
DG
873}
874
f472090a
JG
875/*
876 * Create lockfile using the rundir and return its fd.
877 */
878static int create_lockfile(void)
879{
880 return utils_create_lock_file(config.lock_file_path.value);
881}
882
fac6795d 883/*
54d01ffb
DG
884 * Check if the global socket is available, and if a daemon is answering at the
885 * other side. If yes, error is returned.
f472090a
JG
886 *
887 * Also attempts to create and hold the lock file.
fac6795d 888 */
cf3af59e 889static int check_existing_daemon(void)
fac6795d 890{
f472090a
JG
891 int ret = 0;
892
7d8234d9 893 /* Is there anybody out there ? */
099e26bd 894 if (lttng_session_daemon_alive()) {
f472090a
JG
895 ret = -EEXIST;
896 goto end;
099e26bd 897 }
b09c7c76 898
f472090a
JG
899 lockfile_fd = create_lockfile();
900 if (lockfile_fd < 0) {
901 ret = -EEXIST;
902 goto end;
903 }
904end:
905 return ret;
906}
907
908static void sessiond_cleanup_lock_file(void)
909{
910 int ret;
911
912 /*
913 * Cleanup lock file by deleting it and finaly closing it which will
914 * release the file system lock.
915 */
916 if (lockfile_fd >= 0) {
917 ret = remove(config.lock_file_path.value);
918 if (ret < 0) {
919 PERROR("remove lock file");
920 }
921 ret = close(lockfile_fd);
922 if (ret < 0) {
923 PERROR("close lock file");
924 }
925 }
fac6795d
DG
926}
927
fac6795d 928/*
d063d709 929 * Set the tracing group gid onto the client socket.
5e16da05 930 *
d063d709 931 * Race window between mkdir and chown is OK because we are going from more
d1613cf5 932 * permissive (root.root) to less permissive (root.tracing).
fac6795d 933 */
be040666 934static int set_permissions(char *rundir)
fac6795d
DG
935{
936 int ret;
996b65c8 937 gid_t gid;
fac6795d 938
6710e5aa
JR
939 ret = utils_get_group_id(config.tracing_group_name.value, true, &gid);
940 if (ret) {
941 /* Default to root group. */
942 gid = 0;
943 }
fac6795d 944
d6f42150 945 /* Set lttng run dir */
be040666 946 ret = chown(rundir, 0, gid);
d6f42150 947 if (ret < 0) {
be040666 948 ERR("Unable to set group on %s", rundir);
76d7553f 949 PERROR("chown");
d6f42150
DG
950 }
951
6c71277b
MD
952 /*
953 * Ensure all applications and tracing group can search the run
954 * dir. Allow everyone to read the directory, since it does not
955 * buy us anything to hide its content.
956 */
957 ret = chmod(rundir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
d1613cf5
JN
958 if (ret < 0) {
959 ERR("Unable to set permissions on %s", rundir);
76d7553f 960 PERROR("chmod");
d1613cf5
JN
961 }
962
d6f42150 963 /* lttng client socket path */
e6142f2e 964 ret = chown(config.client_unix_sock_path.value, 0, gid);
fac6795d 965 if (ret < 0) {
e6142f2e 966 ERR("Unable to set group on %s", config.client_unix_sock_path.value);
76d7553f 967 PERROR("chown");
d6f42150
DG
968 }
969
3bd1e081 970 /* kconsumer error socket path */
6c71277b 971 ret = chown(kconsumer_data.err_unix_sock_path, 0, 0);
d6f42150 972 if (ret < 0) {
3bd1e081 973 ERR("Unable to set group on %s", kconsumer_data.err_unix_sock_path);
76d7553f 974 PERROR("chown");
3bd1e081
MD
975 }
976
7753dea8 977 /* 64-bit ustconsumer error socket path */
6c71277b 978 ret = chown(ustconsumer64_data.err_unix_sock_path, 0, 0);
7753dea8
MD
979 if (ret < 0) {
980 ERR("Unable to set group on %s", ustconsumer64_data.err_unix_sock_path);
76d7553f 981 PERROR("chown");
7753dea8
MD
982 }
983
984 /* 32-bit ustconsumer compat32 error socket path */
6c71277b 985 ret = chown(ustconsumer32_data.err_unix_sock_path, 0, 0);
3bd1e081 986 if (ret < 0) {
7753dea8 987 ERR("Unable to set group on %s", ustconsumer32_data.err_unix_sock_path);
76d7553f 988 PERROR("chown");
fac6795d
DG
989 }
990
d6f42150 991 DBG("All permissions are set");
e07ae692 992
fac6795d
DG
993 return ret;
994}
995
d6f42150 996/*
d063d709 997 * Create the lttng run directory needed for all global sockets and pipe.
d6f42150 998 */
e6142f2e 999static int create_lttng_rundir(void)
d6f42150
DG
1000{
1001 int ret;
1002
e6142f2e 1003 DBG3("Creating LTTng run directory: %s", config.rundir.value);
67e40797 1004
e6142f2e 1005 ret = mkdir(config.rundir.value, S_IRWXU);
d6f42150 1006 if (ret < 0) {
b1f11e69 1007 if (errno != EEXIST) {
e6142f2e 1008 ERR("Unable to create %s", config.rundir.value);
b1f11e69
DG
1009 goto error;
1010 } else {
1011 ret = 0;
1012 }
d6f42150
DG
1013 }
1014
1015error:
1016 return ret;
1017}
1018
1019/*
e6142f2e 1020 * Setup sockets and directory needed by the consumerds' communication with the
d063d709 1021 * session daemon.
d6f42150 1022 */
e6142f2e 1023static int set_consumer_sockets(struct consumer_data *consumer_data)
d6f42150
DG
1024{
1025 int ret;
e6142f2e 1026 char *path = NULL;
d6f42150 1027
6c71277b 1028 switch (consumer_data->type) {
7753dea8 1029 case LTTNG_CONSUMER_KERNEL:
e6142f2e 1030 path = config.kconsumerd_path.value;
7753dea8
MD
1031 break;
1032 case LTTNG_CONSUMER64_UST:
e6142f2e 1033 path = config.consumerd64_path.value;
7753dea8
MD
1034 break;
1035 case LTTNG_CONSUMER32_UST:
e6142f2e 1036 path = config.consumerd32_path.value;
7753dea8
MD
1037 break;
1038 default:
1039 ERR("Consumer type unknown");
1040 ret = -EINVAL;
1041 goto error;
d6f42150 1042 }
e6142f2e 1043 assert(path);
d6f42150 1044
67e40797
DG
1045 DBG2("Creating consumer directory: %s", path);
1046
6c71277b 1047 ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP);
e7e1ef17
JR
1048 if (ret < 0 && errno != EEXIST) {
1049 PERROR("mkdir");
1050 ERR("Failed to create %s", path);
1051 goto error;
d6f42150 1052 }
6c71277b 1053 if (is_root) {
6710e5aa
JR
1054 gid_t gid;
1055
1056 ret = utils_get_group_id(config.tracing_group_name.value, true,
1057 &gid);
1058 if (ret) {
1059 /* Default to root group. */
1060 gid = 0;
1061 }
1062
1063 ret = chown(path, 0, gid);
6c71277b
MD
1064 if (ret < 0) {
1065 ERR("Unable to set group on %s", path);
1066 PERROR("chown");
1067 goto error;
1068 }
1069 }
d6f42150 1070
e6142f2e 1071 /* Create the consumerd error unix socket */
3bd1e081
MD
1072 consumer_data->err_sock =
1073 lttcomm_create_unix_sock(consumer_data->err_unix_sock_path);
1074 if (consumer_data->err_sock < 0) {
1075 ERR("Create unix sock failed: %s", consumer_data->err_unix_sock_path);
d6f42150
DG
1076 ret = -1;
1077 goto error;
1078 }
1079
a24f05ab
MD
1080 /*
1081 * Set the CLOEXEC flag. Return code is useless because either way, the
1082 * show must go on.
1083 */
1084 ret = utils_set_fd_cloexec(consumer_data->err_sock);
1085 if (ret < 0) {
1086 PERROR("utils_set_fd_cloexec");
1087 /* continue anyway */
1088 }
1089
d6f42150 1090 /* File permission MUST be 660 */
3bd1e081 1091 ret = chmod(consumer_data->err_unix_sock_path,
54d01ffb 1092 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
d6f42150 1093 if (ret < 0) {
3bd1e081 1094 ERR("Set file permissions failed: %s", consumer_data->err_unix_sock_path);
67e40797 1095 PERROR("chmod");
d6f42150
DG
1096 goto error;
1097 }
1098
1099error:
1100 return ret;
1101}
1102
fac6795d 1103/*
d063d709 1104 * Signal handler for the daemon
cf3af59e 1105 *
54d01ffb
DG
1106 * Simply stop all worker threads, leaving main() return gracefully after
1107 * joining all threads and calling cleanup().
fac6795d
DG
1108 */
1109static void sighandler(int sig)
1110{
1111 switch (sig) {
cf3af59e 1112 case SIGINT:
af87c45a 1113 DBG("SIGINT caught");
cf3af59e
MD
1114 stop_threads();
1115 break;
1116 case SIGTERM:
af87c45a 1117 DBG("SIGTERM caught");
cf3af59e
MD
1118 stop_threads();
1119 break;
0bb7724a
DG
1120 case SIGUSR1:
1121 CMM_STORE_SHARED(recv_child_signal, 1);
1122 break;
cf3af59e
MD
1123 default:
1124 break;
fac6795d 1125 }
fac6795d
DG
1126}
1127
1128/*
d063d709 1129 * Setup signal handler for :
1d4b027a 1130 * SIGINT, SIGTERM, SIGPIPE
fac6795d 1131 */
1d4b027a 1132static int set_signal_handler(void)
fac6795d 1133{
1d4b027a
DG
1134 int ret = 0;
1135 struct sigaction sa;
1136 sigset_t sigset;
fac6795d 1137
1d4b027a 1138 if ((ret = sigemptyset(&sigset)) < 0) {
76d7553f 1139 PERROR("sigemptyset");
1d4b027a
DG
1140 return ret;
1141 }
d6f42150 1142
1d4b027a
DG
1143 sa.sa_mask = sigset;
1144 sa.sa_flags = 0;
0072e5e2
MD
1145
1146 sa.sa_handler = sighandler;
1d4b027a 1147 if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) {
76d7553f 1148 PERROR("sigaction");
1d4b027a 1149 return ret;
d6f42150
DG
1150 }
1151
1d4b027a 1152 if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) {
76d7553f 1153 PERROR("sigaction");
1d4b027a 1154 return ret;
d6f42150 1155 }
aaf26714 1156
0072e5e2 1157 if ((ret = sigaction(SIGUSR1, &sa, NULL)) < 0) {
76d7553f 1158 PERROR("sigaction");
1d4b027a 1159 return ret;
8c0faa1d
DG
1160 }
1161
0072e5e2
MD
1162 sa.sa_handler = SIG_IGN;
1163 if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) {
0bb7724a
DG
1164 PERROR("sigaction");
1165 return ret;
1166 }
1167
1168 DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
1d4b027a
DG
1169
1170 return ret;
fac6795d
DG
1171}
1172
f3ed775e 1173/*
d063d709 1174 * Set open files limit to unlimited. This daemon can open a large number of
514bb9f0 1175 * file descriptors in order to consume multiple kernel traces.
f3ed775e
DG
1176 */
1177static void set_ulimit(void)
1178{
1179 int ret;
1180 struct rlimit lim;
1181
514bb9f0 1182 /* The kernel does not allow an infinite limit for open files */
f3ed775e
DG
1183 lim.rlim_cur = 65535;
1184 lim.rlim_max = 65535;
1185
1186 ret = setrlimit(RLIMIT_NOFILE, &lim);
1187 if (ret < 0) {
76d7553f 1188 PERROR("failed to set open files limit");
f3ed775e
DG
1189 }
1190}
1191
4a15001e 1192static int write_pidfile(void)
35f90c40 1193{
e6142f2e 1194 return utils_create_pid_file(getpid(), config.pid_file_path.value);
35f90c40
DG
1195}
1196
e6142f2e
JG
1197static int set_clock_plugin_env(void)
1198{
1199 int ret = 0;
1200 char *env_value = NULL;
cd9290dd 1201
e6142f2e
JG
1202 if (!config.lttng_ust_clock_plugin.value) {
1203 goto end;
1204 }
1205
1206 ret = asprintf(&env_value, "LTTNG_UST_CLOCK_PLUGIN=%s",
1207 config.lttng_ust_clock_plugin.value);
cd9290dd 1208 if (ret < 0) {
e6142f2e
JG
1209 PERROR("asprintf");
1210 goto end;
cd9290dd
DG
1211 }
1212
e6142f2e
JG
1213 ret = putenv(env_value);
1214 if (ret) {
1215 free(env_value);
1216 PERROR("putenv of LTTNG_UST_CLOCK_PLUGIN");
1217 goto end;
1218 }
cd9290dd 1219
e6142f2e
JG
1220 DBG("Updated LTTNG_UST_CLOCK_PLUGIN environment variable to \"%s\"",
1221 config.lttng_ust_clock_plugin.value);
1222end:
4a15001e 1223 return ret;
ef367a93
JG
1224}
1225
6af972a2
JG
1226static void destroy_all_sessions_and_wait(void)
1227{
1228 struct ltt_session *session, *tmp;
1229 struct ltt_session_list *session_list;
1230
1231 session_list = session_get_list();
1232 DBG("Initiating destruction of all sessions");
1233
1234 if (!session_list) {
1235 return;
1236 }
1237
6af972a2
JG
1238 session_lock_list();
1239 /* Initiate the destruction of all sessions. */
1240 cds_list_for_each_entry_safe(session, tmp,
1241 &session_list->head, list) {
1242 if (!session_get(session)) {
1243 continue;
1244 }
1245
1246 session_lock(session);
1247 if (session->destroyed) {
1248 goto unlock_session;
1249 }
293d47db 1250 (void) cmd_stop_trace(session);
823a1989
JG
1251 (void) cmd_destroy_session(session, notification_thread_handle,
1252 NULL);
6af972a2
JG
1253 unlock_session:
1254 session_unlock(session);
1255 session_put(session);
1256 }
1257 session_unlock_list();
1258
1259 /* Wait for the destruction of all sessions to complete. */
1260 DBG("Waiting for the destruction of all sessions to complete");
1261 session_list_wait_empty();
1262 DBG("Destruction of all sessions completed");
1263}
1264
5bedd986
JG
1265static int run_as_worker_post_fork_cleanup(void *data)
1266{
1267 struct sessiond_config *sessiond_config = data;
1268
1269 sessiond_config_fini(sessiond_config);
1270 return 0;
1271}
1272
1273static int launch_run_as_worker(const char *procname)
1274{
1275 /*
1276 * Clean-up before forking the run-as worker. Any dynamically
1277 * allocated memory of which the worker is not aware will
1278 * be leaked as the process forks a run-as worker (and performs
1279 * no exec*()). The same would apply to any opened fd.
1280 */
1281 return run_as_create_worker(procname, run_as_worker_post_fork_cleanup,
1282 &config);
1283}
1284
3438f6f5
JG
1285static void sessiond_uuid_log(void)
1286{
1287 char uuid_str[UUID_STR_LEN];
1288
1289 lttng_uuid_to_str(sessiond_uuid, uuid_str);
1290 DBG("Starting lttng-sessiond {%s}", uuid_str);
1291}
1292
fac6795d
DG
1293/*
1294 * main
1295 */
1296int main(int argc, char **argv)
1297{
4a15001e 1298 int ret = 0, retval = 0;
e6142f2e 1299 const char *env_app_timeout;
b3530820
JG
1300 struct lttng_pipe *ust32_channel_monitor_pipe = NULL,
1301 *ust64_channel_monitor_pipe = NULL,
1302 *kernel_channel_monitor_pipe = NULL;
548468b9 1303 struct lttng_thread *ht_cleanup_thread = NULL;
a5ab9e05 1304 struct timer_thread_parameters timer_thread_parameters;
a430759b
JG
1305 /* Rotation thread handle. */
1306 struct rotation_thread_handle *rotation_thread_handle = NULL;
d086f507
JD
1307 /* Queue of rotation jobs populated by the sessiond-timer. */
1308 struct rotation_thread_timer_queue *rotation_timer_queue = NULL;
050e613c 1309 struct lttng_thread *client_thread = NULL;
4de27698 1310 struct lttng_thread *notification_thread = NULL;
143745a6 1311 struct lttng_thread *register_apps_thread = NULL;
fac6795d 1312
335a95b7
MD
1313 init_kernel_workarounds();
1314
f6a9efaa
DG
1315 rcu_register_thread();
1316
4a15001e
MD
1317 if (set_signal_handler()) {
1318 retval = -1;
1319 goto exit_set_signal_handler;
0bb7724a
DG
1320 }
1321
82528808 1322 if (timer_signal_init()) {
d086f507
JD
1323 retval = -1;
1324 goto exit_set_signal_handler;
1325 }
1326
12744796
DG
1327 page_size = sysconf(_SC_PAGESIZE);
1328 if (page_size < 0) {
1329 PERROR("sysconf _SC_PAGESIZE");
1330 page_size = LONG_MAX;
1331 WARN("Fallback page size to %ld", page_size);
1332 }
1333
e6142f2e
JG
1334 ret = sessiond_config_init(&config);
1335 if (ret) {
1336 retval = -1;
1337 goto exit_set_signal_handler;
1338 }
1339
2788b494
JR
1340 /*
1341 * Init config from environment variables.
1342 * Command line option override env configuration per-doc. Do env first.
1343 */
1344 sessiond_config_apply_env_config(&config);
1345
4a15001e
MD
1346 /*
1347 * Parse arguments and load the daemon configuration file.
1348 *
1349 * We have an exit_options exit path to free memory reserved by
1350 * set_options. This is needed because the rest of sessiond_cleanup()
1351 * depends on ht_cleanup_thread, which depends on lttng_daemonize, which
1352 * depends on set_options.
1353 */
fac6795d 1354 progname = argv[0];
4a15001e
MD
1355 if (set_options(argc, argv)) {
1356 retval = -1;
1357 goto exit_options;
fac6795d
DG
1358 }
1359
e6142f2e
JG
1360 /*
1361 * Resolve all paths received as arguments, configuration option, or
1362 * through environment variable as absolute paths. This is necessary
1363 * since daemonizing causes the sessiond's current working directory
1364 * to '/'.
1365 */
1366 ret = sessiond_config_resolve_paths(&config);
1367 if (ret) {
1368 goto exit_options;
1369 }
1370
1371 /* Apply config. */
1372 lttng_opt_verbose = config.verbose;
1373 lttng_opt_quiet = config.quiet;
1374 kconsumer_data.err_unix_sock_path =
1375 config.kconsumerd_err_unix_sock_path.value;
1376 kconsumer_data.cmd_unix_sock_path =
1377 config.kconsumerd_cmd_unix_sock_path.value;
1378 ustconsumer32_data.err_unix_sock_path =
1379 config.consumerd32_err_unix_sock_path.value;
1380 ustconsumer32_data.cmd_unix_sock_path =
1381 config.consumerd32_cmd_unix_sock_path.value;
1382 ustconsumer64_data.err_unix_sock_path =
1383 config.consumerd64_err_unix_sock_path.value;
1384 ustconsumer64_data.cmd_unix_sock_path =
1385 config.consumerd64_cmd_unix_sock_path.value;
1386 set_clock_plugin_env();
1387
1388 sessiond_config_log(&config);
3438f6f5 1389 sessiond_uuid_log();
e6142f2e 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
5bedd986 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;
813ef6cb 1444 goto stop_threads;
4a15001e
MD
1445 }
1446
4a15001e 1447 /* Create thread to clean up RCU hash tables */
548468b9
JG
1448 ht_cleanup_thread = launch_ht_cleanup_thread();
1449 if (!ht_cleanup_thread) {
4a15001e 1450 retval = -1;
813ef6cb 1451 goto stop_threads;
4a15001e
MD
1452 }
1453
ceed52b5 1454 /* Create thread quit pipe */
51bb4dbb 1455 if (sessiond_init_thread_quit_pipe()) {
4a15001e 1456 retval = -1;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 1494 goto stop_threads;
b3530820 1495 }
62c43103 1496
d086f507 1497 /*
82528808
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 */
82528808 1502 rotation_timer_queue = rotation_thread_timer_queue_create();
d086f507
JD
1503 if (!rotation_timer_queue) {
1504 retval = -1;
813ef6cb 1505 goto stop_threads;
d086f507 1506 }
a5ab9e05
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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 1568 goto stop_threads;
67e40797
DG
1569 }
1570
e6142f2e 1571 if (set_consumer_sockets(&ustconsumer32_data)) {
4a15001e 1572 retval = -1;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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;
813ef6cb 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. */
225221a8 1631 if (!launch_health_management_thread()) {
4a15001e 1632 retval = -1;
813ef6cb 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,
8898b0da 1640 kernel_channel_monitor_pipe);
b3530820
JG
1641 if (!notification_thread_handle) {
1642 retval = -1;
1643 ERR("Failed to create notification thread shared data");
813ef6cb 1644 goto stop_threads;
b3530820
JG
1645 }
1646
1647 /* Create notification thread. */
4de27698
JG
1648 notification_thread = launch_notification_thread(
1649 notification_thread_handle);
1650 if (!notification_thread) {
b3530820 1651 retval = -1;
813ef6cb 1652 goto stop_threads;
b3530820
JG
1653 }
1654
d086f507 1655 /* Create timer thread. */
a5ab9e05 1656 if (!launch_timer_thread(&timer_thread_parameters)) {
d086f507 1657 retval = -1;
813ef6cb 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,
8898b0da 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();
813ef6cb 1669 goto stop_threads;
db66e574 1670 }
db66e574
JD
1671
1672 /* Create rotation thread. */
a430759b 1673 if (!launch_rotation_thread(rotation_thread_handle)) {
db66e574 1674 retval = -1;
813ef6cb 1675 goto stop_threads;
db66e574
JD
1676 }
1677
cf3af59e 1678 /* Create thread to manage the client socket */
050e613c
JG
1679 client_thread = launch_client_thread();
1680 if (!client_thread) {
4a15001e 1681 retval = -1;
813ef6cb 1682 goto stop_threads;
cf3af59e 1683 }
fac6795d 1684
eaacb6d7
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
dd5875e7
JG
1691 if (!launch_ust_dispatch_thread(&ust_cmd_queue, apps_cmd_pipe[1],
1692 apps_cmd_notify_pipe[1])) {
4a15001e 1693 retval = -1;
813ef6cb 1694 goto stop_threads;
099e26bd
DG
1695 }
1696
1697 /* Create thread to manage application registration. */
143745a6
JG
1698 register_apps_thread = launch_application_registration_thread(
1699 &ust_cmd_queue);
1700 if (!register_apps_thread) {
4a15001e 1701 retval = -1;
813ef6cb 1702 goto stop_threads;
099e26bd
DG
1703 }
1704
cf3af59e 1705 /* Create thread to manage application socket */
cdffb210 1706 if (!launch_application_management_thread(apps_cmd_pipe[0])) {
4a15001e 1707 retval = -1;
813ef6cb 1708 goto stop_threads;
d0b96690
DG
1709 }
1710
1711 /* Create thread to manage application notify socket */
53c51aaa 1712 if (!launch_application_notification_thread(apps_cmd_notify_pipe[0])) {
4a15001e 1713 retval = -1;
813ef6cb 1714 goto stop_threads;
cf3af59e 1715 }
fac6795d 1716
7baf7871
JG
1717 /* Create agent management thread. */
1718 if (!launch_agent_management_thread()) {
4a15001e 1719 retval = -1;
813ef6cb 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 */
45f6525f 1726 if (!launch_kernel_management_thread(kernel_poll_pipe[0])) {
4a15001e 1727 retval = -1;
813ef6cb 1728 goto stop_threads;
6620da75 1729 }
ef367a93 1730 }
7a485870 1731
51e3e495
JG
1732 /* Load sessions. */
1733 ret = config_load_session(config.load_session_path.value,
1734 NULL, 1, 1, NULL);
4a15001e 1735 if (ret) {
51e3e495 1736 ERR("Session load failed: %s", error_get_str(ret));
4a15001e 1737 retval = -1;
813ef6cb 1738 goto stop_threads;
4a15001e
MD
1739 }
1740
51e3e495
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
6af972a2 1749 /* Initiate teardown once activity occurs on the quit pipe. */
06d7785f 1750 sessiond_wait_for_quit_pipe(-1);
050e613c 1751
813ef6cb 1752stop_threads:
050e613c
JG
1753 /*
1754 * Ensure that the client thread is no longer accepting new commands,
1755 * which could cause new sessions to be created.
1756 */
813ef6cb
JG
1757 if (client_thread) {
1758 lttng_thread_shutdown(client_thread);
050e613c 1759 lttng_thread_put(client_thread);
050e613c
JG
1760 }
1761
6af972a2 1762 destroy_all_sessions_and_wait();
813ef6cb 1763
143745a6
JG
1764 if (register_apps_thread) {
1765 lttng_thread_shutdown(register_apps_thread);
1766 lttng_thread_put(register_apps_thread);
1767 }
548468b9 1768 lttng_thread_list_shutdown_orphans();
050e613c 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
4de27698
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
548468b9
JG
1795 if (ht_cleanup_thread) {
1796 lttng_thread_shutdown(ht_cleanup_thread);
1797 lttng_thread_put(ht_cleanup_thread);
1798 }
1799
a430759b
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 */
82528808 1811 rotation_thread_timer_queue_destroy(rotation_timer_queue);
8898b0da
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
98693d4f
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.374833 seconds and 4 git commands to generate.