2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
22 #include <sys/mount.h>
23 #include <sys/resource.h>
24 #include <sys/socket.h>
26 #include <sys/types.h>
28 #include <urcu/uatomic.h>
32 #include <common/common.h>
33 #include <common/compat/socket.h>
34 #include <common/compat/getenv.h>
35 #include <common/defaults.h>
36 #include <common/kernel-consumer/kernel-consumer.h>
37 #include <common/futex.h>
38 #include <common/relayd/relayd.h>
39 #include <common/utils.h>
40 #include <common/daemonize.h>
41 #include <common/config/session-config.h>
42 #include <common/dynamic-buffer.h>
43 #include <lttng/event-internal.h>
45 #include "lttng-sessiond.h"
46 #include "buffer-registry.h"
52 #include "event-notifier-error-accounting.h"
54 #include "kernel-consumer.h"
55 #include "lttng-ust-ctl.h"
56 #include "ust-consumer.h"
59 #include "health-sessiond.h"
60 #include "testpoint.h"
61 #include "notify-apps.h"
62 #include "agent-thread.h"
64 #include "notification-thread.h"
65 #include "notification-thread-commands.h"
66 #include "rotation-thread.h"
68 #include "ht-cleanup.h"
69 #include "sessiond-config.h"
75 #include "manage-apps.h"
76 #include "manage-kernel.h"
79 static const char *help_msg
=
80 #ifdef LTTNG_EMBED_HELP
81 #include <lttng-sessiond.8.h>
87 #define EVENT_NOTIFIER_ERROR_COUNTER_NUMBER_OF_BUCKET_MAX 65535
90 static int lockfile_fd
= -1;
91 static int opt_print_version
;
93 /* Set to 1 when a SIGUSR1 signal is received. */
94 static int recv_child_signal
;
96 /* Command line options */
97 static const struct option long_options
[] = {
98 { "client-sock", required_argument
, 0, 'c' },
99 { "apps-sock", required_argument
, 0, 'a' },
100 { "kconsumerd-cmd-sock", required_argument
, 0, '\0' },
101 { "kconsumerd-err-sock", required_argument
, 0, '\0' },
102 { "ustconsumerd32-cmd-sock", required_argument
, 0, '\0' },
103 { "ustconsumerd32-err-sock", required_argument
, 0, '\0' },
104 { "ustconsumerd64-cmd-sock", required_argument
, 0, '\0' },
105 { "ustconsumerd64-err-sock", required_argument
, 0, '\0' },
106 { "consumerd32-path", required_argument
, 0, '\0' },
107 { "consumerd32-libdir", required_argument
, 0, '\0' },
108 { "consumerd64-path", required_argument
, 0, '\0' },
109 { "consumerd64-libdir", required_argument
, 0, '\0' },
110 { "daemonize", no_argument
, 0, 'd' },
111 { "background", no_argument
, 0, 'b' },
112 { "sig-parent", no_argument
, 0, 'S' },
113 { "help", no_argument
, 0, 'h' },
114 { "group", required_argument
, 0, 'g' },
115 { "version", no_argument
, 0, 'V' },
116 { "quiet", no_argument
, 0, 'q' },
117 { "verbose", no_argument
, 0, 'v' },
118 { "verbose-consumer", no_argument
, 0, '\0' },
119 { "no-kernel", no_argument
, 0, '\0' },
120 { "pidfile", required_argument
, 0, 'p' },
121 { "agent-tcp-port", required_argument
, 0, '\0' },
122 { "config", required_argument
, 0, 'f' },
123 { "load", required_argument
, 0, 'l' },
124 { "kmod-probes", required_argument
, 0, '\0' },
125 { "extra-kmod-probes", required_argument
, 0, '\0' },
126 { "event-notifier-error-number-of-bucket", required_argument
, 0, '\0' },
130 /* Command line options to ignore from configuration file */
131 static const char *config_ignore_options
[] = { "help", "version", "config" };
134 * This pipe is used to inform the thread managing application communication
135 * that a command is queued and ready to be processed.
137 static int apps_cmd_pipe
[2] = { -1, -1 };
138 static int apps_cmd_notify_pipe
[2] = { -1, -1 };
141 * UST registration command queue. This queue is tied with a futex and uses a N
142 * wakers / 1 waiter implemented and detailed in futex.c/.h
144 * The thread_registration_apps and thread_dispatch_ust_registration uses this
145 * queue along with the wait/wake scheme. The thread_manage_apps receives down
146 * the line new application socket and monitors it for any I/O error or clean
147 * close that triggers an unregistration of the application.
149 static struct ust_cmd_queue ust_cmd_queue
;
152 * Section name to look for in the daemon configuration file.
154 static const char * const config_section_name
= "sessiond";
156 /* Am I root or not. Set to 1 if the daemon is running as root */
160 * Stop all threads by closing the thread quit pipe.
162 static void stop_threads(void)
166 /* Stopping all threads */
167 DBG("Terminating all threads");
168 ret
= sessiond_notify_quit_pipe();
170 ERR("write error on thread quit pipe");
175 * Close every consumer sockets.
177 static void close_consumer_sockets(void)
181 if (kconsumer_data
.err_sock
>= 0) {
182 ret
= close(kconsumer_data
.err_sock
);
184 PERROR("kernel consumer err_sock close");
187 if (ustconsumer32_data
.err_sock
>= 0) {
188 ret
= close(ustconsumer32_data
.err_sock
);
190 PERROR("UST consumerd32 err_sock close");
193 if (ustconsumer64_data
.err_sock
>= 0) {
194 ret
= close(ustconsumer64_data
.err_sock
);
196 PERROR("UST consumerd64 err_sock close");
199 if (kconsumer_data
.cmd_sock
>= 0) {
200 ret
= close(kconsumer_data
.cmd_sock
);
202 PERROR("kernel consumer cmd_sock close");
205 if (ustconsumer32_data
.cmd_sock
>= 0) {
206 ret
= close(ustconsumer32_data
.cmd_sock
);
208 PERROR("UST consumerd32 cmd_sock close");
211 if (ustconsumer64_data
.cmd_sock
>= 0) {
212 ret
= close(ustconsumer64_data
.cmd_sock
);
214 PERROR("UST consumerd64 cmd_sock close");
217 if (kconsumer_data
.channel_monitor_pipe
>= 0) {
218 ret
= close(kconsumer_data
.channel_monitor_pipe
);
220 PERROR("kernel consumer channel monitor pipe close");
223 if (ustconsumer32_data
.channel_monitor_pipe
>= 0) {
224 ret
= close(ustconsumer32_data
.channel_monitor_pipe
);
226 PERROR("UST consumerd32 channel monitor pipe close");
229 if (ustconsumer64_data
.channel_monitor_pipe
>= 0) {
230 ret
= close(ustconsumer64_data
.channel_monitor_pipe
);
232 PERROR("UST consumerd64 channel monitor pipe close");
238 * Wait on consumer process termination.
240 * Need to be called with the consumer data lock held or from a context
241 * ensuring no concurrent access to data (e.g: cleanup).
243 static void wait_consumer(struct consumer_data
*consumer_data
)
248 if (consumer_data
->pid
<= 0) {
252 DBG("Waiting for complete teardown of consumerd (PID: %d)",
254 ret
= waitpid(consumer_data
->pid
, &status
, 0);
256 PERROR("consumerd waitpid pid: %d", consumer_data
->pid
)
257 } else if (!WIFEXITED(status
)) {
258 ERR("consumerd termination with error: %d",
261 consumer_data
->pid
= 0;
265 * Cleanup the session daemon's data structures.
267 static void sessiond_cleanup(void)
270 struct ltt_session_list
*session_list
= session_get_list();
272 DBG("Cleanup sessiond");
275 * Close the thread quit pipe. It has already done its job,
276 * since we are now called.
278 sessiond_close_quit_pipe();
279 utils_close_pipe(apps_cmd_pipe
);
280 utils_close_pipe(apps_cmd_notify_pipe
);
281 utils_close_pipe(kernel_poll_pipe
);
283 ret
= remove(config
.pid_file_path
.value
);
285 PERROR("remove pidfile %s", config
.pid_file_path
.value
);
288 DBG("Removing sessiond and consumerd content of directory %s",
289 config
.rundir
.value
);
292 DBG("Removing %s", config
.pid_file_path
.value
);
293 (void) unlink(config
.pid_file_path
.value
);
295 DBG("Removing %s", config
.agent_port_file_path
.value
);
296 (void) unlink(config
.agent_port_file_path
.value
);
299 DBG("Removing %s", kconsumer_data
.err_unix_sock_path
);
300 (void) unlink(kconsumer_data
.err_unix_sock_path
);
302 DBG("Removing directory %s", config
.kconsumerd_path
.value
);
303 (void) rmdir(config
.kconsumerd_path
.value
);
305 /* ust consumerd 32 */
306 DBG("Removing %s", config
.consumerd32_err_unix_sock_path
.value
);
307 (void) unlink(config
.consumerd32_err_unix_sock_path
.value
);
309 DBG("Removing directory %s", config
.consumerd32_path
.value
);
310 (void) rmdir(config
.consumerd32_path
.value
);
312 /* ust consumerd 64 */
313 DBG("Removing %s", config
.consumerd64_err_unix_sock_path
.value
);
314 (void) unlink(config
.consumerd64_err_unix_sock_path
.value
);
316 DBG("Removing directory %s", config
.consumerd64_path
.value
);
317 (void) rmdir(config
.consumerd64_path
.value
);
319 pthread_mutex_destroy(&session_list
->lock
);
321 DBG("Cleaning up all per-event notifier domain agents");
322 agent_by_event_notifier_domain_ht_destroy();
324 DBG("Cleaning up all agent apps");
325 agent_app_ht_clean();
326 DBG("Closing all UST sockets");
327 ust_app_clean_list();
328 buffer_reg_destroy_registries();
330 close_consumer_sockets();
332 wait_consumer(&kconsumer_data
);
333 wait_consumer(&ustconsumer64_data
);
334 wait_consumer(&ustconsumer32_data
);
336 if (is_root
&& !config
.no_kernel
) {
337 cleanup_kernel_tracer();
341 * We do NOT rmdir rundir because there are other processes
342 * using it, for instance lttng-relayd, which can start in
343 * parallel with this teardown.
348 * Cleanup the daemon's option data structures.
350 static void sessiond_cleanup_options(void)
352 DBG("Cleaning up options");
354 sessiond_config_fini(&config
);
356 run_as_destroy_worker();
359 static int string_match(const char *str1
, const char *str2
)
361 return (str1
&& str2
) && !strcmp(str1
, str2
);
365 * Take an option from the getopt output and set it in the right variable to be
368 * Return 0 on success else a negative value.
370 static int set_option(int opt
, const char *arg
, const char *optname
)
374 if (string_match(optname
, "client-sock") || opt
== 'c') {
375 if (!arg
|| *arg
== '\0') {
379 if (lttng_is_setuid_setgid()) {
380 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
381 "-c, --client-sock");
383 config_string_set(&config
.client_unix_sock_path
,
385 if (!config
.client_unix_sock_path
.value
) {
390 } else if (string_match(optname
, "apps-sock") || opt
== 'a') {
391 if (!arg
|| *arg
== '\0') {
395 if (lttng_is_setuid_setgid()) {
396 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
399 config_string_set(&config
.apps_unix_sock_path
,
401 if (!config
.apps_unix_sock_path
.value
) {
406 } else if (string_match(optname
, "daemonize") || opt
== 'd') {
407 config
.daemonize
= true;
408 } else if (string_match(optname
, "background") || opt
== 'b') {
409 config
.background
= true;
410 } else if (string_match(optname
, "group") || opt
== 'g') {
411 if (!arg
|| *arg
== '\0') {
415 if (lttng_is_setuid_setgid()) {
416 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
419 config_string_set(&config
.tracing_group_name
,
421 if (!config
.tracing_group_name
.value
) {
426 } else if (string_match(optname
, "help") || opt
== 'h') {
427 ret
= utils_show_help(8, "lttng-sessiond", help_msg
);
429 ERR("Cannot show --help for `lttng-sessiond`");
432 exit(ret
? EXIT_FAILURE
: EXIT_SUCCESS
);
433 } else if (string_match(optname
, "version") || opt
== 'V') {
434 opt_print_version
= 1;
435 } else if (string_match(optname
, "sig-parent") || opt
== 'S') {
436 config
.sig_parent
= true;
437 } else if (string_match(optname
, "kconsumerd-err-sock")) {
438 if (!arg
|| *arg
== '\0') {
442 if (lttng_is_setuid_setgid()) {
443 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
444 "--kconsumerd-err-sock");
446 config_string_set(&config
.kconsumerd_err_unix_sock_path
,
448 if (!config
.kconsumerd_err_unix_sock_path
.value
) {
453 } else if (string_match(optname
, "kconsumerd-cmd-sock")) {
454 if (!arg
|| *arg
== '\0') {
458 if (lttng_is_setuid_setgid()) {
459 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
460 "--kconsumerd-cmd-sock");
462 config_string_set(&config
.kconsumerd_cmd_unix_sock_path
,
464 if (!config
.kconsumerd_cmd_unix_sock_path
.value
) {
469 } else if (string_match(optname
, "ustconsumerd64-err-sock")) {
470 if (!arg
|| *arg
== '\0') {
474 if (lttng_is_setuid_setgid()) {
475 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
476 "--ustconsumerd64-err-sock");
478 config_string_set(&config
.consumerd64_err_unix_sock_path
,
480 if (!config
.consumerd64_err_unix_sock_path
.value
) {
485 } else if (string_match(optname
, "ustconsumerd64-cmd-sock")) {
486 if (!arg
|| *arg
== '\0') {
490 if (lttng_is_setuid_setgid()) {
491 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
492 "--ustconsumerd64-cmd-sock");
494 config_string_set(&config
.consumerd64_cmd_unix_sock_path
,
496 if (!config
.consumerd64_cmd_unix_sock_path
.value
) {
501 } else if (string_match(optname
, "ustconsumerd32-err-sock")) {
502 if (!arg
|| *arg
== '\0') {
506 if (lttng_is_setuid_setgid()) {
507 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
508 "--ustconsumerd32-err-sock");
510 config_string_set(&config
.consumerd32_err_unix_sock_path
,
512 if (!config
.consumerd32_err_unix_sock_path
.value
) {
517 } else if (string_match(optname
, "ustconsumerd32-cmd-sock")) {
518 if (!arg
|| *arg
== '\0') {
522 if (lttng_is_setuid_setgid()) {
523 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
524 "--ustconsumerd32-cmd-sock");
526 config_string_set(&config
.consumerd32_cmd_unix_sock_path
,
528 if (!config
.consumerd32_cmd_unix_sock_path
.value
) {
533 } else if (string_match(optname
, "no-kernel")) {
534 config
.no_kernel
= true;
535 } else if (string_match(optname
, "quiet") || opt
== 'q') {
537 } else if (string_match(optname
, "verbose") || opt
== 'v') {
538 /* Verbose level can increase using multiple -v */
540 /* Value obtained from config file */
541 config
.verbose
= config_parse_value(arg
);
543 /* -v used on command line */
546 /* Clamp value to [0, 3] */
547 config
.verbose
= config
.verbose
< 0 ? 0 :
548 (config
.verbose
<= 3 ? config
.verbose
: 3);
549 } else if (string_match(optname
, "verbose-consumer")) {
551 config
.verbose_consumer
= config_parse_value(arg
);
553 config
.verbose_consumer
++;
555 } else if (string_match(optname
, "consumerd32-path")) {
556 if (!arg
|| *arg
== '\0') {
560 if (lttng_is_setuid_setgid()) {
561 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
562 "--consumerd32-path");
564 config_string_set(&config
.consumerd32_bin_path
,
566 if (!config
.consumerd32_bin_path
.value
) {
571 } else if (string_match(optname
, "consumerd32-libdir")) {
572 if (!arg
|| *arg
== '\0') {
576 if (lttng_is_setuid_setgid()) {
577 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
578 "--consumerd32-libdir");
580 config_string_set(&config
.consumerd32_lib_dir
,
582 if (!config
.consumerd32_lib_dir
.value
) {
587 } else if (string_match(optname
, "consumerd64-path")) {
588 if (!arg
|| *arg
== '\0') {
592 if (lttng_is_setuid_setgid()) {
593 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
594 "--consumerd64-path");
596 config_string_set(&config
.consumerd64_bin_path
,
598 if (!config
.consumerd64_bin_path
.value
) {
603 } else if (string_match(optname
, "consumerd64-libdir")) {
604 if (!arg
|| *arg
== '\0') {
608 if (lttng_is_setuid_setgid()) {
609 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
610 "--consumerd64-libdir");
612 config_string_set(&config
.consumerd64_lib_dir
,
614 if (!config
.consumerd64_lib_dir
.value
) {
619 } else if (string_match(optname
, "pidfile") || opt
== 'p') {
620 if (!arg
|| *arg
== '\0') {
624 if (lttng_is_setuid_setgid()) {
625 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
628 config_string_set(&config
.pid_file_path
, strdup(arg
));
629 if (!config
.pid_file_path
.value
) {
634 } else if (string_match(optname
, "agent-tcp-port")) {
635 if (!arg
|| *arg
== '\0') {
639 if (lttng_is_setuid_setgid()) {
640 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
646 v
= strtoul(arg
, NULL
, 0);
647 if (errno
!= 0 || !isdigit(arg
[0])) {
648 ERR("Wrong value in --agent-tcp-port parameter: %s", arg
);
651 if (v
== 0 || v
>= 65535) {
652 ERR("Port overflow in --agent-tcp-port parameter: %s", arg
);
655 config
.agent_tcp_port
.begin
= config
.agent_tcp_port
.end
= (int) v
;
656 DBG3("Agent TCP port set to non default: %i", (int) v
);
658 } else if (string_match(optname
, "load") || opt
== 'l') {
659 if (!arg
|| *arg
== '\0') {
663 if (lttng_is_setuid_setgid()) {
664 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
667 config_string_set(&config
.load_session_path
, strdup(arg
));
668 if (!config
.load_session_path
.value
) {
673 } else if (string_match(optname
, "kmod-probes")) {
674 if (!arg
|| *arg
== '\0') {
678 if (lttng_is_setuid_setgid()) {
679 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
682 config_string_set(&config
.kmod_probes_list
, strdup(arg
));
683 if (!config
.kmod_probes_list
.value
) {
688 } else if (string_match(optname
, "extra-kmod-probes")) {
689 if (!arg
|| *arg
== '\0') {
693 if (lttng_is_setuid_setgid()) {
694 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
695 "--extra-kmod-probes");
697 config_string_set(&config
.kmod_extra_probes_list
,
699 if (!config
.kmod_extra_probes_list
.value
) {
704 } else if (string_match(optname
, "event-notifier-error-number-of-bucket")) {
708 v
= strtoul(arg
, NULL
, 0);
709 if (errno
!= 0 || !isdigit(arg
[0])) {
710 ERR("Wrong value in --event-notifier-error-number-of-bucket parameter: %s", arg
);
713 if (v
== 0 || v
>= EVENT_NOTIFIER_ERROR_COUNTER_NUMBER_OF_BUCKET_MAX
) {
714 ERR("Value out of range for --event-notifier-error-number-of-bucket parameter: %s", arg
);
717 config
.event_notifier_error_counter_bucket
= (int) v
;
718 DBG3("Number of event notifier error counter set to non default: %i",
719 config
.event_notifier_error_counter_bucket
);
721 } else if (string_match(optname
, "config") || opt
== 'f') {
722 /* This is handled in set_options() thus silent skip. */
725 /* Unknown option or other error.
726 * Error is printed by getopt, just return */
731 if (ret
== -EINVAL
) {
732 const char *opt_name
= "unknown";
735 for (i
= 0; i
< sizeof(long_options
) / sizeof(struct option
);
737 if (opt
== long_options
[i
].val
) {
738 opt_name
= long_options
[i
].name
;
743 WARN("Invalid argument provided for option \"%s\", using default value.",
751 * config_entry_handler_cb used to handle options read from a config file.
752 * See config_entry_handler_cb comment in common/config/session-config.h for the
753 * return value conventions.
755 static int config_entry_handler(const struct config_entry
*entry
, void *unused
)
759 if (!entry
|| !entry
->name
|| !entry
->value
) {
764 /* Check if the option is to be ignored */
765 for (i
= 0; i
< sizeof(config_ignore_options
) / sizeof(char *); i
++) {
766 if (!strcmp(entry
->name
, config_ignore_options
[i
])) {
771 for (i
= 0; i
< (sizeof(long_options
) / sizeof(struct option
)) - 1;
774 /* Ignore if not fully matched. */
775 if (strcmp(entry
->name
, long_options
[i
].name
)) {
780 * If the option takes no argument on the command line, we have to
781 * check if the value is "true". We support non-zero numeric values,
784 if (!long_options
[i
].has_arg
) {
785 ret
= config_parse_value(entry
->value
);
788 WARN("Invalid configuration value \"%s\" for option %s",
789 entry
->value
, entry
->name
);
791 /* False, skip boolean config option. */
796 ret
= set_option(long_options
[i
].val
, entry
->value
, entry
->name
);
800 WARN("Unrecognized option \"%s\" in daemon configuration file.", entry
->name
);
806 static void print_version(void) {
807 fprintf(stdout
, "%s\n", VERSION
);
811 * daemon configuration loading and argument parsing
813 static int set_options(int argc
, char **argv
)
815 int ret
= 0, c
= 0, option_index
= 0;
816 int orig_optopt
= optopt
, orig_optind
= optind
;
818 const char *config_path
= NULL
;
820 optstring
= utils_generate_optstring(long_options
,
821 sizeof(long_options
) / sizeof(struct option
));
827 /* Check for the --config option */
828 while ((c
= getopt_long(argc
, argv
, optstring
, long_options
,
829 &option_index
)) != -1) {
833 } else if (c
!= 'f') {
834 /* if not equal to --config option. */
838 if (lttng_is_setuid_setgid()) {
839 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
842 config_path
= utils_expand_path(optarg
);
844 ERR("Failed to resolve path: %s", optarg
);
849 ret
= config_get_section_entries(config_path
, config_section_name
,
850 config_entry_handler
, NULL
);
853 ERR("Invalid configuration option at line %i", ret
);
859 /* Reset getopt's global state */
860 optopt
= orig_optopt
;
861 optind
= orig_optind
;
865 * getopt_long() will not set option_index if it encounters a
868 c
= getopt_long(argc
, argv
, optstring
, long_options
,
875 * Pass NULL as the long option name if popt left the index
878 ret
= set_option(c
, optarg
,
879 option_index
< 0 ? NULL
:
880 long_options
[option_index
].name
);
892 * Create lockfile using the rundir and return its fd.
894 static int create_lockfile(void)
896 return utils_create_lock_file(config
.lock_file_path
.value
);
900 * Check if the global socket is available, and if a daemon is answering at the
901 * other side. If yes, error is returned.
903 * Also attempts to create and hold the lock file.
905 static int check_existing_daemon(void)
909 /* Is there anybody out there ? */
910 if (lttng_session_daemon_alive()) {
915 lockfile_fd
= create_lockfile();
916 if (lockfile_fd
< 0) {
924 static void sessiond_cleanup_lock_file(void)
929 * Cleanup lock file by deleting it and finaly closing it which will
930 * release the file system lock.
932 if (lockfile_fd
>= 0) {
933 ret
= remove(config
.lock_file_path
.value
);
935 PERROR("remove lock file");
937 ret
= close(lockfile_fd
);
939 PERROR("close lock file");
945 * Set the tracing group gid onto the client socket.
947 * Race window between mkdir and chown is OK because we are going from more
948 * permissive (root.root) to less permissive (root.tracing).
950 static int set_permissions(char *rundir
)
955 ret
= utils_get_group_id(config
.tracing_group_name
.value
, true, &gid
);
957 /* Default to root group. */
961 /* Set lttng run dir */
962 ret
= chown(rundir
, 0, gid
);
964 ERR("Unable to set group on %s", rundir
);
969 * Ensure all applications and tracing group can search the run
970 * dir. Allow everyone to read the directory, since it does not
971 * buy us anything to hide its content.
973 ret
= chmod(rundir
, S_IRWXU
| S_IRGRP
| S_IXGRP
| S_IROTH
| S_IXOTH
);
975 ERR("Unable to set permissions on %s", rundir
);
979 /* lttng client socket path */
980 ret
= chown(config
.client_unix_sock_path
.value
, 0, gid
);
982 ERR("Unable to set group on %s", config
.client_unix_sock_path
.value
);
986 /* kconsumer error socket path */
987 ret
= chown(kconsumer_data
.err_unix_sock_path
, 0, 0);
989 ERR("Unable to set group on %s", kconsumer_data
.err_unix_sock_path
);
993 /* 64-bit ustconsumer error socket path */
994 ret
= chown(ustconsumer64_data
.err_unix_sock_path
, 0, 0);
996 ERR("Unable to set group on %s", ustconsumer64_data
.err_unix_sock_path
);
1000 /* 32-bit ustconsumer compat32 error socket path */
1001 ret
= chown(ustconsumer32_data
.err_unix_sock_path
, 0, 0);
1003 ERR("Unable to set group on %s", ustconsumer32_data
.err_unix_sock_path
);
1007 DBG("All permissions are set");
1013 * Create the lttng run directory needed for all global sockets and pipe.
1015 static int create_lttng_rundir(void)
1019 DBG3("Creating LTTng run directory: %s", config
.rundir
.value
);
1021 ret
= mkdir(config
.rundir
.value
, S_IRWXU
);
1023 if (errno
!= EEXIST
) {
1024 ERR("Unable to create %s", config
.rundir
.value
);
1036 * Setup sockets and directory needed by the consumerds' communication with the
1039 static int set_consumer_sockets(struct consumer_data
*consumer_data
)
1044 switch (consumer_data
->type
) {
1045 case LTTNG_CONSUMER_KERNEL
:
1046 path
= config
.kconsumerd_path
.value
;
1048 case LTTNG_CONSUMER64_UST
:
1049 path
= config
.consumerd64_path
.value
;
1051 case LTTNG_CONSUMER32_UST
:
1052 path
= config
.consumerd32_path
.value
;
1055 ERR("Consumer type unknown");
1061 DBG2("Creating consumer directory: %s", path
);
1063 ret
= mkdir(path
, S_IRWXU
| S_IRGRP
| S_IXGRP
);
1064 if (ret
< 0 && errno
!= EEXIST
) {
1066 ERR("Failed to create %s", path
);
1072 ret
= utils_get_group_id(config
.tracing_group_name
.value
, true,
1075 /* Default to root group. */
1079 ret
= chown(path
, 0, gid
);
1081 ERR("Unable to set group on %s", path
);
1087 /* Create the consumerd error unix socket */
1088 consumer_data
->err_sock
=
1089 lttcomm_create_unix_sock(consumer_data
->err_unix_sock_path
);
1090 if (consumer_data
->err_sock
< 0) {
1091 ERR("Create unix sock failed: %s", consumer_data
->err_unix_sock_path
);
1097 * Set the CLOEXEC flag. Return code is useless because either way, the
1100 ret
= utils_set_fd_cloexec(consumer_data
->err_sock
);
1102 PERROR("utils_set_fd_cloexec");
1103 /* continue anyway */
1106 /* File permission MUST be 660 */
1107 ret
= chmod(consumer_data
->err_unix_sock_path
,
1108 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
1110 ERR("Set file permissions failed: %s", consumer_data
->err_unix_sock_path
);
1120 * Signal handler for the daemon
1122 * Simply stop all worker threads, leaving main() return gracefully after
1123 * joining all threads and calling cleanup().
1125 static void sighandler(int sig
)
1129 DBG("SIGINT caught");
1133 DBG("SIGTERM caught");
1137 CMM_STORE_SHARED(recv_child_signal
, 1);
1145 * Setup signal handler for :
1146 * SIGINT, SIGTERM, SIGPIPE
1148 static int set_signal_handler(void)
1151 struct sigaction sa
;
1154 if ((ret
= sigemptyset(&sigset
)) < 0) {
1155 PERROR("sigemptyset");
1159 sa
.sa_mask
= sigset
;
1162 sa
.sa_handler
= sighandler
;
1163 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
1164 PERROR("sigaction");
1168 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
1169 PERROR("sigaction");
1173 if ((ret
= sigaction(SIGUSR1
, &sa
, NULL
)) < 0) {
1174 PERROR("sigaction");
1178 sa
.sa_handler
= SIG_IGN
;
1179 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
1180 PERROR("sigaction");
1184 DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
1190 * Set open files limit to unlimited. This daemon can open a large number of
1191 * file descriptors in order to consume multiple kernel traces.
1193 static void set_ulimit(void)
1198 /* The kernel does not allow an infinite limit for open files */
1199 lim
.rlim_cur
= 65535;
1200 lim
.rlim_max
= 65535;
1202 ret
= setrlimit(RLIMIT_NOFILE
, &lim
);
1204 PERROR("failed to set open files limit");
1208 static int write_pidfile(void)
1210 return utils_create_pid_file(getpid(), config
.pid_file_path
.value
);
1213 static int set_clock_plugin_env(void)
1216 char *env_value
= NULL
;
1218 if (!config
.lttng_ust_clock_plugin
.value
) {
1222 ret
= asprintf(&env_value
, "LTTNG_UST_CLOCK_PLUGIN=%s",
1223 config
.lttng_ust_clock_plugin
.value
);
1229 ret
= putenv(env_value
);
1232 PERROR("putenv of LTTNG_UST_CLOCK_PLUGIN");
1236 DBG("Updated LTTNG_UST_CLOCK_PLUGIN environment variable to \"%s\"",
1237 config
.lttng_ust_clock_plugin
.value
);
1242 static void destroy_all_sessions_and_wait(void)
1244 struct ltt_session
*session
, *tmp
;
1245 struct ltt_session_list
*session_list
;
1247 session_list
= session_get_list();
1248 DBG("Initiating destruction of all sessions");
1250 if (!session_list
) {
1254 session_lock_list();
1255 /* Initiate the destruction of all sessions. */
1256 cds_list_for_each_entry_safe(session
, tmp
,
1257 &session_list
->head
, list
) {
1258 if (!session_get(session
)) {
1262 session_lock(session
);
1263 if (session
->destroyed
) {
1264 goto unlock_session
;
1266 (void) cmd_stop_trace(session
);
1267 (void) cmd_destroy_session(session
, notification_thread_handle
,
1270 session_unlock(session
);
1271 session_put(session
);
1273 session_unlock_list();
1275 /* Wait for the destruction of all sessions to complete. */
1276 DBG("Waiting for the destruction of all sessions to complete");
1277 session_list_wait_empty();
1278 DBG("Destruction of all sessions completed");
1281 static void unregister_all_triggers(void)
1283 enum lttng_error_code ret_code
;
1284 enum lttng_trigger_status trigger_status
;
1285 struct lttng_triggers
*triggers
= NULL
;
1286 unsigned int trigger_count
, i
;
1287 const struct lttng_credentials creds
= {
1288 .uid
= LTTNG_OPTIONAL_INIT_VALUE(0),
1291 DBG("Unregistering all triggers");
1294 * List all triggers as "root" since we wish to unregister all triggers.
1296 ret_code
= notification_thread_command_list_triggers(
1297 notification_thread_handle
, creds
.uid
.value
, &triggers
);
1298 if (ret_code
!= LTTNG_OK
) {
1299 ERR("Failed to list triggers while unregistering all triggers");
1303 trigger_status
= lttng_triggers_get_count(triggers
, &trigger_count
);
1304 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
1306 for (i
= 0; i
< trigger_count
; i
++) {
1307 enum lttng_error_code ret_code
;
1308 uid_t trigger_owner
;
1309 const char *trigger_name
;
1310 const struct lttng_trigger
*trigger
=
1311 lttng_triggers_get_at_index(triggers
, i
);
1315 trigger_status
= lttng_trigger_get_owner_uid(
1316 trigger
, &trigger_owner
);
1317 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
1319 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
1320 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
1322 DBG("Unregistering trigger: trigger owner uid = %d, trigger name = '%s'",
1323 (int) trigger_owner
, trigger_name
);
1325 ret_code
= cmd_unregister_trigger(
1326 &creds
, trigger
, notification_thread_handle
);
1327 if (ret_code
!= LTTNG_OK
) {
1328 ERR("Failed to unregister trigger: trigger owner uid = %d, trigger name = '%s', error: '%s'",
1329 (int) trigger_owner
, trigger_name
,
1330 lttng_strerror(-ret_code
));
1331 /* Continue to unregister the remaining triggers. */
1335 lttng_triggers_destroy(triggers
);
1338 static int run_as_worker_post_fork_cleanup(void *data
)
1340 struct sessiond_config
*sessiond_config
= data
;
1342 sessiond_config_fini(sessiond_config
);
1346 static int launch_run_as_worker(const char *procname
)
1349 * Clean-up before forking the run-as worker. Any dynamically
1350 * allocated memory of which the worker is not aware will
1351 * be leaked as the process forks a run-as worker (and performs
1352 * no exec*()). The same would apply to any opened fd.
1354 return run_as_create_worker(procname
, run_as_worker_post_fork_cleanup
,
1358 static void sessiond_uuid_log(void)
1360 char uuid_str
[LTTNG_UUID_STR_LEN
];
1362 lttng_uuid_to_str(sessiond_uuid
, uuid_str
);
1363 DBG("Starting lttng-sessiond {%s}", uuid_str
);
1369 int main(int argc
, char **argv
)
1371 int ret
= 0, retval
= 0;
1372 const char *env_app_timeout
;
1373 struct lttng_pipe
*ust32_channel_monitor_pipe
= NULL
,
1374 *ust64_channel_monitor_pipe
= NULL
,
1375 *kernel_channel_monitor_pipe
= NULL
;
1376 struct lttng_thread
*ht_cleanup_thread
= NULL
;
1377 struct timer_thread_parameters timer_thread_parameters
;
1378 /* Rotation thread handle. */
1379 struct rotation_thread_handle
*rotation_thread_handle
= NULL
;
1380 /* Queue of rotation jobs populated by the sessiond-timer. */
1381 struct rotation_thread_timer_queue
*rotation_timer_queue
= NULL
;
1382 struct lttng_thread
*client_thread
= NULL
;
1383 struct lttng_thread
*notification_thread
= NULL
;
1384 struct lttng_thread
*register_apps_thread
= NULL
;
1386 logger_set_thread_name("Main", false);
1387 init_kernel_workarounds();
1389 rcu_register_thread();
1391 if (set_signal_handler()) {
1393 goto exit_set_signal_handler
;
1396 if (timer_signal_init()) {
1398 goto exit_set_signal_handler
;
1401 page_size
= sysconf(_SC_PAGESIZE
);
1402 if (page_size
< 0) {
1403 PERROR("sysconf _SC_PAGESIZE");
1404 page_size
= LONG_MAX
;
1405 WARN("Fallback page size to %ld", page_size
);
1408 ret
= sessiond_config_init(&config
);
1411 goto exit_set_signal_handler
;
1415 * Init config from environment variables.
1416 * Command line option override env configuration per-doc. Do env first.
1418 sessiond_config_apply_env_config(&config
);
1421 * Parse arguments and load the daemon configuration file.
1423 * We have an exit_options exit path to free memory reserved by
1424 * set_options. This is needed because the rest of sessiond_cleanup()
1425 * depends on ht_cleanup_thread, which depends on lttng_daemonize, which
1426 * depends on set_options.
1429 if (set_options(argc
, argv
)) {
1435 * Resolve all paths received as arguments, configuration option, or
1436 * through environment variable as absolute paths. This is necessary
1437 * since daemonizing causes the sessiond's current working directory
1440 ret
= sessiond_config_resolve_paths(&config
);
1446 lttng_opt_verbose
= config
.verbose
;
1447 lttng_opt_quiet
= config
.quiet
;
1448 kconsumer_data
.err_unix_sock_path
=
1449 config
.kconsumerd_err_unix_sock_path
.value
;
1450 kconsumer_data
.cmd_unix_sock_path
=
1451 config
.kconsumerd_cmd_unix_sock_path
.value
;
1452 ustconsumer32_data
.err_unix_sock_path
=
1453 config
.consumerd32_err_unix_sock_path
.value
;
1454 ustconsumer32_data
.cmd_unix_sock_path
=
1455 config
.consumerd32_cmd_unix_sock_path
.value
;
1456 ustconsumer64_data
.err_unix_sock_path
=
1457 config
.consumerd64_err_unix_sock_path
.value
;
1458 ustconsumer64_data
.cmd_unix_sock_path
=
1459 config
.consumerd64_cmd_unix_sock_path
.value
;
1460 set_clock_plugin_env();
1462 sessiond_config_log(&config
);
1463 sessiond_uuid_log();
1465 if (opt_print_version
) {
1471 if (create_lttng_rundir()) {
1476 /* Abort launch if a session daemon is already running. */
1477 if (check_existing_daemon()) {
1478 ERR("A session daemon is already running.");
1484 if (config
.daemonize
|| config
.background
) {
1487 ret
= lttng_daemonize(&child_ppid
, &recv_child_signal
,
1488 !config
.background
);
1495 * We are in the child. Make sure all other file descriptors are
1496 * closed, in case we are called with more opened file
1497 * descriptors than the standard ones and the lock file.
1499 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
1500 if (i
== lockfile_fd
) {
1507 if (launch_run_as_worker(argv
[0]) < 0) {
1508 goto exit_create_run_as_worker_cleanup
;
1512 * Starting from here, we can create threads. This needs to be after
1513 * lttng_daemonize due to RCU.
1517 * Initialize the health check subsystem. This call should set the
1518 * appropriate time values.
1520 health_sessiond
= health_app_create(NR_HEALTH_SESSIOND_TYPES
);
1521 if (!health_sessiond
) {
1522 PERROR("health_app_create error");
1527 /* Create thread to clean up RCU hash tables */
1528 ht_cleanup_thread
= launch_ht_cleanup_thread();
1529 if (!ht_cleanup_thread
) {
1534 /* Create thread quit pipe */
1535 if (sessiond_init_thread_quit_pipe()) {
1540 /* Check if daemon is UID = 0 */
1541 is_root
= !getuid();
1543 /* Create global run dir with root access */
1545 kernel_channel_monitor_pipe
= lttng_pipe_open(0);
1546 if (!kernel_channel_monitor_pipe
) {
1547 ERR("Failed to create kernel consumer channel monitor pipe");
1551 kconsumer_data
.channel_monitor_pipe
=
1552 lttng_pipe_release_writefd(
1553 kernel_channel_monitor_pipe
);
1554 if (kconsumer_data
.channel_monitor_pipe
< 0) {
1560 /* Set consumer initial state */
1561 kernel_consumerd_state
= CONSUMER_STOPPED
;
1562 ust_consumerd_state
= CONSUMER_STOPPED
;
1564 ust32_channel_monitor_pipe
= lttng_pipe_open(0);
1565 if (!ust32_channel_monitor_pipe
) {
1566 ERR("Failed to create 32-bit user space consumer channel monitor pipe");
1570 ustconsumer32_data
.channel_monitor_pipe
= lttng_pipe_release_writefd(
1571 ust32_channel_monitor_pipe
);
1572 if (ustconsumer32_data
.channel_monitor_pipe
< 0) {
1578 * The rotation_thread_timer_queue structure is shared between the
1579 * sessiond timer thread and the rotation thread. The main thread keeps
1580 * its ownership and destroys it when both threads have been joined.
1582 rotation_timer_queue
= rotation_thread_timer_queue_create();
1583 if (!rotation_timer_queue
) {
1587 timer_thread_parameters
.rotation_thread_job_queue
=
1588 rotation_timer_queue
;
1590 ust64_channel_monitor_pipe
= lttng_pipe_open(0);
1591 if (!ust64_channel_monitor_pipe
) {
1592 ERR("Failed to create 64-bit user space consumer channel monitor pipe");
1596 ustconsumer64_data
.channel_monitor_pipe
= lttng_pipe_release_writefd(
1597 ust64_channel_monitor_pipe
);
1598 if (ustconsumer64_data
.channel_monitor_pipe
< 0) {
1604 * Init UST app hash table. Alloc hash table before this point since
1605 * cleanup() can get called after that point.
1607 if (ust_app_ht_alloc()) {
1608 ERR("Failed to allocate UST app hash table");
1613 event_notifier_error_accounting_init(config
.event_notifier_error_counter_bucket
);
1616 * Initialize agent app hash table. We allocate the hash table here
1617 * since cleanup() can get called after this point.
1619 if (agent_app_ht_alloc()) {
1620 ERR("Failed to allocate Agent app hash table");
1625 if (agent_by_event_notifier_domain_ht_create()) {
1626 ERR("Failed to allocate per-event notifier domain agent hash table");
1631 * These actions must be executed as root. We do that *after* setting up
1632 * the sockets path because we MUST make the check for another daemon using
1633 * those paths *before* trying to set the kernel consumer sockets and init
1637 if (set_consumer_sockets(&kconsumer_data
)) {
1642 /* Setup kernel tracer */
1643 if (!config
.no_kernel
) {
1644 init_kernel_tracer();
1647 /* Set ulimit for open files */
1650 /* init lttng_fd tracking must be done after set_ulimit. */
1653 if (set_consumer_sockets(&ustconsumer64_data
)) {
1658 if (set_consumer_sockets(&ustconsumer32_data
)) {
1663 /* Get parent pid if -S, --sig-parent is specified. */
1664 if (config
.sig_parent
) {
1668 /* Setup the kernel pipe for waking up the kernel thread */
1669 if (is_root
&& !config
.no_kernel
) {
1670 if (utils_create_pipe_cloexec(kernel_poll_pipe
)) {
1676 /* Setup the thread apps communication pipe. */
1677 if (utils_create_pipe_cloexec(apps_cmd_pipe
)) {
1682 /* Setup the thread apps notify communication pipe. */
1683 if (utils_create_pipe_cloexec(apps_cmd_notify_pipe
)) {
1688 /* Initialize global buffer per UID and PID registry. */
1689 buffer_reg_init_uid_registry();
1690 buffer_reg_init_pid_registry();
1692 /* Init UST command queue. */
1693 cds_wfcq_init(&ust_cmd_queue
.head
, &ust_cmd_queue
.tail
);
1697 /* Check for the application socket timeout env variable. */
1698 env_app_timeout
= getenv(DEFAULT_APP_SOCKET_TIMEOUT_ENV
);
1699 if (env_app_timeout
) {
1700 config
.app_socket_timeout
= atoi(env_app_timeout
);
1702 config
.app_socket_timeout
= DEFAULT_APP_SOCKET_RW_TIMEOUT
;
1705 ret
= write_pidfile();
1707 ERR("Error in write_pidfile");
1712 /* Initialize communication library */
1714 /* Initialize TCP timeout values */
1715 lttcomm_inet_init();
1717 /* Create health-check thread. */
1718 if (!launch_health_management_thread()) {
1723 /* notification_thread_data acquires the pipes' read side. */
1724 notification_thread_handle
= notification_thread_handle_create(
1725 ust32_channel_monitor_pipe
,
1726 ust64_channel_monitor_pipe
,
1727 kernel_channel_monitor_pipe
);
1728 if (!notification_thread_handle
) {
1730 ERR("Failed to create notification thread shared data");
1734 /* Create notification thread. */
1735 notification_thread
= launch_notification_thread(
1736 notification_thread_handle
);
1737 if (!notification_thread
) {
1742 /* Create timer thread. */
1743 if (!launch_timer_thread(&timer_thread_parameters
)) {
1748 /* rotation_thread_data acquires the pipes' read side. */
1749 rotation_thread_handle
= rotation_thread_handle_create(
1750 rotation_timer_queue
,
1751 notification_thread_handle
);
1752 if (!rotation_thread_handle
) {
1754 ERR("Failed to create rotation thread shared data");
1759 /* Create rotation thread. */
1760 if (!launch_rotation_thread(rotation_thread_handle
)) {
1765 /* Create thread to manage the client socket */
1766 client_thread
= launch_client_thread();
1767 if (!client_thread
) {
1772 /* Set credentials of the client socket and rundir */
1773 if (is_root
&& set_permissions(config
.rundir
.value
)) {
1778 if (!launch_ust_dispatch_thread(&ust_cmd_queue
, apps_cmd_pipe
[1],
1779 apps_cmd_notify_pipe
[1])) {
1784 /* Create thread to manage application registration. */
1785 register_apps_thread
= launch_application_registration_thread(
1787 if (!register_apps_thread
) {
1792 /* Create thread to manage application socket */
1793 if (!launch_application_management_thread(apps_cmd_pipe
[0])) {
1798 /* Create thread to manage application notify socket */
1799 if (!launch_application_notification_thread(apps_cmd_notify_pipe
[0])) {
1804 /* Create agent management thread. */
1805 if (!launch_agent_management_thread()) {
1810 /* Don't start this thread if kernel tracing is not requested nor root */
1811 if (is_root
&& !config
.no_kernel
) {
1812 /* Create kernel thread to manage kernel event */
1813 if (!launch_kernel_management_thread(kernel_poll_pipe
[0])) {
1818 if (kernel_get_notification_fd() >= 0) {
1819 ret
= notification_thread_command_add_tracer_event_source(
1820 notification_thread_handle
,
1821 kernel_get_notification_fd(),
1822 LTTNG_DOMAIN_KERNEL
);
1823 if (ret
!= LTTNG_OK
) {
1824 ERR("Failed to add kernel trigger event source to notification thread");
1831 /* Load sessions. */
1832 ret
= config_load_session(config
.load_session_path
.value
,
1835 ERR("Session load failed: %s", error_get_str(ret
));
1840 /* Initialization completed. */
1841 sessiond_signal_parents();
1844 * This is where we start awaiting program completion (e.g. through
1845 * signal that asks threads to teardown).
1848 /* Initiate teardown once activity occurs on the quit pipe. */
1849 sessiond_wait_for_quit_pipe(-1);
1854 * Ensure that the client thread is no longer accepting new commands,
1855 * which could cause new sessions to be created.
1857 if (client_thread
) {
1858 lttng_thread_shutdown(client_thread
);
1859 lttng_thread_put(client_thread
);
1862 destroy_all_sessions_and_wait();
1865 * At this point no new trigger can be registered (no sessions are
1866 * running/rotating) and clients can't connect to the session daemon
1867 * anymore. Unregister all triggers.
1869 unregister_all_triggers();
1871 if (register_apps_thread
) {
1872 lttng_thread_shutdown(register_apps_thread
);
1873 lttng_thread_put(register_apps_thread
);
1875 lttng_thread_list_shutdown_orphans();
1878 * Wait for all pending call_rcu work to complete before tearing
1879 * down data structures. call_rcu worker may be trying to
1880 * perform lookups in those structures.
1884 * sessiond_cleanup() is called when no other thread is running, except
1885 * the ht_cleanup thread, which is needed to destroy the hash tables.
1887 rcu_thread_online();
1891 * Wait for all pending call_rcu work to complete before shutting down
1892 * the notification thread. This call_rcu work includes shutting down
1893 * UST apps and event notifier pipes.
1897 if (notification_thread
) {
1898 lttng_thread_shutdown(notification_thread
);
1899 lttng_thread_put(notification_thread
);
1903 * Error accounting teardown has to be done after the teardown of all
1904 * event notifier pipes to ensure that no tracer may try to use the
1905 * error accounting facilities.
1907 event_notifier_error_accounting_fini();
1910 * Unloading the kernel modules needs to be done after all kernel
1911 * ressources have been released. In our case, this includes the
1912 * notification fd, the event notifier group fd, error accounting fd,
1913 * all event and event notifier fds, etc.
1915 * In short, at this point, we need to have called close() on all fds
1916 * received from the kernel tracer.
1918 if (is_root
&& !config
.no_kernel
) {
1919 DBG("Unloading kernel modules");
1920 modprobe_remove_lttng_all();
1924 * Ensure all prior call_rcu are done. call_rcu callbacks may push
1925 * hash tables to the ht_cleanup thread. Therefore, we ensure that
1926 * the queue is empty before shutting down the clean-up thread.
1930 if (ht_cleanup_thread
) {
1931 lttng_thread_shutdown(ht_cleanup_thread
);
1932 lttng_thread_put(ht_cleanup_thread
);
1935 rcu_thread_offline();
1936 rcu_unregister_thread();
1938 if (rotation_thread_handle
) {
1939 rotation_thread_handle_destroy(rotation_thread_handle
);
1943 * After the rotation and timer thread have quit, we can safely destroy
1944 * the rotation_timer_queue.
1946 rotation_thread_timer_queue_destroy(rotation_timer_queue
);
1948 * The teardown of the notification system is performed after the
1949 * session daemon's teardown in order to allow it to be notified
1950 * of the active session and channels at the moment of the teardown.
1952 if (notification_thread_handle
) {
1953 notification_thread_handle_destroy(notification_thread_handle
);
1955 lttng_pipe_destroy(ust32_channel_monitor_pipe
);
1956 lttng_pipe_destroy(ust64_channel_monitor_pipe
);
1957 lttng_pipe_destroy(kernel_channel_monitor_pipe
);
1959 if (health_sessiond
) {
1960 health_app_destroy(health_sessiond
);
1962 exit_create_run_as_worker_cleanup
:
1964 sessiond_cleanup_lock_file();
1965 sessiond_cleanup_options();
1967 exit_set_signal_handler
: