2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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.
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.
32 #include <sys/mount.h>
33 #include <sys/resource.h>
34 #include <sys/socket.h>
36 #include <sys/types.h>
38 #include <urcu/uatomic.h>
42 #include <common/common.h>
43 #include <common/compat/socket.h>
44 #include <common/compat/getenv.h>
45 #include <common/defaults.h>
46 #include <common/kernel-consumer/kernel-consumer.h>
47 #include <common/futex.h>
48 #include <common/relayd/relayd.h>
49 #include <common/utils.h>
50 #include <common/daemonize.h>
51 #include <common/config/session-config.h>
53 #include "lttng-sessiond.h"
54 #include "buffer-registry.h"
61 #include "kernel-consumer.h"
65 #include "ust-consumer.h"
68 #include "health-sessiond.h"
69 #include "testpoint.h"
70 #include "ust-thread.h"
71 #include "agent-thread.h"
73 #include "load-session-thread.h"
74 #include "notification-thread.h"
75 #include "notification-thread-commands.h"
76 #include "rotation-thread.h"
77 #include "lttng-syscall.h"
79 #include "ht-cleanup.h"
80 #include "sessiond-config.h"
81 #include "sessiond-timer.h"
83 static const char *help_msg
=
84 #ifdef LTTNG_EMBED_HELP
85 #include <lttng-sessiond.8.h>
92 static pid_t ppid
; /* Parent PID for --sig-parent option */
93 static pid_t child_ppid
; /* Internal parent PID use with daemonize. */
94 static int lockfile_fd
= -1;
96 /* Set to 1 when a SIGUSR1 signal is received. */
97 static int recv_child_signal
;
99 static struct lttng_kernel_tracer_version kernel_tracer_version
;
100 static struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version
;
103 * Consumer daemon specific control data. Every value not initialized here is
104 * set to 0 by the static definition.
106 static struct consumer_data kconsumer_data
= {
107 .type
= LTTNG_CONSUMER_KERNEL
,
110 .channel_monitor_pipe
= -1,
111 .channel_rotate_pipe
= -1,
112 .pid_mutex
= PTHREAD_MUTEX_INITIALIZER
,
113 .lock
= PTHREAD_MUTEX_INITIALIZER
,
114 .cond
= PTHREAD_COND_INITIALIZER
,
115 .cond_mutex
= PTHREAD_MUTEX_INITIALIZER
,
117 static struct consumer_data ustconsumer64_data
= {
118 .type
= LTTNG_CONSUMER64_UST
,
121 .channel_monitor_pipe
= -1,
122 .channel_rotate_pipe
= -1,
123 .pid_mutex
= PTHREAD_MUTEX_INITIALIZER
,
124 .lock
= PTHREAD_MUTEX_INITIALIZER
,
125 .cond
= PTHREAD_COND_INITIALIZER
,
126 .cond_mutex
= PTHREAD_MUTEX_INITIALIZER
,
128 static struct consumer_data ustconsumer32_data
= {
129 .type
= LTTNG_CONSUMER32_UST
,
132 .channel_monitor_pipe
= -1,
133 .channel_rotate_pipe
= -1,
134 .pid_mutex
= PTHREAD_MUTEX_INITIALIZER
,
135 .lock
= PTHREAD_MUTEX_INITIALIZER
,
136 .cond
= PTHREAD_COND_INITIALIZER
,
137 .cond_mutex
= PTHREAD_MUTEX_INITIALIZER
,
140 /* Command line options */
141 static const struct option long_options
[] = {
142 { "client-sock", required_argument
, 0, 'c' },
143 { "apps-sock", required_argument
, 0, 'a' },
144 { "kconsumerd-cmd-sock", required_argument
, 0, '\0' },
145 { "kconsumerd-err-sock", required_argument
, 0, '\0' },
146 { "ustconsumerd32-cmd-sock", required_argument
, 0, '\0' },
147 { "ustconsumerd32-err-sock", required_argument
, 0, '\0' },
148 { "ustconsumerd64-cmd-sock", required_argument
, 0, '\0' },
149 { "ustconsumerd64-err-sock", required_argument
, 0, '\0' },
150 { "consumerd32-path", required_argument
, 0, '\0' },
151 { "consumerd32-libdir", required_argument
, 0, '\0' },
152 { "consumerd64-path", required_argument
, 0, '\0' },
153 { "consumerd64-libdir", required_argument
, 0, '\0' },
154 { "daemonize", no_argument
, 0, 'd' },
155 { "background", no_argument
, 0, 'b' },
156 { "sig-parent", no_argument
, 0, 'S' },
157 { "help", no_argument
, 0, 'h' },
158 { "group", required_argument
, 0, 'g' },
159 { "version", no_argument
, 0, 'V' },
160 { "quiet", no_argument
, 0, 'q' },
161 { "verbose", no_argument
, 0, 'v' },
162 { "verbose-consumer", no_argument
, 0, '\0' },
163 { "no-kernel", no_argument
, 0, '\0' },
164 { "pidfile", required_argument
, 0, 'p' },
165 { "agent-tcp-port", required_argument
, 0, '\0' },
166 { "config", required_argument
, 0, 'f' },
167 { "load", required_argument
, 0, 'l' },
168 { "kmod-probes", required_argument
, 0, '\0' },
169 { "extra-kmod-probes", required_argument
, 0, '\0' },
173 struct sessiond_config config
;
175 /* Command line options to ignore from configuration file */
176 static const char *config_ignore_options
[] = { "help", "version", "config" };
178 /* Shared between threads */
179 static int dispatch_thread_exit
;
181 /* Sockets and FDs */
182 static int client_sock
= -1;
183 static int apps_sock
= -1;
184 int kernel_tracer_fd
= -1;
185 static int kernel_poll_pipe
[2] = { -1, -1 };
188 * Quit pipe for all threads. This permits a single cancellation point
189 * for all threads when receiving an event on the pipe.
191 static int thread_quit_pipe
[2] = { -1, -1 };
194 * This pipe is used to inform the thread managing application communication
195 * that a command is queued and ready to be processed.
197 static int apps_cmd_pipe
[2] = { -1, -1 };
199 int apps_cmd_notify_pipe
[2] = { -1, -1 };
201 /* Pthread, Mutexes and Semaphores */
202 static pthread_t apps_thread
;
203 static pthread_t apps_notify_thread
;
204 static pthread_t reg_apps_thread
;
205 static pthread_t client_thread
;
206 static pthread_t kernel_thread
;
207 static pthread_t dispatch_thread
;
208 static pthread_t health_thread
;
209 static pthread_t ht_cleanup_thread
;
210 static pthread_t agent_reg_thread
;
211 static pthread_t load_session_thread
;
212 static pthread_t notification_thread
;
213 static pthread_t rotation_thread
;
214 static pthread_t timer_thread
;
217 * UST registration command queue. This queue is tied with a futex and uses a N
218 * wakers / 1 waiter implemented and detailed in futex.c/.h
220 * The thread_registration_apps and thread_dispatch_ust_registration uses this
221 * queue along with the wait/wake scheme. The thread_manage_apps receives down
222 * the line new application socket and monitors it for any I/O error or clean
223 * close that triggers an unregistration of the application.
225 static struct ust_cmd_queue ust_cmd_queue
;
228 * Pointer initialized before thread creation.
230 * This points to the tracing session list containing the session count and a
231 * mutex lock. The lock MUST be taken if you iterate over the list. The lock
232 * MUST NOT be taken if you call a public function in session.c.
234 * The lock is nested inside the structure: session_list_ptr->lock. Please use
235 * session_lock_list and session_unlock_list for lock acquisition.
237 static struct ltt_session_list
*session_list_ptr
;
239 int ust_consumerd64_fd
= -1;
240 int ust_consumerd32_fd
= -1;
242 static const char *module_proc_lttng
= "/proc/lttng";
245 * Consumer daemon state which is changed when spawning it, killing it or in
246 * case of a fatal error.
248 enum consumerd_state
{
249 CONSUMER_STARTED
= 1,
250 CONSUMER_STOPPED
= 2,
255 * This consumer daemon state is used to validate if a client command will be
256 * able to reach the consumer. If not, the client is informed. For instance,
257 * doing a "lttng start" when the consumer state is set to ERROR will return an
258 * error to the client.
260 * The following example shows a possible race condition of this scheme:
262 * consumer thread error happens
264 * client cmd checks state -> still OK
265 * consumer thread exit, sets error
266 * client cmd try to talk to consumer
269 * However, since the consumer is a different daemon, we have no way of making
270 * sure the command will reach it safely even with this state flag. This is why
271 * we consider that up to the state validation during command processing, the
272 * command is safe. After that, we can not guarantee the correctness of the
273 * client request vis-a-vis the consumer.
275 static enum consumerd_state ust_consumerd_state
;
276 static enum consumerd_state kernel_consumerd_state
;
278 /* Set in main() with the current page size. */
281 /* Application health monitoring */
282 struct health_app
*health_sessiond
;
284 /* Am I root or not. */
285 int is_root
; /* Set to 1 if the daemon is running as root */
287 const char * const config_section_name
= "sessiond";
289 /* Load session thread information to operate. */
290 struct load_session_thread_data
*load_info
;
292 /* Notification thread handle. */
293 struct notification_thread_handle
*notification_thread_handle
;
295 /* Rotation thread handle. */
296 struct rotation_thread_handle
*rotation_thread_handle
;
298 /* Global hash tables */
299 struct lttng_ht
*agent_apps_ht_by_sock
= NULL
;
302 * The initialization of the session daemon is done in multiple phases.
304 * While all threads are launched near-simultaneously, only some of them
305 * are needed to ensure the session daemon can start to respond to client
308 * There are two important guarantees that we wish to offer with respect
309 * to the initialisation of the session daemon:
310 * - When the daemonize/background launcher process exits, the sessiond
311 * is fully able to respond to client requests,
312 * - Auto-loaded sessions are visible to clients.
314 * In order to achieve this, a number of support threads have to be launched
315 * to allow the "client" thread to function properly. Moreover, since the
316 * "load session" thread needs the client thread, we must provide a way
317 * for the "load session" thread to know that the "client" thread is up
320 * Hence, the support threads decrement the lttng_sessiond_ready counter
321 * while the "client" threads waits for it to reach 0. Once the "client" thread
322 * unblocks, it posts the message_thread_ready semaphore which allows the
323 * "load session" thread to progress.
325 * This implies that the "load session" thread is the last to be initialized
326 * and will explicitly call sessiond_signal_parents(), which signals the parents
327 * that the session daemon is fully initialized.
329 * The four (4) support threads are:
331 * - notification_thread
335 int lttng_sessiond_ready
= 4;
337 int sessiond_check_thread_quit_pipe(int fd
, uint32_t events
)
339 return (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
)) ? 1 : 0;
342 /* Notify parents that we are ready for cmd and health check */
344 void sessiond_signal_parents(void)
347 * Notify parent pid that we are ready to accept command
348 * for client side. This ppid is the one from the
349 * external process that spawned us.
351 if (config
.sig_parent
) {
356 * Notify the parent of the fork() process that we are
359 if (config
.daemonize
|| config
.background
) {
360 kill(child_ppid
, SIGUSR1
);
365 void sessiond_notify_ready(void)
368 * The _return variant is used since the implied memory barriers are
371 (void) uatomic_sub_return(<tng_sessiond_ready
, 1);
375 int __sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
,
382 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
388 ret
= lttng_poll_add(events
, a_pipe
[0], LPOLLIN
| LPOLLERR
);
400 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
402 int sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
)
404 return __sessiond_set_thread_pollset(events
, size
, thread_quit_pipe
);
408 * Init thread quit pipe.
410 * Return -1 on error or 0 if all pipes are created.
412 static int __init_thread_quit_pipe(int *a_pipe
)
418 PERROR("thread quit pipe");
422 for (i
= 0; i
< 2; i
++) {
423 ret
= fcntl(a_pipe
[i
], F_SETFD
, FD_CLOEXEC
);
434 static int init_thread_quit_pipe(void)
436 return __init_thread_quit_pipe(thread_quit_pipe
);
440 * Stop all threads by closing the thread quit pipe.
442 static void stop_threads(void)
446 /* Stopping all threads */
447 DBG("Terminating all threads");
448 ret
= notify_thread_pipe(thread_quit_pipe
[1]);
450 ERR("write error on thread quit pipe");
453 /* Dispatch thread */
454 CMM_STORE_SHARED(dispatch_thread_exit
, 1);
455 futex_nto1_wake(&ust_cmd_queue
.futex
);
459 * Close every consumer sockets.
461 static void close_consumer_sockets(void)
465 if (kconsumer_data
.err_sock
>= 0) {
466 ret
= close(kconsumer_data
.err_sock
);
468 PERROR("kernel consumer err_sock close");
471 if (ustconsumer32_data
.err_sock
>= 0) {
472 ret
= close(ustconsumer32_data
.err_sock
);
474 PERROR("UST consumerd32 err_sock close");
477 if (ustconsumer64_data
.err_sock
>= 0) {
478 ret
= close(ustconsumer64_data
.err_sock
);
480 PERROR("UST consumerd64 err_sock close");
483 if (kconsumer_data
.cmd_sock
>= 0) {
484 ret
= close(kconsumer_data
.cmd_sock
);
486 PERROR("kernel consumer cmd_sock close");
489 if (ustconsumer32_data
.cmd_sock
>= 0) {
490 ret
= close(ustconsumer32_data
.cmd_sock
);
492 PERROR("UST consumerd32 cmd_sock close");
495 if (ustconsumer64_data
.cmd_sock
>= 0) {
496 ret
= close(ustconsumer64_data
.cmd_sock
);
498 PERROR("UST consumerd64 cmd_sock close");
501 if (kconsumer_data
.channel_monitor_pipe
>= 0) {
502 ret
= close(kconsumer_data
.channel_monitor_pipe
);
504 PERROR("kernel consumer channel monitor pipe close");
507 if (ustconsumer32_data
.channel_monitor_pipe
>= 0) {
508 ret
= close(ustconsumer32_data
.channel_monitor_pipe
);
510 PERROR("UST consumerd32 channel monitor pipe close");
513 if (ustconsumer64_data
.channel_monitor_pipe
>= 0) {
514 ret
= close(ustconsumer64_data
.channel_monitor_pipe
);
516 PERROR("UST consumerd64 channel monitor pipe close");
519 if (kconsumer_data
.channel_rotate_pipe
>= 0) {
520 ret
= close(kconsumer_data
.channel_rotate_pipe
);
522 PERROR("kernel consumer channel rotate pipe close");
525 if (ustconsumer32_data
.channel_rotate_pipe
>= 0) {
526 ret
= close(ustconsumer32_data
.channel_rotate_pipe
);
528 PERROR("UST consumerd32 channel rotate pipe close");
531 if (ustconsumer64_data
.channel_rotate_pipe
>= 0) {
532 ret
= close(ustconsumer64_data
.channel_rotate_pipe
);
534 PERROR("UST consumerd64 channel rotate pipe close");
540 * Wait on consumer process termination.
542 * Need to be called with the consumer data lock held or from a context
543 * ensuring no concurrent access to data (e.g: cleanup).
545 static void wait_consumer(struct consumer_data
*consumer_data
)
550 if (consumer_data
->pid
<= 0) {
554 DBG("Waiting for complete teardown of consumerd (PID: %d)",
556 ret
= waitpid(consumer_data
->pid
, &status
, 0);
558 PERROR("consumerd waitpid pid: %d", consumer_data
->pid
)
559 } else if (!WIFEXITED(status
)) {
560 ERR("consumerd termination with error: %d",
563 consumer_data
->pid
= 0;
567 * Cleanup the session daemon's data structures.
569 static void sessiond_cleanup(void)
572 struct ltt_session
*sess
, *stmp
;
574 DBG("Cleanup sessiond");
577 * Close the thread quit pipe. It has already done its job,
578 * since we are now called.
580 utils_close_pipe(thread_quit_pipe
);
583 * If config.pid_file_path.value is undefined, the default file will be
584 * wiped when removing the rundir.
586 if (config
.pid_file_path
.value
) {
587 ret
= remove(config
.pid_file_path
.value
);
589 PERROR("remove pidfile %s", config
.pid_file_path
.value
);
593 DBG("Removing sessiond and consumerd content of directory %s",
594 config
.rundir
.value
);
597 DBG("Removing %s", config
.pid_file_path
.value
);
598 (void) unlink(config
.pid_file_path
.value
);
600 DBG("Removing %s", config
.agent_port_file_path
.value
);
601 (void) unlink(config
.agent_port_file_path
.value
);
604 DBG("Removing %s", kconsumer_data
.err_unix_sock_path
);
605 (void) unlink(kconsumer_data
.err_unix_sock_path
);
607 DBG("Removing directory %s", config
.kconsumerd_path
.value
);
608 (void) rmdir(config
.kconsumerd_path
.value
);
610 /* ust consumerd 32 */
611 DBG("Removing %s", config
.consumerd32_err_unix_sock_path
.value
);
612 (void) unlink(config
.consumerd32_err_unix_sock_path
.value
);
614 DBG("Removing directory %s", config
.consumerd32_path
.value
);
615 (void) rmdir(config
.consumerd32_path
.value
);
617 /* ust consumerd 64 */
618 DBG("Removing %s", config
.consumerd64_err_unix_sock_path
.value
);
619 (void) unlink(config
.consumerd64_err_unix_sock_path
.value
);
621 DBG("Removing directory %s", config
.consumerd64_path
.value
);
622 (void) rmdir(config
.consumerd64_path
.value
);
624 DBG("Cleaning up all sessions");
626 /* Destroy session list mutex */
627 if (session_list_ptr
!= NULL
) {
628 pthread_mutex_destroy(&session_list_ptr
->lock
);
630 /* Cleanup ALL session */
631 cds_list_for_each_entry_safe(sess
, stmp
,
632 &session_list_ptr
->head
, list
) {
633 cmd_destroy_session(sess
, kernel_poll_pipe
[1],
634 notification_thread_handle
);
638 wait_consumer(&kconsumer_data
);
639 wait_consumer(&ustconsumer64_data
);
640 wait_consumer(&ustconsumer32_data
);
642 DBG("Cleaning up all agent apps");
643 agent_app_ht_clean();
645 DBG("Closing all UST sockets");
646 ust_app_clean_list();
647 buffer_reg_destroy_registries();
649 if (is_root
&& !config
.no_kernel
) {
650 DBG2("Closing kernel fd");
651 if (kernel_tracer_fd
>= 0) {
652 ret
= close(kernel_tracer_fd
);
657 DBG("Unloading kernel modules");
658 modprobe_remove_lttng_all();
662 close_consumer_sockets();
665 load_session_destroy_data(load_info
);
670 * We do NOT rmdir rundir because there are other processes
671 * using it, for instance lttng-relayd, which can start in
672 * parallel with this teardown.
677 * Cleanup the daemon's option data structures.
679 static void sessiond_cleanup_options(void)
681 DBG("Cleaning up options");
683 sessiond_config_fini(&config
);
685 run_as_destroy_worker();
689 * Send data on a unix socket using the liblttsessiondcomm API.
691 * Return lttcomm error code.
693 static int send_unix_sock(int sock
, void *buf
, size_t len
)
695 /* Check valid length */
700 return lttcomm_send_unix_sock(sock
, buf
, len
);
704 * Free memory of a command context structure.
706 static void clean_command_ctx(struct command_ctx
**cmd_ctx
)
708 DBG("Clean command context structure");
710 if ((*cmd_ctx
)->llm
) {
711 free((*cmd_ctx
)->llm
);
713 if ((*cmd_ctx
)->lsm
) {
714 free((*cmd_ctx
)->lsm
);
722 * Notify UST applications using the shm mmap futex.
724 static int notify_ust_apps(int active
)
728 DBG("Notifying applications of session daemon state: %d", active
);
730 /* See shm.c for this call implying mmap, shm and futex calls */
731 wait_shm_mmap
= shm_ust_get_mmap(config
.wait_shm_path
.value
, is_root
);
732 if (wait_shm_mmap
== NULL
) {
736 /* Wake waiting process */
737 futex_wait_update((int32_t *) wait_shm_mmap
, active
);
739 /* Apps notified successfully */
747 * Setup the outgoing data buffer for the response (llm) by allocating the
748 * right amount of memory and copying the original information from the lsm
751 * Return 0 on success, negative value on error.
753 static int setup_lttng_msg(struct command_ctx
*cmd_ctx
,
754 const void *payload_buf
, size_t payload_len
,
755 const void *cmd_header_buf
, size_t cmd_header_len
)
758 const size_t header_len
= sizeof(struct lttcomm_lttng_msg
);
759 const size_t cmd_header_offset
= header_len
;
760 const size_t payload_offset
= cmd_header_offset
+ cmd_header_len
;
761 const size_t total_msg_size
= header_len
+ cmd_header_len
+ payload_len
;
763 cmd_ctx
->llm
= zmalloc(total_msg_size
);
765 if (cmd_ctx
->llm
== NULL
) {
771 /* Copy common data */
772 cmd_ctx
->llm
->cmd_type
= cmd_ctx
->lsm
->cmd_type
;
773 cmd_ctx
->llm
->pid
= cmd_ctx
->lsm
->domain
.attr
.pid
;
774 cmd_ctx
->llm
->cmd_header_size
= cmd_header_len
;
775 cmd_ctx
->llm
->data_size
= payload_len
;
776 cmd_ctx
->lttng_msg_size
= total_msg_size
;
778 /* Copy command header */
779 if (cmd_header_len
) {
780 memcpy(((uint8_t *) cmd_ctx
->llm
) + cmd_header_offset
, cmd_header_buf
,
786 memcpy(((uint8_t *) cmd_ctx
->llm
) + payload_offset
, payload_buf
,
795 * Version of setup_lttng_msg() without command header.
797 static int setup_lttng_msg_no_cmd_header(struct command_ctx
*cmd_ctx
,
798 void *payload_buf
, size_t payload_len
)
800 return setup_lttng_msg(cmd_ctx
, payload_buf
, payload_len
, NULL
, 0);
803 * Update the kernel poll set of all channel fd available over all tracing
804 * session. Add the wakeup pipe at the end of the set.
806 static int update_kernel_poll(struct lttng_poll_event
*events
)
809 struct ltt_session
*session
;
810 struct ltt_kernel_channel
*channel
;
812 DBG("Updating kernel poll set");
815 cds_list_for_each_entry(session
, &session_list_ptr
->head
, list
) {
816 session_lock(session
);
817 if (session
->kernel_session
== NULL
) {
818 session_unlock(session
);
822 cds_list_for_each_entry(channel
,
823 &session
->kernel_session
->channel_list
.head
, list
) {
824 /* Add channel fd to the kernel poll set */
825 ret
= lttng_poll_add(events
, channel
->fd
, LPOLLIN
| LPOLLRDNORM
);
827 session_unlock(session
);
830 DBG("Channel fd %d added to kernel set", channel
->fd
);
832 session_unlock(session
);
834 session_unlock_list();
839 session_unlock_list();
844 * Find the channel fd from 'fd' over all tracing session. When found, check
845 * for new channel stream and send those stream fds to the kernel consumer.
847 * Useful for CPU hotplug feature.
849 static int update_kernel_stream(struct consumer_data
*consumer_data
, int fd
)
852 struct ltt_session
*session
;
853 struct ltt_kernel_session
*ksess
;
854 struct ltt_kernel_channel
*channel
;
856 DBG("Updating kernel streams for channel fd %d", fd
);
859 cds_list_for_each_entry(session
, &session_list_ptr
->head
, list
) {
860 session_lock(session
);
861 if (session
->kernel_session
== NULL
) {
862 session_unlock(session
);
865 ksess
= session
->kernel_session
;
867 cds_list_for_each_entry(channel
,
868 &ksess
->channel_list
.head
, list
) {
869 struct lttng_ht_iter iter
;
870 struct consumer_socket
*socket
;
872 if (channel
->fd
!= fd
) {
875 DBG("Channel found, updating kernel streams");
876 ret
= kernel_open_channel_stream(channel
);
880 /* Update the stream global counter */
881 ksess
->stream_count_global
+= ret
;
884 * Have we already sent fds to the consumer? If yes, it
885 * means that tracing is started so it is safe to send
886 * our updated stream fds.
888 if (ksess
->consumer_fds_sent
!= 1
889 || ksess
->consumer
== NULL
) {
895 cds_lfht_for_each_entry(ksess
->consumer
->socks
->ht
,
896 &iter
.iter
, socket
, node
.node
) {
897 pthread_mutex_lock(socket
->lock
);
898 ret
= kernel_consumer_send_channel_streams(socket
,
900 session
->output_traces
? 1 : 0);
901 pthread_mutex_unlock(socket
->lock
);
909 session_unlock(session
);
911 session_unlock_list();
915 session_unlock(session
);
916 session_unlock_list();
921 * For each tracing session, update newly registered apps. The session list
922 * lock MUST be acquired before calling this.
924 static void update_ust_app(int app_sock
)
926 struct ltt_session
*sess
, *stmp
;
928 /* Consumer is in an ERROR state. Stop any application update. */
929 if (uatomic_read(&ust_consumerd_state
) == CONSUMER_ERROR
) {
930 /* Stop the update process since the consumer is dead. */
934 /* For all tracing session(s) */
935 cds_list_for_each_entry_safe(sess
, stmp
, &session_list_ptr
->head
, list
) {
939 if (!sess
->ust_session
) {
944 assert(app_sock
>= 0);
945 app
= ust_app_find_by_sock(app_sock
);
948 * Application can be unregistered before so
949 * this is possible hence simply stopping the
952 DBG3("UST app update failed to find app sock %d",
956 ust_app_global_update(sess
->ust_session
, app
);
960 session_unlock(sess
);
965 * This thread manage event coming from the kernel.
967 * Features supported in this thread:
970 static void *thread_manage_kernel(void *data
)
972 int ret
, i
, pollfd
, update_poll_flag
= 1, err
= -1;
973 uint32_t revents
, nb_fd
;
975 struct lttng_poll_event events
;
977 DBG("[thread] Thread manage kernel started");
979 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_KERNEL
);
982 * This first step of the while is to clean this structure which could free
983 * non NULL pointers so initialize it before the loop.
985 lttng_poll_init(&events
);
987 if (testpoint(sessiond_thread_manage_kernel
)) {
988 goto error_testpoint
;
991 health_code_update();
993 if (testpoint(sessiond_thread_manage_kernel_before_loop
)) {
994 goto error_testpoint
;
998 health_code_update();
1000 if (update_poll_flag
== 1) {
1001 /* Clean events object. We are about to populate it again. */
1002 lttng_poll_clean(&events
);
1004 ret
= sessiond_set_thread_pollset(&events
, 2);
1006 goto error_poll_create
;
1009 ret
= lttng_poll_add(&events
, kernel_poll_pipe
[0], LPOLLIN
);
1014 /* This will add the available kernel channel if any. */
1015 ret
= update_kernel_poll(&events
);
1019 update_poll_flag
= 0;
1022 DBG("Thread kernel polling");
1024 /* Poll infinite value of time */
1026 health_poll_entry();
1027 ret
= lttng_poll_wait(&events
, -1);
1028 DBG("Thread kernel return from poll on %d fds",
1029 LTTNG_POLL_GETNB(&events
));
1033 * Restart interrupted system call.
1035 if (errno
== EINTR
) {
1039 } else if (ret
== 0) {
1040 /* Should not happen since timeout is infinite */
1041 ERR("Return value of poll is 0 with an infinite timeout.\n"
1042 "This should not have happened! Continuing...");
1048 for (i
= 0; i
< nb_fd
; i
++) {
1049 /* Fetch once the poll data */
1050 revents
= LTTNG_POLL_GETEV(&events
, i
);
1051 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1053 health_code_update();
1056 /* No activity for this FD (poll implementation). */
1060 /* Thread quit pipe has been closed. Killing thread. */
1061 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
1067 /* Check for data on kernel pipe */
1068 if (revents
& LPOLLIN
) {
1069 if (pollfd
== kernel_poll_pipe
[0]) {
1070 (void) lttng_read(kernel_poll_pipe
[0],
1073 * Ret value is useless here, if this pipe gets any actions an
1074 * update is required anyway.
1076 update_poll_flag
= 1;
1080 * New CPU detected by the kernel. Adding kernel stream to
1081 * kernel session and updating the kernel consumer
1083 ret
= update_kernel_stream(&kconsumer_data
, pollfd
);
1089 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1090 update_poll_flag
= 1;
1093 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
1101 lttng_poll_clean(&events
);
1104 utils_close_pipe(kernel_poll_pipe
);
1105 kernel_poll_pipe
[0] = kernel_poll_pipe
[1] = -1;
1108 ERR("Health error occurred in %s", __func__
);
1109 WARN("Kernel thread died unexpectedly. "
1110 "Kernel tracing can continue but CPU hotplug is disabled.");
1112 health_unregister(health_sessiond
);
1113 DBG("Kernel thread dying");
1118 * Signal pthread condition of the consumer data that the thread.
1120 static void signal_consumer_condition(struct consumer_data
*data
, int state
)
1122 pthread_mutex_lock(&data
->cond_mutex
);
1125 * The state is set before signaling. It can be any value, it's the waiter
1126 * job to correctly interpret this condition variable associated to the
1127 * consumer pthread_cond.
1129 * A value of 0 means that the corresponding thread of the consumer data
1130 * was not started. 1 indicates that the thread has started and is ready
1131 * for action. A negative value means that there was an error during the
1134 data
->consumer_thread_is_ready
= state
;
1135 (void) pthread_cond_signal(&data
->cond
);
1137 pthread_mutex_unlock(&data
->cond_mutex
);
1141 * This thread manage the consumer error sent back to the session daemon.
1143 static void *thread_manage_consumer(void *data
)
1145 int sock
= -1, i
, ret
, pollfd
, err
= -1, should_quit
= 0;
1146 uint32_t revents
, nb_fd
;
1147 enum lttcomm_return_code code
;
1148 struct lttng_poll_event events
;
1149 struct consumer_data
*consumer_data
= data
;
1150 struct consumer_socket
*cmd_socket_wrapper
= NULL
;
1152 DBG("[thread] Manage consumer started");
1154 rcu_register_thread();
1155 rcu_thread_online();
1157 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_CONSUMER
);
1159 health_code_update();
1162 * Pass 3 as size here for the thread quit pipe, consumerd_err_sock and the
1163 * metadata_sock. Nothing more will be added to this poll set.
1165 ret
= sessiond_set_thread_pollset(&events
, 3);
1171 * The error socket here is already in a listening state which was done
1172 * just before spawning this thread to avoid a race between the consumer
1173 * daemon exec trying to connect and the listen() call.
1175 ret
= lttng_poll_add(&events
, consumer_data
->err_sock
, LPOLLIN
| LPOLLRDHUP
);
1180 health_code_update();
1182 /* Infinite blocking call, waiting for transmission */
1184 health_poll_entry();
1186 if (testpoint(sessiond_thread_manage_consumer
)) {
1190 ret
= lttng_poll_wait(&events
, -1);
1194 * Restart interrupted system call.
1196 if (errno
== EINTR
) {
1204 for (i
= 0; i
< nb_fd
; i
++) {
1205 /* Fetch once the poll data */
1206 revents
= LTTNG_POLL_GETEV(&events
, i
);
1207 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1209 health_code_update();
1212 /* No activity for this FD (poll implementation). */
1216 /* Thread quit pipe has been closed. Killing thread. */
1217 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
1223 /* Event on the registration socket */
1224 if (pollfd
== consumer_data
->err_sock
) {
1225 if (revents
& LPOLLIN
) {
1227 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1228 ERR("consumer err socket poll error");
1231 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
1237 sock
= lttcomm_accept_unix_sock(consumer_data
->err_sock
);
1243 * Set the CLOEXEC flag. Return code is useless because either way, the
1246 (void) utils_set_fd_cloexec(sock
);
1248 health_code_update();
1250 DBG2("Receiving code from consumer err_sock");
1252 /* Getting status code from kconsumerd */
1253 ret
= lttcomm_recv_unix_sock(sock
, &code
,
1254 sizeof(enum lttcomm_return_code
));
1259 health_code_update();
1260 if (code
!= LTTCOMM_CONSUMERD_COMMAND_SOCK_READY
) {
1261 ERR("consumer error when waiting for SOCK_READY : %s",
1262 lttcomm_get_readable_code(-code
));
1266 /* Connect both command and metadata sockets. */
1267 consumer_data
->cmd_sock
=
1268 lttcomm_connect_unix_sock(
1269 consumer_data
->cmd_unix_sock_path
);
1270 consumer_data
->metadata_fd
=
1271 lttcomm_connect_unix_sock(
1272 consumer_data
->cmd_unix_sock_path
);
1273 if (consumer_data
->cmd_sock
< 0 || consumer_data
->metadata_fd
< 0) {
1274 PERROR("consumer connect cmd socket");
1275 /* On error, signal condition and quit. */
1276 signal_consumer_condition(consumer_data
, -1);
1280 consumer_data
->metadata_sock
.fd_ptr
= &consumer_data
->metadata_fd
;
1282 /* Create metadata socket lock. */
1283 consumer_data
->metadata_sock
.lock
= zmalloc(sizeof(pthread_mutex_t
));
1284 if (consumer_data
->metadata_sock
.lock
== NULL
) {
1285 PERROR("zmalloc pthread mutex");
1288 pthread_mutex_init(consumer_data
->metadata_sock
.lock
, NULL
);
1290 DBG("Consumer command socket ready (fd: %d", consumer_data
->cmd_sock
);
1291 DBG("Consumer metadata socket ready (fd: %d)",
1292 consumer_data
->metadata_fd
);
1295 * Remove the consumerd error sock since we've established a connection.
1297 ret
= lttng_poll_del(&events
, consumer_data
->err_sock
);
1302 /* Add new accepted error socket. */
1303 ret
= lttng_poll_add(&events
, sock
, LPOLLIN
| LPOLLRDHUP
);
1308 /* Add metadata socket that is successfully connected. */
1309 ret
= lttng_poll_add(&events
, consumer_data
->metadata_fd
,
1310 LPOLLIN
| LPOLLRDHUP
);
1315 health_code_update();
1318 * Transfer the write-end of the channel monitoring and rotate pipe
1319 * to the consumer by issuing a SET_CHANNEL_MONITOR_PIPE and
1320 * SET_CHANNEL_ROTATE_PIPE commands.
1322 cmd_socket_wrapper
= consumer_allocate_socket(&consumer_data
->cmd_sock
);
1323 if (!cmd_socket_wrapper
) {
1326 cmd_socket_wrapper
->lock
= &consumer_data
->lock
;
1328 ret
= consumer_send_channel_monitor_pipe(cmd_socket_wrapper
,
1329 consumer_data
->channel_monitor_pipe
);
1334 ret
= consumer_send_channel_rotate_pipe(cmd_socket_wrapper
,
1335 consumer_data
->channel_rotate_pipe
);
1340 /* Discard the socket wrapper as it is no longer needed. */
1341 consumer_destroy_socket(cmd_socket_wrapper
);
1342 cmd_socket_wrapper
= NULL
;
1344 /* The thread is completely initialized, signal that it is ready. */
1345 signal_consumer_condition(consumer_data
, 1);
1347 /* Infinite blocking call, waiting for transmission */
1350 health_code_update();
1352 /* Exit the thread because the thread quit pipe has been triggered. */
1354 /* Not a health error. */
1359 health_poll_entry();
1360 ret
= lttng_poll_wait(&events
, -1);
1364 * Restart interrupted system call.
1366 if (errno
== EINTR
) {
1374 for (i
= 0; i
< nb_fd
; i
++) {
1375 /* Fetch once the poll data */
1376 revents
= LTTNG_POLL_GETEV(&events
, i
);
1377 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1379 health_code_update();
1382 /* No activity for this FD (poll implementation). */
1387 * Thread quit pipe has been triggered, flag that we should stop
1388 * but continue the current loop to handle potential data from
1391 should_quit
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
1393 if (pollfd
== sock
) {
1394 /* Event on the consumerd socket */
1395 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)
1396 && !(revents
& LPOLLIN
)) {
1397 ERR("consumer err socket second poll error");
1400 health_code_update();
1401 /* Wait for any kconsumerd error */
1402 ret
= lttcomm_recv_unix_sock(sock
, &code
,
1403 sizeof(enum lttcomm_return_code
));
1405 ERR("consumer closed the command socket");
1409 ERR("consumer return code : %s",
1410 lttcomm_get_readable_code(-code
));
1413 } else if (pollfd
== consumer_data
->metadata_fd
) {
1414 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)
1415 && !(revents
& LPOLLIN
)) {
1416 ERR("consumer err metadata socket second poll error");
1419 /* UST metadata requests */
1420 ret
= ust_consumer_metadata_request(
1421 &consumer_data
->metadata_sock
);
1423 ERR("Handling metadata request");
1427 /* No need for an else branch all FDs are tested prior. */
1429 health_code_update();
1435 * We lock here because we are about to close the sockets and some other
1436 * thread might be using them so get exclusive access which will abort all
1437 * other consumer command by other threads.
1439 pthread_mutex_lock(&consumer_data
->lock
);
1441 /* Immediately set the consumerd state to stopped */
1442 if (consumer_data
->type
== LTTNG_CONSUMER_KERNEL
) {
1443 uatomic_set(&kernel_consumerd_state
, CONSUMER_ERROR
);
1444 } else if (consumer_data
->type
== LTTNG_CONSUMER64_UST
||
1445 consumer_data
->type
== LTTNG_CONSUMER32_UST
) {
1446 uatomic_set(&ust_consumerd_state
, CONSUMER_ERROR
);
1448 /* Code flow error... */
1452 if (consumer_data
->err_sock
>= 0) {
1453 ret
= close(consumer_data
->err_sock
);
1457 consumer_data
->err_sock
= -1;
1459 if (consumer_data
->cmd_sock
>= 0) {
1460 ret
= close(consumer_data
->cmd_sock
);
1464 consumer_data
->cmd_sock
= -1;
1466 if (consumer_data
->metadata_sock
.fd_ptr
&&
1467 *consumer_data
->metadata_sock
.fd_ptr
>= 0) {
1468 ret
= close(*consumer_data
->metadata_sock
.fd_ptr
);
1480 unlink(consumer_data
->err_unix_sock_path
);
1481 unlink(consumer_data
->cmd_unix_sock_path
);
1482 pthread_mutex_unlock(&consumer_data
->lock
);
1484 /* Cleanup metadata socket mutex. */
1485 if (consumer_data
->metadata_sock
.lock
) {
1486 pthread_mutex_destroy(consumer_data
->metadata_sock
.lock
);
1487 free(consumer_data
->metadata_sock
.lock
);
1489 lttng_poll_clean(&events
);
1491 if (cmd_socket_wrapper
) {
1492 consumer_destroy_socket(cmd_socket_wrapper
);
1497 ERR("Health error occurred in %s", __func__
);
1499 health_unregister(health_sessiond
);
1500 DBG("consumer thread cleanup completed");
1502 rcu_thread_offline();
1503 rcu_unregister_thread();
1509 * This thread receives application command sockets (FDs) on the
1510 * apps_cmd_pipe and waits (polls) on them until they are closed
1511 * or an error occurs.
1513 * At that point, it flushes the data (tracing and metadata) associated
1514 * with this application and tears down ust app sessions and other
1515 * associated data structures through ust_app_unregister().
1517 * Note that this thread never sends commands to the applications
1518 * through the command sockets; it merely listens for hang-ups
1519 * and errors on those sockets and cleans-up as they occur.
1521 static void *thread_manage_apps(void *data
)
1523 int i
, ret
, pollfd
, err
= -1;
1525 uint32_t revents
, nb_fd
;
1526 struct lttng_poll_event events
;
1528 DBG("[thread] Manage application started");
1530 rcu_register_thread();
1531 rcu_thread_online();
1533 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_APP_MANAGE
);
1535 if (testpoint(sessiond_thread_manage_apps
)) {
1536 goto error_testpoint
;
1539 health_code_update();
1541 ret
= sessiond_set_thread_pollset(&events
, 2);
1543 goto error_poll_create
;
1546 ret
= lttng_poll_add(&events
, apps_cmd_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
1551 if (testpoint(sessiond_thread_manage_apps_before_loop
)) {
1555 health_code_update();
1558 DBG("Apps thread polling");
1560 /* Inifinite blocking call, waiting for transmission */
1562 health_poll_entry();
1563 ret
= lttng_poll_wait(&events
, -1);
1564 DBG("Apps thread return from poll on %d fds",
1565 LTTNG_POLL_GETNB(&events
));
1569 * Restart interrupted system call.
1571 if (errno
== EINTR
) {
1579 for (i
= 0; i
< nb_fd
; i
++) {
1580 /* Fetch once the poll data */
1581 revents
= LTTNG_POLL_GETEV(&events
, i
);
1582 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1584 health_code_update();
1587 /* No activity for this FD (poll implementation). */
1591 /* Thread quit pipe has been closed. Killing thread. */
1592 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
1598 /* Inspect the apps cmd pipe */
1599 if (pollfd
== apps_cmd_pipe
[0]) {
1600 if (revents
& LPOLLIN
) {
1604 size_ret
= lttng_read(apps_cmd_pipe
[0], &sock
, sizeof(sock
));
1605 if (size_ret
< sizeof(sock
)) {
1606 PERROR("read apps cmd pipe");
1610 health_code_update();
1613 * Since this is a command socket (write then read),
1614 * we only monitor the error events of the socket.
1616 ret
= lttng_poll_add(&events
, sock
,
1617 LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
);
1622 DBG("Apps with sock %d added to poll set", sock
);
1623 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1624 ERR("Apps command pipe error");
1627 ERR("Unknown poll events %u for sock %d", revents
, pollfd
);
1632 * At this point, we know that a registered application made
1633 * the event at poll_wait.
1635 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1636 /* Removing from the poll set */
1637 ret
= lttng_poll_del(&events
, pollfd
);
1642 /* Socket closed on remote end. */
1643 ust_app_unregister(pollfd
);
1645 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
1650 health_code_update();
1656 lttng_poll_clean(&events
);
1659 utils_close_pipe(apps_cmd_pipe
);
1660 apps_cmd_pipe
[0] = apps_cmd_pipe
[1] = -1;
1663 * We don't clean the UST app hash table here since already registered
1664 * applications can still be controlled so let them be until the session
1665 * daemon dies or the applications stop.
1670 ERR("Health error occurred in %s", __func__
);
1672 health_unregister(health_sessiond
);
1673 DBG("Application communication apps thread cleanup complete");
1674 rcu_thread_offline();
1675 rcu_unregister_thread();
1680 * Send a socket to a thread This is called from the dispatch UST registration
1681 * thread once all sockets are set for the application.
1683 * The sock value can be invalid, we don't really care, the thread will handle
1684 * it and make the necessary cleanup if so.
1686 * On success, return 0 else a negative value being the errno message of the
1689 static int send_socket_to_thread(int fd
, int sock
)
1694 * It's possible that the FD is set as invalid with -1 concurrently just
1695 * before calling this function being a shutdown state of the thread.
1702 ret
= lttng_write(fd
, &sock
, sizeof(sock
));
1703 if (ret
< sizeof(sock
)) {
1704 PERROR("write apps pipe %d", fd
);
1711 /* All good. Don't send back the write positive ret value. */
1718 * Sanitize the wait queue of the dispatch registration thread meaning removing
1719 * invalid nodes from it. This is to avoid memory leaks for the case the UST
1720 * notify socket is never received.
1722 static void sanitize_wait_queue(struct ust_reg_wait_queue
*wait_queue
)
1724 int ret
, nb_fd
= 0, i
;
1725 unsigned int fd_added
= 0;
1726 struct lttng_poll_event events
;
1727 struct ust_reg_wait_node
*wait_node
= NULL
, *tmp_wait_node
;
1731 lttng_poll_init(&events
);
1733 /* Just skip everything for an empty queue. */
1734 if (!wait_queue
->count
) {
1738 ret
= lttng_poll_create(&events
, wait_queue
->count
, LTTNG_CLOEXEC
);
1743 cds_list_for_each_entry_safe(wait_node
, tmp_wait_node
,
1744 &wait_queue
->head
, head
) {
1745 assert(wait_node
->app
);
1746 ret
= lttng_poll_add(&events
, wait_node
->app
->sock
,
1747 LPOLLHUP
| LPOLLERR
);
1760 * Poll but don't block so we can quickly identify the faulty events and
1761 * clean them afterwards from the wait queue.
1763 ret
= lttng_poll_wait(&events
, 0);
1769 for (i
= 0; i
< nb_fd
; i
++) {
1770 /* Get faulty FD. */
1771 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
1772 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1775 /* No activity for this FD (poll implementation). */
1779 cds_list_for_each_entry_safe(wait_node
, tmp_wait_node
,
1780 &wait_queue
->head
, head
) {
1781 if (pollfd
== wait_node
->app
->sock
&&
1782 (revents
& (LPOLLHUP
| LPOLLERR
))) {
1783 cds_list_del(&wait_node
->head
);
1784 wait_queue
->count
--;
1785 ust_app_destroy(wait_node
->app
);
1788 * Silence warning of use-after-free in
1789 * cds_list_for_each_entry_safe which uses
1790 * __typeof__(*wait_node).
1795 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
1802 DBG("Wait queue sanitized, %d node were cleaned up", nb_fd
);
1806 lttng_poll_clean(&events
);
1810 lttng_poll_clean(&events
);
1812 ERR("Unable to sanitize wait queue");
1817 * Dispatch request from the registration threads to the application
1818 * communication thread.
1820 static void *thread_dispatch_ust_registration(void *data
)
1823 struct cds_wfcq_node
*node
;
1824 struct ust_command
*ust_cmd
= NULL
;
1825 struct ust_reg_wait_node
*wait_node
= NULL
, *tmp_wait_node
;
1826 struct ust_reg_wait_queue wait_queue
= {
1830 rcu_register_thread();
1832 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_APP_REG_DISPATCH
);
1834 if (testpoint(sessiond_thread_app_reg_dispatch
)) {
1835 goto error_testpoint
;
1838 health_code_update();
1840 CDS_INIT_LIST_HEAD(&wait_queue
.head
);
1842 DBG("[thread] Dispatch UST command started");
1845 health_code_update();
1847 /* Atomically prepare the queue futex */
1848 futex_nto1_prepare(&ust_cmd_queue
.futex
);
1850 if (CMM_LOAD_SHARED(dispatch_thread_exit
)) {
1855 struct ust_app
*app
= NULL
;
1859 * Make sure we don't have node(s) that have hung up before receiving
1860 * the notify socket. This is to clean the list in order to avoid
1861 * memory leaks from notify socket that are never seen.
1863 sanitize_wait_queue(&wait_queue
);
1865 health_code_update();
1866 /* Dequeue command for registration */
1867 node
= cds_wfcq_dequeue_blocking(&ust_cmd_queue
.head
, &ust_cmd_queue
.tail
);
1869 DBG("Woken up but nothing in the UST command queue");
1870 /* Continue thread execution */
1874 ust_cmd
= caa_container_of(node
, struct ust_command
, node
);
1876 DBG("Dispatching UST registration pid:%d ppid:%d uid:%d"
1877 " gid:%d sock:%d name:%s (version %d.%d)",
1878 ust_cmd
->reg_msg
.pid
, ust_cmd
->reg_msg
.ppid
,
1879 ust_cmd
->reg_msg
.uid
, ust_cmd
->reg_msg
.gid
,
1880 ust_cmd
->sock
, ust_cmd
->reg_msg
.name
,
1881 ust_cmd
->reg_msg
.major
, ust_cmd
->reg_msg
.minor
);
1883 if (ust_cmd
->reg_msg
.type
== USTCTL_SOCKET_CMD
) {
1884 wait_node
= zmalloc(sizeof(*wait_node
));
1886 PERROR("zmalloc wait_node dispatch");
1887 ret
= close(ust_cmd
->sock
);
1889 PERROR("close ust sock dispatch %d", ust_cmd
->sock
);
1891 lttng_fd_put(LTTNG_FD_APPS
, 1);
1895 CDS_INIT_LIST_HEAD(&wait_node
->head
);
1897 /* Create application object if socket is CMD. */
1898 wait_node
->app
= ust_app_create(&ust_cmd
->reg_msg
,
1900 if (!wait_node
->app
) {
1901 ret
= close(ust_cmd
->sock
);
1903 PERROR("close ust sock dispatch %d", ust_cmd
->sock
);
1905 lttng_fd_put(LTTNG_FD_APPS
, 1);
1911 * Add application to the wait queue so we can set the notify
1912 * socket before putting this object in the global ht.
1914 cds_list_add(&wait_node
->head
, &wait_queue
.head
);
1919 * We have to continue here since we don't have the notify
1920 * socket and the application MUST be added to the hash table
1921 * only at that moment.
1926 * Look for the application in the local wait queue and set the
1927 * notify socket if found.
1929 cds_list_for_each_entry_safe(wait_node
, tmp_wait_node
,
1930 &wait_queue
.head
, head
) {
1931 health_code_update();
1932 if (wait_node
->app
->pid
== ust_cmd
->reg_msg
.pid
) {
1933 wait_node
->app
->notify_sock
= ust_cmd
->sock
;
1934 cds_list_del(&wait_node
->head
);
1936 app
= wait_node
->app
;
1938 DBG3("UST app notify socket %d is set", ust_cmd
->sock
);
1944 * With no application at this stage the received socket is
1945 * basically useless so close it before we free the cmd data
1946 * structure for good.
1949 ret
= close(ust_cmd
->sock
);
1951 PERROR("close ust sock dispatch %d", ust_cmd
->sock
);
1953 lttng_fd_put(LTTNG_FD_APPS
, 1);
1960 * @session_lock_list
1962 * Lock the global session list so from the register up to the
1963 * registration done message, no thread can see the application
1964 * and change its state.
1966 session_lock_list();
1970 * Add application to the global hash table. This needs to be
1971 * done before the update to the UST registry can locate the
1976 /* Set app version. This call will print an error if needed. */
1977 (void) ust_app_version(app
);
1979 /* Send notify socket through the notify pipe. */
1980 ret
= send_socket_to_thread(apps_cmd_notify_pipe
[1],
1984 session_unlock_list();
1986 * No notify thread, stop the UST tracing. However, this is
1987 * not an internal error of the this thread thus setting
1988 * the health error code to a normal exit.
1995 * Update newly registered application with the tracing
1996 * registry info already enabled information.
1998 update_ust_app(app
->sock
);
2001 * Don't care about return value. Let the manage apps threads
2002 * handle app unregistration upon socket close.
2004 (void) ust_app_register_done(app
);
2007 * Even if the application socket has been closed, send the app
2008 * to the thread and unregistration will take place at that
2011 ret
= send_socket_to_thread(apps_cmd_pipe
[1], app
->sock
);
2014 session_unlock_list();
2016 * No apps. thread, stop the UST tracing. However, this is
2017 * not an internal error of the this thread thus setting
2018 * the health error code to a normal exit.
2025 session_unlock_list();
2027 } while (node
!= NULL
);
2029 health_poll_entry();
2030 /* Futex wait on queue. Blocking call on futex() */
2031 futex_nto1_wait(&ust_cmd_queue
.futex
);
2034 /* Normal exit, no error */
2038 /* Clean up wait queue. */
2039 cds_list_for_each_entry_safe(wait_node
, tmp_wait_node
,
2040 &wait_queue
.head
, head
) {
2041 cds_list_del(&wait_node
->head
);
2046 /* Empty command queue. */
2048 /* Dequeue command for registration */
2049 node
= cds_wfcq_dequeue_blocking(&ust_cmd_queue
.head
, &ust_cmd_queue
.tail
);
2053 ust_cmd
= caa_container_of(node
, struct ust_command
, node
);
2054 ret
= close(ust_cmd
->sock
);
2056 PERROR("close ust sock exit dispatch %d", ust_cmd
->sock
);
2058 lttng_fd_put(LTTNG_FD_APPS
, 1);
2063 DBG("Dispatch thread dying");
2066 ERR("Health error occurred in %s", __func__
);
2068 health_unregister(health_sessiond
);
2069 rcu_unregister_thread();
2074 * This thread manage application registration.
2076 static void *thread_registration_apps(void *data
)
2078 int sock
= -1, i
, ret
, pollfd
, err
= -1;
2079 uint32_t revents
, nb_fd
;
2080 struct lttng_poll_event events
;
2082 * Get allocated in this thread, enqueued to a global queue, dequeued and
2083 * freed in the manage apps thread.
2085 struct ust_command
*ust_cmd
= NULL
;
2087 DBG("[thread] Manage application registration started");
2089 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_APP_REG
);
2091 if (testpoint(sessiond_thread_registration_apps
)) {
2092 goto error_testpoint
;
2095 ret
= lttcomm_listen_unix_sock(apps_sock
);
2101 * Pass 2 as size here for the thread quit pipe and apps socket. Nothing
2102 * more will be added to this poll set.
2104 ret
= sessiond_set_thread_pollset(&events
, 2);
2106 goto error_create_poll
;
2109 /* Add the application registration socket */
2110 ret
= lttng_poll_add(&events
, apps_sock
, LPOLLIN
| LPOLLRDHUP
);
2112 goto error_poll_add
;
2115 /* Notify all applications to register */
2116 ret
= notify_ust_apps(1);
2118 ERR("Failed to notify applications or create the wait shared memory.\n"
2119 "Execution continues but there might be problem for already\n"
2120 "running applications that wishes to register.");
2124 DBG("Accepting application registration");
2126 /* Inifinite blocking call, waiting for transmission */
2128 health_poll_entry();
2129 ret
= lttng_poll_wait(&events
, -1);
2133 * Restart interrupted system call.
2135 if (errno
== EINTR
) {
2143 for (i
= 0; i
< nb_fd
; i
++) {
2144 health_code_update();
2146 /* Fetch once the poll data */
2147 revents
= LTTNG_POLL_GETEV(&events
, i
);
2148 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2151 /* No activity for this FD (poll implementation). */
2155 /* Thread quit pipe has been closed. Killing thread. */
2156 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
2162 /* Event on the registration socket */
2163 if (pollfd
== apps_sock
) {
2164 if (revents
& LPOLLIN
) {
2165 sock
= lttcomm_accept_unix_sock(apps_sock
);
2171 * Set socket timeout for both receiving and ending.
2172 * app_socket_timeout is in seconds, whereas
2173 * lttcomm_setsockopt_rcv_timeout and
2174 * lttcomm_setsockopt_snd_timeout expect msec as
2177 if (config
.app_socket_timeout
>= 0) {
2178 (void) lttcomm_setsockopt_rcv_timeout(sock
,
2179 config
.app_socket_timeout
* 1000);
2180 (void) lttcomm_setsockopt_snd_timeout(sock
,
2181 config
.app_socket_timeout
* 1000);
2185 * Set the CLOEXEC flag. Return code is useless because
2186 * either way, the show must go on.
2188 (void) utils_set_fd_cloexec(sock
);
2190 /* Create UST registration command for enqueuing */
2191 ust_cmd
= zmalloc(sizeof(struct ust_command
));
2192 if (ust_cmd
== NULL
) {
2193 PERROR("ust command zmalloc");
2202 * Using message-based transmissions to ensure we don't
2203 * have to deal with partially received messages.
2205 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
2207 ERR("Exhausted file descriptors allowed for applications.");
2217 health_code_update();
2218 ret
= ust_app_recv_registration(sock
, &ust_cmd
->reg_msg
);
2221 /* Close socket of the application. */
2226 lttng_fd_put(LTTNG_FD_APPS
, 1);
2230 health_code_update();
2232 ust_cmd
->sock
= sock
;
2235 DBG("UST registration received with pid:%d ppid:%d uid:%d"
2236 " gid:%d sock:%d name:%s (version %d.%d)",
2237 ust_cmd
->reg_msg
.pid
, ust_cmd
->reg_msg
.ppid
,
2238 ust_cmd
->reg_msg
.uid
, ust_cmd
->reg_msg
.gid
,
2239 ust_cmd
->sock
, ust_cmd
->reg_msg
.name
,
2240 ust_cmd
->reg_msg
.major
, ust_cmd
->reg_msg
.minor
);
2243 * Lock free enqueue the registration request. The red pill
2244 * has been taken! This apps will be part of the *system*.
2246 cds_wfcq_enqueue(&ust_cmd_queue
.head
, &ust_cmd_queue
.tail
, &ust_cmd
->node
);
2249 * Wake the registration queue futex. Implicit memory
2250 * barrier with the exchange in cds_wfcq_enqueue.
2252 futex_nto1_wake(&ust_cmd_queue
.futex
);
2253 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2254 ERR("Register apps socket poll error");
2257 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2266 /* Notify that the registration thread is gone */
2269 if (apps_sock
>= 0) {
2270 ret
= close(apps_sock
);
2280 lttng_fd_put(LTTNG_FD_APPS
, 1);
2282 unlink(config
.apps_unix_sock_path
.value
);
2285 lttng_poll_clean(&events
);
2289 DBG("UST Registration thread cleanup complete");
2292 ERR("Health error occurred in %s", __func__
);
2294 health_unregister(health_sessiond
);
2300 * Start the thread_manage_consumer. This must be done after a lttng-consumerd
2301 * exec or it will fails.
2303 static int spawn_consumer_thread(struct consumer_data
*consumer_data
)
2306 struct timespec timeout
;
2309 * Make sure we set the readiness flag to 0 because we are NOT ready.
2310 * This access to consumer_thread_is_ready does not need to be
2311 * protected by consumer_data.cond_mutex (yet) since the consumer
2312 * management thread has not been started at this point.
2314 consumer_data
->consumer_thread_is_ready
= 0;
2316 /* Setup pthread condition */
2317 ret
= pthread_condattr_init(&consumer_data
->condattr
);
2320 PERROR("pthread_condattr_init consumer data");
2325 * Set the monotonic clock in order to make sure we DO NOT jump in time
2326 * between the clock_gettime() call and the timedwait call. See bug #324
2327 * for a more details and how we noticed it.
2329 ret
= pthread_condattr_setclock(&consumer_data
->condattr
, CLOCK_MONOTONIC
);
2332 PERROR("pthread_condattr_setclock consumer data");
2336 ret
= pthread_cond_init(&consumer_data
->cond
, &consumer_data
->condattr
);
2339 PERROR("pthread_cond_init consumer data");
2343 ret
= pthread_create(&consumer_data
->thread
, default_pthread_attr(),
2344 thread_manage_consumer
, consumer_data
);
2347 PERROR("pthread_create consumer");
2352 /* We are about to wait on a pthread condition */
2353 pthread_mutex_lock(&consumer_data
->cond_mutex
);
2355 /* Get time for sem_timedwait absolute timeout */
2356 clock_ret
= lttng_clock_gettime(CLOCK_MONOTONIC
, &timeout
);
2358 * Set the timeout for the condition timed wait even if the clock gettime
2359 * call fails since we might loop on that call and we want to avoid to
2360 * increment the timeout too many times.
2362 timeout
.tv_sec
+= DEFAULT_SEM_WAIT_TIMEOUT
;
2365 * The following loop COULD be skipped in some conditions so this is why we
2366 * set ret to 0 in order to make sure at least one round of the loop is
2372 * Loop until the condition is reached or when a timeout is reached. Note
2373 * that the pthread_cond_timedwait(P) man page specifies that EINTR can NOT
2374 * be returned but the pthread_cond(3), from the glibc-doc, says that it is
2375 * possible. This loop does not take any chances and works with both of
2378 while (!consumer_data
->consumer_thread_is_ready
&& ret
!= ETIMEDOUT
) {
2379 if (clock_ret
< 0) {
2380 PERROR("clock_gettime spawn consumer");
2381 /* Infinite wait for the consumerd thread to be ready */
2382 ret
= pthread_cond_wait(&consumer_data
->cond
,
2383 &consumer_data
->cond_mutex
);
2385 ret
= pthread_cond_timedwait(&consumer_data
->cond
,
2386 &consumer_data
->cond_mutex
, &timeout
);
2390 /* Release the pthread condition */
2391 pthread_mutex_unlock(&consumer_data
->cond_mutex
);
2395 if (ret
== ETIMEDOUT
) {
2399 * Call has timed out so we kill the kconsumerd_thread and return
2402 ERR("Condition timed out. The consumer thread was never ready."
2404 pth_ret
= pthread_cancel(consumer_data
->thread
);
2406 PERROR("pthread_cancel consumer thread");
2409 PERROR("pthread_cond_wait failed consumer thread");
2411 /* Caller is expecting a negative value on failure. */
2416 pthread_mutex_lock(&consumer_data
->pid_mutex
);
2417 if (consumer_data
->pid
== 0) {
2418 ERR("Consumerd did not start");
2419 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
2422 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
2431 * Join consumer thread
2433 static int join_consumer_thread(struct consumer_data
*consumer_data
)
2437 /* Consumer pid must be a real one. */
2438 if (consumer_data
->pid
> 0) {
2440 ret
= kill(consumer_data
->pid
, SIGTERM
);
2442 PERROR("Error killing consumer daemon");
2445 return pthread_join(consumer_data
->thread
, &status
);
2452 * Fork and exec a consumer daemon (consumerd).
2454 * Return pid if successful else -1.
2456 static pid_t
spawn_consumerd(struct consumer_data
*consumer_data
)
2460 const char *consumer_to_use
;
2461 const char *verbosity
;
2464 DBG("Spawning consumerd");
2471 if (config
.verbose_consumer
) {
2472 verbosity
= "--verbose";
2473 } else if (lttng_opt_quiet
) {
2474 verbosity
= "--quiet";
2479 switch (consumer_data
->type
) {
2480 case LTTNG_CONSUMER_KERNEL
:
2482 * Find out which consumerd to execute. We will first try the
2483 * 64-bit path, then the sessiond's installation directory, and
2484 * fallback on the 32-bit one,
2486 DBG3("Looking for a kernel consumer at these locations:");
2487 DBG3(" 1) %s", config
.consumerd64_bin_path
.value
? : "NULL");
2488 DBG3(" 2) %s/%s", INSTALL_BIN_PATH
, DEFAULT_CONSUMERD_FILE
);
2489 DBG3(" 3) %s", config
.consumerd32_bin_path
.value
? : "NULL");
2490 if (stat(config
.consumerd64_bin_path
.value
, &st
) == 0) {
2491 DBG3("Found location #1");
2492 consumer_to_use
= config
.consumerd64_bin_path
.value
;
2493 } else if (stat(INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
, &st
) == 0) {
2494 DBG3("Found location #2");
2495 consumer_to_use
= INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
;
2496 } else if (stat(config
.consumerd32_bin_path
.value
, &st
) == 0) {
2497 DBG3("Found location #3");
2498 consumer_to_use
= config
.consumerd32_bin_path
.value
;
2500 DBG("Could not find any valid consumerd executable");
2504 DBG("Using kernel consumer at: %s", consumer_to_use
);
2505 (void) execl(consumer_to_use
,
2506 "lttng-consumerd", verbosity
, "-k",
2507 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
2508 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
2509 "--group", config
.tracing_group_name
.value
,
2512 case LTTNG_CONSUMER64_UST
:
2514 if (config
.consumerd64_lib_dir
.value
) {
2519 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
2523 tmplen
= strlen(config
.consumerd64_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
2524 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
2529 strcat(tmpnew
, config
.consumerd64_lib_dir
.value
);
2530 if (tmp
[0] != '\0') {
2531 strcat(tmpnew
, ":");
2532 strcat(tmpnew
, tmp
);
2534 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
2541 DBG("Using 64-bit UST consumer at: %s", config
.consumerd64_bin_path
.value
);
2542 (void) execl(config
.consumerd64_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
2543 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
2544 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
2545 "--group", config
.tracing_group_name
.value
,
2549 case LTTNG_CONSUMER32_UST
:
2551 if (config
.consumerd32_lib_dir
.value
) {
2556 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
2560 tmplen
= strlen(config
.consumerd32_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
2561 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
2566 strcat(tmpnew
, config
.consumerd32_lib_dir
.value
);
2567 if (tmp
[0] != '\0') {
2568 strcat(tmpnew
, ":");
2569 strcat(tmpnew
, tmp
);
2571 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
2578 DBG("Using 32-bit UST consumer at: %s", config
.consumerd32_bin_path
.value
);
2579 (void) execl(config
.consumerd32_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
2580 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
2581 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
2582 "--group", config
.tracing_group_name
.value
,
2587 ERR("unknown consumer type");
2591 PERROR("Consumer execl()");
2593 /* Reaching this point, we got a failure on our execl(). */
2595 } else if (pid
> 0) {
2598 PERROR("start consumer fork");
2606 * Spawn the consumerd daemon and session daemon thread.
2608 static int start_consumerd(struct consumer_data
*consumer_data
)
2613 * Set the listen() state on the socket since there is a possible race
2614 * between the exec() of the consumer daemon and this call if place in the
2615 * consumer thread. See bug #366 for more details.
2617 ret
= lttcomm_listen_unix_sock(consumer_data
->err_sock
);
2622 pthread_mutex_lock(&consumer_data
->pid_mutex
);
2623 if (consumer_data
->pid
!= 0) {
2624 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
2628 ret
= spawn_consumerd(consumer_data
);
2630 ERR("Spawning consumerd failed");
2631 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
2635 /* Setting up the consumer_data pid */
2636 consumer_data
->pid
= ret
;
2637 DBG2("Consumer pid %d", consumer_data
->pid
);
2638 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
2640 DBG2("Spawning consumer control thread");
2641 ret
= spawn_consumer_thread(consumer_data
);
2643 ERR("Fatal error spawning consumer control thread");
2651 /* Cleanup already created sockets on error. */
2652 if (consumer_data
->err_sock
>= 0) {
2655 err
= close(consumer_data
->err_sock
);
2657 PERROR("close consumer data error socket");
2664 * Setup necessary data for kernel tracer action.
2666 static int init_kernel_tracer(void)
2670 /* Modprobe lttng kernel modules */
2671 ret
= modprobe_lttng_control();
2676 /* Open debugfs lttng */
2677 kernel_tracer_fd
= open(module_proc_lttng
, O_RDWR
);
2678 if (kernel_tracer_fd
< 0) {
2679 DBG("Failed to open %s", module_proc_lttng
);
2683 /* Validate kernel version */
2684 ret
= kernel_validate_version(kernel_tracer_fd
, &kernel_tracer_version
,
2685 &kernel_tracer_abi_version
);
2690 ret
= modprobe_lttng_data();
2695 ret
= kernel_supports_ring_buffer_snapshot_sample_positions(
2702 WARN("Kernel tracer does not support buffer monitoring. "
2703 "The monitoring timer of channels in the kernel domain "
2704 "will be set to 0 (disabled).");
2707 DBG("Kernel tracer fd %d", kernel_tracer_fd
);
2711 modprobe_remove_lttng_control();
2712 ret
= close(kernel_tracer_fd
);
2716 kernel_tracer_fd
= -1;
2717 return LTTNG_ERR_KERN_VERSION
;
2720 ret
= close(kernel_tracer_fd
);
2726 modprobe_remove_lttng_control();
2729 WARN("No kernel tracer available");
2730 kernel_tracer_fd
= -1;
2732 return LTTNG_ERR_NEED_ROOT_SESSIOND
;
2734 return LTTNG_ERR_KERN_NA
;
2740 * Copy consumer output from the tracing session to the domain session. The
2741 * function also applies the right modification on a per domain basis for the
2742 * trace files destination directory.
2744 * Should *NOT* be called with RCU read-side lock held.
2746 static int copy_session_consumer(int domain
, struct ltt_session
*session
)
2749 const char *dir_name
;
2750 struct consumer_output
*consumer
;
2753 assert(session
->consumer
);
2756 case LTTNG_DOMAIN_KERNEL
:
2757 DBG3("Copying tracing session consumer output in kernel session");
2759 * XXX: We should audit the session creation and what this function
2760 * does "extra" in order to avoid a destroy since this function is used
2761 * in the domain session creation (kernel and ust) only. Same for UST
2764 if (session
->kernel_session
->consumer
) {
2765 consumer_output_put(session
->kernel_session
->consumer
);
2767 session
->kernel_session
->consumer
=
2768 consumer_copy_output(session
->consumer
);
2769 /* Ease our life a bit for the next part */
2770 consumer
= session
->kernel_session
->consumer
;
2771 dir_name
= DEFAULT_KERNEL_TRACE_DIR
;
2773 case LTTNG_DOMAIN_JUL
:
2774 case LTTNG_DOMAIN_LOG4J
:
2775 case LTTNG_DOMAIN_PYTHON
:
2776 case LTTNG_DOMAIN_UST
:
2777 DBG3("Copying tracing session consumer output in UST session");
2778 if (session
->ust_session
->consumer
) {
2779 consumer_output_put(session
->ust_session
->consumer
);
2781 session
->ust_session
->consumer
=
2782 consumer_copy_output(session
->consumer
);
2783 /* Ease our life a bit for the next part */
2784 consumer
= session
->ust_session
->consumer
;
2785 dir_name
= DEFAULT_UST_TRACE_DIR
;
2788 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
2792 /* Append correct directory to subdir */
2793 strncat(consumer
->subdir
, dir_name
,
2794 sizeof(consumer
->subdir
) - strlen(consumer
->subdir
) - 1);
2795 DBG3("Copy session consumer subdir %s", consumer
->subdir
);
2804 * Create an UST session and add it to the session ust list.
2806 * Should *NOT* be called with RCU read-side lock held.
2808 static int create_ust_session(struct ltt_session
*session
,
2809 struct lttng_domain
*domain
)
2812 struct ltt_ust_session
*lus
= NULL
;
2816 assert(session
->consumer
);
2818 switch (domain
->type
) {
2819 case LTTNG_DOMAIN_JUL
:
2820 case LTTNG_DOMAIN_LOG4J
:
2821 case LTTNG_DOMAIN_PYTHON
:
2822 case LTTNG_DOMAIN_UST
:
2825 ERR("Unknown UST domain on create session %d", domain
->type
);
2826 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
2830 DBG("Creating UST session");
2832 lus
= trace_ust_create_session(session
->id
);
2834 ret
= LTTNG_ERR_UST_SESS_FAIL
;
2838 lus
->uid
= session
->uid
;
2839 lus
->gid
= session
->gid
;
2840 lus
->output_traces
= session
->output_traces
;
2841 lus
->snapshot_mode
= session
->snapshot_mode
;
2842 lus
->live_timer_interval
= session
->live_timer
;
2843 session
->ust_session
= lus
;
2844 if (session
->shm_path
[0]) {
2845 strncpy(lus
->root_shm_path
, session
->shm_path
,
2846 sizeof(lus
->root_shm_path
));
2847 lus
->root_shm_path
[sizeof(lus
->root_shm_path
) - 1] = '\0';
2848 strncpy(lus
->shm_path
, session
->shm_path
,
2849 sizeof(lus
->shm_path
));
2850 lus
->shm_path
[sizeof(lus
->shm_path
) - 1] = '\0';
2851 strncat(lus
->shm_path
, "/ust",
2852 sizeof(lus
->shm_path
) - strlen(lus
->shm_path
) - 1);
2854 /* Copy session output to the newly created UST session */
2855 ret
= copy_session_consumer(domain
->type
, session
);
2856 if (ret
!= LTTNG_OK
) {
2864 session
->ust_session
= NULL
;
2869 * Create a kernel tracer session then create the default channel.
2871 static int create_kernel_session(struct ltt_session
*session
)
2875 DBG("Creating kernel session");
2877 ret
= kernel_create_session(session
, kernel_tracer_fd
);
2879 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
2883 /* Code flow safety */
2884 assert(session
->kernel_session
);
2886 /* Copy session output to the newly created Kernel session */
2887 ret
= copy_session_consumer(LTTNG_DOMAIN_KERNEL
, session
);
2888 if (ret
!= LTTNG_OK
) {
2892 session
->kernel_session
->uid
= session
->uid
;
2893 session
->kernel_session
->gid
= session
->gid
;
2894 session
->kernel_session
->output_traces
= session
->output_traces
;
2895 session
->kernel_session
->snapshot_mode
= session
->snapshot_mode
;
2900 trace_kernel_destroy_session(session
->kernel_session
);
2901 session
->kernel_session
= NULL
;
2906 * Count number of session permitted by uid/gid.
2908 static unsigned int lttng_sessions_count(uid_t uid
, gid_t gid
)
2911 struct ltt_session
*session
;
2913 DBG("Counting number of available session for UID %d GID %d",
2915 cds_list_for_each_entry(session
, &session_list_ptr
->head
, list
) {
2917 * Only list the sessions the user can control.
2919 if (!session_access_ok(session
, uid
, gid
)) {
2928 * Check if the current kernel tracer supports the session rotation feature.
2929 * Return 1 if it does, 0 otherwise.
2931 static int check_rotate_compatible(void)
2935 if (kernel_tracer_version
.major
!= 2 || kernel_tracer_version
.minor
< 11) {
2936 DBG("Kernel tracer version is not compatible with the rotation feature");
2944 * Process the command requested by the lttng client within the command
2945 * context structure. This function make sure that the return structure (llm)
2946 * is set and ready for transmission before returning.
2948 * Return any error encountered or 0 for success.
2950 * "sock" is only used for special-case var. len data.
2952 * Should *NOT* be called with RCU read-side lock held.
2954 static int process_client_msg(struct command_ctx
*cmd_ctx
, int sock
,
2958 int need_tracing_session
= 1;
2961 DBG("Processing client command %d", cmd_ctx
->lsm
->cmd_type
);
2963 assert(!rcu_read_ongoing());
2967 switch (cmd_ctx
->lsm
->cmd_type
) {
2968 case LTTNG_CREATE_SESSION
:
2969 case LTTNG_CREATE_SESSION_SNAPSHOT
:
2970 case LTTNG_CREATE_SESSION_LIVE
:
2971 case LTTNG_DESTROY_SESSION
:
2972 case LTTNG_LIST_SESSIONS
:
2973 case LTTNG_LIST_DOMAINS
:
2974 case LTTNG_START_TRACE
:
2975 case LTTNG_STOP_TRACE
:
2976 case LTTNG_DATA_PENDING
:
2977 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
2978 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
2979 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
2980 case LTTNG_SNAPSHOT_RECORD
:
2981 case LTTNG_SAVE_SESSION
:
2982 case LTTNG_SET_SESSION_SHM_PATH
:
2983 case LTTNG_REGENERATE_METADATA
:
2984 case LTTNG_REGENERATE_STATEDUMP
:
2985 case LTTNG_REGISTER_TRIGGER
:
2986 case LTTNG_UNREGISTER_TRIGGER
:
2987 case LTTNG_ROTATE_SESSION
:
2988 case LTTNG_ROTATION_GET_INFO
:
2989 case LTTNG_SESSION_GET_CURRENT_OUTPUT
:
2990 case LTTNG_ROTATION_SET_SCHEDULE
:
2991 case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD
:
2992 case LTTNG_ROTATION_SCHEDULE_GET_SIZE
:
2999 if (config
.no_kernel
&& need_domain
3000 && cmd_ctx
->lsm
->domain
.type
== LTTNG_DOMAIN_KERNEL
) {
3002 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
3004 ret
= LTTNG_ERR_KERN_NA
;
3009 /* Deny register consumer if we already have a spawned consumer. */
3010 if (cmd_ctx
->lsm
->cmd_type
== LTTNG_REGISTER_CONSUMER
) {
3011 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
3012 if (kconsumer_data
.pid
> 0) {
3013 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
3014 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
3017 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
3021 * Check for command that don't needs to allocate a returned payload. We do
3022 * this here so we don't have to make the call for no payload at each
3025 switch(cmd_ctx
->lsm
->cmd_type
) {
3026 case LTTNG_LIST_SESSIONS
:
3027 case LTTNG_LIST_TRACEPOINTS
:
3028 case LTTNG_LIST_TRACEPOINT_FIELDS
:
3029 case LTTNG_LIST_DOMAINS
:
3030 case LTTNG_LIST_CHANNELS
:
3031 case LTTNG_LIST_EVENTS
:
3032 case LTTNG_LIST_SYSCALLS
:
3033 case LTTNG_LIST_TRACKER_PIDS
:
3034 case LTTNG_DATA_PENDING
:
3035 case LTTNG_ROTATE_SESSION
:
3036 case LTTNG_ROTATION_GET_INFO
:
3037 case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD
:
3038 case LTTNG_ROTATION_SCHEDULE_GET_SIZE
:
3041 /* Setup lttng message with no payload */
3042 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0);
3044 /* This label does not try to unlock the session */
3045 goto init_setup_error
;
3049 /* Commands that DO NOT need a session. */
3050 switch (cmd_ctx
->lsm
->cmd_type
) {
3051 case LTTNG_CREATE_SESSION
:
3052 case LTTNG_CREATE_SESSION_SNAPSHOT
:
3053 case LTTNG_CREATE_SESSION_LIVE
:
3054 case LTTNG_LIST_SESSIONS
:
3055 case LTTNG_LIST_TRACEPOINTS
:
3056 case LTTNG_LIST_SYSCALLS
:
3057 case LTTNG_LIST_TRACEPOINT_FIELDS
:
3058 case LTTNG_SAVE_SESSION
:
3059 case LTTNG_REGISTER_TRIGGER
:
3060 case LTTNG_UNREGISTER_TRIGGER
:
3061 need_tracing_session
= 0;
3064 DBG("Getting session %s by name", cmd_ctx
->lsm
->session
.name
);
3066 * We keep the session list lock across _all_ commands
3067 * for now, because the per-session lock does not
3068 * handle teardown properly.
3070 session_lock_list();
3071 cmd_ctx
->session
= session_find_by_name(cmd_ctx
->lsm
->session
.name
);
3072 if (cmd_ctx
->session
== NULL
) {
3073 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
3076 /* Acquire lock for the session */
3077 session_lock(cmd_ctx
->session
);
3083 * Commands that need a valid session but should NOT create one if none
3084 * exists. Instead of creating one and destroying it when the command is
3085 * handled, process that right before so we save some round trip in useless
3088 switch (cmd_ctx
->lsm
->cmd_type
) {
3089 case LTTNG_DISABLE_CHANNEL
:
3090 case LTTNG_DISABLE_EVENT
:
3091 switch (cmd_ctx
->lsm
->domain
.type
) {
3092 case LTTNG_DOMAIN_KERNEL
:
3093 if (!cmd_ctx
->session
->kernel_session
) {
3094 ret
= LTTNG_ERR_NO_CHANNEL
;
3098 case LTTNG_DOMAIN_JUL
:
3099 case LTTNG_DOMAIN_LOG4J
:
3100 case LTTNG_DOMAIN_PYTHON
:
3101 case LTTNG_DOMAIN_UST
:
3102 if (!cmd_ctx
->session
->ust_session
) {
3103 ret
= LTTNG_ERR_NO_CHANNEL
;
3108 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
3120 * Check domain type for specific "pre-action".
3122 switch (cmd_ctx
->lsm
->domain
.type
) {
3123 case LTTNG_DOMAIN_KERNEL
:
3125 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
3129 /* Kernel tracer check */
3130 if (kernel_tracer_fd
== -1) {
3131 /* Basically, load kernel tracer modules */
3132 ret
= init_kernel_tracer();
3138 /* Consumer is in an ERROR state. Report back to client */
3139 if (uatomic_read(&kernel_consumerd_state
) == CONSUMER_ERROR
) {
3140 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
3144 /* Need a session for kernel command */
3145 if (need_tracing_session
) {
3146 if (cmd_ctx
->session
->kernel_session
== NULL
) {
3147 ret
= create_kernel_session(cmd_ctx
->session
);
3149 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
3154 /* Start the kernel consumer daemon */
3155 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
3156 if (kconsumer_data
.pid
== 0 &&
3157 cmd_ctx
->lsm
->cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
3158 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
3159 ret
= start_consumerd(&kconsumer_data
);
3161 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
3164 uatomic_set(&kernel_consumerd_state
, CONSUMER_STARTED
);
3166 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
3170 * The consumer was just spawned so we need to add the socket to
3171 * the consumer output of the session if exist.
3173 ret
= consumer_create_socket(&kconsumer_data
,
3174 cmd_ctx
->session
->kernel_session
->consumer
);
3181 case LTTNG_DOMAIN_JUL
:
3182 case LTTNG_DOMAIN_LOG4J
:
3183 case LTTNG_DOMAIN_PYTHON
:
3184 case LTTNG_DOMAIN_UST
:
3186 if (!ust_app_supported()) {
3187 ret
= LTTNG_ERR_NO_UST
;
3190 /* Consumer is in an ERROR state. Report back to client */
3191 if (uatomic_read(&ust_consumerd_state
) == CONSUMER_ERROR
) {
3192 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
3196 if (need_tracing_session
) {
3197 /* Create UST session if none exist. */
3198 if (cmd_ctx
->session
->ust_session
== NULL
) {
3199 ret
= create_ust_session(cmd_ctx
->session
,
3200 &cmd_ctx
->lsm
->domain
);
3201 if (ret
!= LTTNG_OK
) {
3206 /* Start the UST consumer daemons */
3208 pthread_mutex_lock(&ustconsumer64_data
.pid_mutex
);
3209 if (config
.consumerd64_bin_path
.value
&&
3210 ustconsumer64_data
.pid
== 0 &&
3211 cmd_ctx
->lsm
->cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
3212 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
3213 ret
= start_consumerd(&ustconsumer64_data
);
3215 ret
= LTTNG_ERR_UST_CONSUMER64_FAIL
;
3216 uatomic_set(&ust_consumerd64_fd
, -EINVAL
);
3220 uatomic_set(&ust_consumerd64_fd
, ustconsumer64_data
.cmd_sock
);
3221 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
3223 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
3227 * Setup socket for consumer 64 bit. No need for atomic access
3228 * since it was set above and can ONLY be set in this thread.
3230 ret
= consumer_create_socket(&ustconsumer64_data
,
3231 cmd_ctx
->session
->ust_session
->consumer
);
3237 pthread_mutex_lock(&ustconsumer32_data
.pid_mutex
);
3238 if (config
.consumerd32_bin_path
.value
&&
3239 ustconsumer32_data
.pid
== 0 &&
3240 cmd_ctx
->lsm
->cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
3241 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
3242 ret
= start_consumerd(&ustconsumer32_data
);
3244 ret
= LTTNG_ERR_UST_CONSUMER32_FAIL
;
3245 uatomic_set(&ust_consumerd32_fd
, -EINVAL
);
3249 uatomic_set(&ust_consumerd32_fd
, ustconsumer32_data
.cmd_sock
);
3250 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
3252 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
3256 * Setup socket for consumer 64 bit. No need for atomic access
3257 * since it was set above and can ONLY be set in this thread.
3259 ret
= consumer_create_socket(&ustconsumer32_data
,
3260 cmd_ctx
->session
->ust_session
->consumer
);
3272 /* Validate consumer daemon state when start/stop trace command */
3273 if (cmd_ctx
->lsm
->cmd_type
== LTTNG_START_TRACE
||
3274 cmd_ctx
->lsm
->cmd_type
== LTTNG_STOP_TRACE
) {
3275 switch (cmd_ctx
->lsm
->domain
.type
) {
3276 case LTTNG_DOMAIN_NONE
:
3278 case LTTNG_DOMAIN_JUL
:
3279 case LTTNG_DOMAIN_LOG4J
:
3280 case LTTNG_DOMAIN_PYTHON
:
3281 case LTTNG_DOMAIN_UST
:
3282 if (uatomic_read(&ust_consumerd_state
) != CONSUMER_STARTED
) {
3283 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
3287 case LTTNG_DOMAIN_KERNEL
:
3288 if (uatomic_read(&kernel_consumerd_state
) != CONSUMER_STARTED
) {
3289 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
3294 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
3300 * Check that the UID or GID match that of the tracing session.
3301 * The root user can interact with all sessions.
3303 if (need_tracing_session
) {
3304 if (!session_access_ok(cmd_ctx
->session
,
3305 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
3306 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
))) {
3307 ret
= LTTNG_ERR_EPERM
;
3313 * Send relayd information to consumer as soon as we have a domain and a
3316 if (cmd_ctx
->session
&& need_domain
) {
3318 * Setup relayd if not done yet. If the relayd information was already
3319 * sent to the consumer, this call will gracefully return.
3321 ret
= cmd_setup_relayd(cmd_ctx
->session
);
3322 if (ret
!= LTTNG_OK
) {
3327 /* Process by command type */
3328 switch (cmd_ctx
->lsm
->cmd_type
) {
3329 case LTTNG_ADD_CONTEXT
:
3332 * An LTTNG_ADD_CONTEXT command might have a supplementary
3333 * payload if the context being added is an application context.
3335 if (cmd_ctx
->lsm
->u
.context
.ctx
.ctx
==
3336 LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
3337 char *provider_name
= NULL
, *context_name
= NULL
;
3338 size_t provider_name_len
=
3339 cmd_ctx
->lsm
->u
.context
.provider_name_len
;
3340 size_t context_name_len
=
3341 cmd_ctx
->lsm
->u
.context
.context_name_len
;
3343 if (provider_name_len
== 0 || context_name_len
== 0) {
3345 * Application provider and context names MUST
3348 ret
= -LTTNG_ERR_INVALID
;
3352 provider_name
= zmalloc(provider_name_len
+ 1);
3353 if (!provider_name
) {
3354 ret
= -LTTNG_ERR_NOMEM
;
3357 cmd_ctx
->lsm
->u
.context
.ctx
.u
.app_ctx
.provider_name
=
3360 context_name
= zmalloc(context_name_len
+ 1);
3361 if (!context_name
) {
3362 ret
= -LTTNG_ERR_NOMEM
;
3363 goto error_add_context
;
3365 cmd_ctx
->lsm
->u
.context
.ctx
.u
.app_ctx
.ctx_name
=
3368 ret
= lttcomm_recv_unix_sock(sock
, provider_name
,
3371 goto error_add_context
;
3374 ret
= lttcomm_recv_unix_sock(sock
, context_name
,
3377 goto error_add_context
;
3382 * cmd_add_context assumes ownership of the provider and context
3385 ret
= cmd_add_context(cmd_ctx
->session
,
3386 cmd_ctx
->lsm
->domain
.type
,
3387 cmd_ctx
->lsm
->u
.context
.channel_name
,
3388 &cmd_ctx
->lsm
->u
.context
.ctx
,
3389 kernel_poll_pipe
[1]);
3391 cmd_ctx
->lsm
->u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
3392 cmd_ctx
->lsm
->u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
3394 free(cmd_ctx
->lsm
->u
.context
.ctx
.u
.app_ctx
.provider_name
);
3395 free(cmd_ctx
->lsm
->u
.context
.ctx
.u
.app_ctx
.ctx_name
);
3401 case LTTNG_DISABLE_CHANNEL
:
3403 ret
= cmd_disable_channel(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
3404 cmd_ctx
->lsm
->u
.disable
.channel_name
);
3407 case LTTNG_DISABLE_EVENT
:
3411 * FIXME: handle filter; for now we just receive the filter's
3412 * bytecode along with the filter expression which are sent by
3413 * liblttng-ctl and discard them.
3415 * This fixes an issue where the client may block while sending
3416 * the filter payload and encounter an error because the session
3417 * daemon closes the socket without ever handling this data.
3419 size_t count
= cmd_ctx
->lsm
->u
.disable
.expression_len
+
3420 cmd_ctx
->lsm
->u
.disable
.bytecode_len
;
3423 char data
[LTTNG_FILTER_MAX_LEN
];
3425 DBG("Discarding disable event command payload of size %zu", count
);
3427 ret
= lttcomm_recv_unix_sock(sock
, data
,
3428 count
> sizeof(data
) ? sizeof(data
) : count
);
3433 count
-= (size_t) ret
;
3436 /* FIXME: passing packed structure to non-packed pointer */
3437 ret
= cmd_disable_event(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
3438 cmd_ctx
->lsm
->u
.disable
.channel_name
,
3439 &cmd_ctx
->lsm
->u
.disable
.event
);
3442 case LTTNG_ENABLE_CHANNEL
:
3444 cmd_ctx
->lsm
->u
.channel
.chan
.attr
.extended
.ptr
=
3445 (struct lttng_channel_extended
*) &cmd_ctx
->lsm
->u
.channel
.extended
;
3446 ret
= cmd_enable_channel(cmd_ctx
->session
, &cmd_ctx
->lsm
->domain
,
3447 &cmd_ctx
->lsm
->u
.channel
.chan
,
3448 kernel_poll_pipe
[1]);
3451 case LTTNG_TRACK_PID
:
3453 ret
= cmd_track_pid(cmd_ctx
->session
,
3454 cmd_ctx
->lsm
->domain
.type
,
3455 cmd_ctx
->lsm
->u
.pid_tracker
.pid
);
3458 case LTTNG_UNTRACK_PID
:
3460 ret
= cmd_untrack_pid(cmd_ctx
->session
,
3461 cmd_ctx
->lsm
->domain
.type
,
3462 cmd_ctx
->lsm
->u
.pid_tracker
.pid
);
3465 case LTTNG_ENABLE_EVENT
:
3467 struct lttng_event_exclusion
*exclusion
= NULL
;
3468 struct lttng_filter_bytecode
*bytecode
= NULL
;
3469 char *filter_expression
= NULL
;
3471 /* Handle exclusion events and receive it from the client. */
3472 if (cmd_ctx
->lsm
->u
.enable
.exclusion_count
> 0) {
3473 size_t count
= cmd_ctx
->lsm
->u
.enable
.exclusion_count
;
3475 exclusion
= zmalloc(sizeof(struct lttng_event_exclusion
) +
3476 (count
* LTTNG_SYMBOL_NAME_LEN
));
3478 ret
= LTTNG_ERR_EXCLUSION_NOMEM
;
3482 DBG("Receiving var len exclusion event list from client ...");
3483 exclusion
->count
= count
;
3484 ret
= lttcomm_recv_unix_sock(sock
, exclusion
->names
,
3485 count
* LTTNG_SYMBOL_NAME_LEN
);
3487 DBG("Nothing recv() from client var len data... continuing");
3490 ret
= LTTNG_ERR_EXCLUSION_INVAL
;
3495 /* Get filter expression from client. */
3496 if (cmd_ctx
->lsm
->u
.enable
.expression_len
> 0) {
3497 size_t expression_len
=
3498 cmd_ctx
->lsm
->u
.enable
.expression_len
;
3500 if (expression_len
> LTTNG_FILTER_MAX_LEN
) {
3501 ret
= LTTNG_ERR_FILTER_INVAL
;
3506 filter_expression
= zmalloc(expression_len
);
3507 if (!filter_expression
) {
3509 ret
= LTTNG_ERR_FILTER_NOMEM
;
3513 /* Receive var. len. data */
3514 DBG("Receiving var len filter's expression from client ...");
3515 ret
= lttcomm_recv_unix_sock(sock
, filter_expression
,
3518 DBG("Nothing recv() from client car len data... continuing");
3520 free(filter_expression
);
3522 ret
= LTTNG_ERR_FILTER_INVAL
;
3527 /* Handle filter and get bytecode from client. */
3528 if (cmd_ctx
->lsm
->u
.enable
.bytecode_len
> 0) {
3529 size_t bytecode_len
= cmd_ctx
->lsm
->u
.enable
.bytecode_len
;
3531 if (bytecode_len
> LTTNG_FILTER_MAX_LEN
) {
3532 ret
= LTTNG_ERR_FILTER_INVAL
;
3533 free(filter_expression
);
3538 bytecode
= zmalloc(bytecode_len
);
3540 free(filter_expression
);
3542 ret
= LTTNG_ERR_FILTER_NOMEM
;
3546 /* Receive var. len. data */
3547 DBG("Receiving var len filter's bytecode from client ...");
3548 ret
= lttcomm_recv_unix_sock(sock
, bytecode
, bytecode_len
);
3550 DBG("Nothing recv() from client car len data... continuing");
3552 free(filter_expression
);
3555 ret
= LTTNG_ERR_FILTER_INVAL
;
3559 if ((bytecode
->len
+ sizeof(*bytecode
)) != bytecode_len
) {
3560 free(filter_expression
);
3563 ret
= LTTNG_ERR_FILTER_INVAL
;
3568 ret
= cmd_enable_event(cmd_ctx
->session
, &cmd_ctx
->lsm
->domain
,
3569 cmd_ctx
->lsm
->u
.enable
.channel_name
,
3570 &cmd_ctx
->lsm
->u
.enable
.event
,
3571 filter_expression
, bytecode
, exclusion
,
3572 kernel_poll_pipe
[1]);
3575 case LTTNG_LIST_TRACEPOINTS
:
3577 struct lttng_event
*events
;
3580 session_lock_list();
3581 nb_events
= cmd_list_tracepoints(cmd_ctx
->lsm
->domain
.type
, &events
);
3582 session_unlock_list();
3583 if (nb_events
< 0) {
3584 /* Return value is a negative lttng_error_code. */
3590 * Setup lttng message with payload size set to the event list size in
3591 * bytes and then copy list into the llm payload.
3593 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
3594 sizeof(struct lttng_event
) * nb_events
);
3604 case LTTNG_LIST_TRACEPOINT_FIELDS
:
3606 struct lttng_event_field
*fields
;
3609 session_lock_list();
3610 nb_fields
= cmd_list_tracepoint_fields(cmd_ctx
->lsm
->domain
.type
,
3612 session_unlock_list();
3613 if (nb_fields
< 0) {
3614 /* Return value is a negative lttng_error_code. */
3620 * Setup lttng message with payload size set to the event list size in
3621 * bytes and then copy list into the llm payload.
3623 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, fields
,
3624 sizeof(struct lttng_event_field
) * nb_fields
);
3634 case LTTNG_LIST_SYSCALLS
:
3636 struct lttng_event
*events
;
3639 nb_events
= cmd_list_syscalls(&events
);
3640 if (nb_events
< 0) {
3641 /* Return value is a negative lttng_error_code. */
3647 * Setup lttng message with payload size set to the event list size in
3648 * bytes and then copy list into the llm payload.
3650 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
3651 sizeof(struct lttng_event
) * nb_events
);
3661 case LTTNG_LIST_TRACKER_PIDS
:
3663 int32_t *pids
= NULL
;
3666 nr_pids
= cmd_list_tracker_pids(cmd_ctx
->session
,
3667 cmd_ctx
->lsm
->domain
.type
, &pids
);
3669 /* Return value is a negative lttng_error_code. */
3675 * Setup lttng message with payload size set to the event list size in
3676 * bytes and then copy list into the llm payload.
3678 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, pids
,
3679 sizeof(int32_t) * nr_pids
);
3689 case LTTNG_SET_CONSUMER_URI
:
3692 struct lttng_uri
*uris
;
3694 nb_uri
= cmd_ctx
->lsm
->u
.uri
.size
;
3695 len
= nb_uri
* sizeof(struct lttng_uri
);
3698 ret
= LTTNG_ERR_INVALID
;
3702 uris
= zmalloc(len
);
3704 ret
= LTTNG_ERR_FATAL
;
3708 /* Receive variable len data */
3709 DBG("Receiving %zu URI(s) from client ...", nb_uri
);
3710 ret
= lttcomm_recv_unix_sock(sock
, uris
, len
);
3712 DBG("No URIs received from client... continuing");
3714 ret
= LTTNG_ERR_SESSION_FAIL
;
3719 ret
= cmd_set_consumer_uri(cmd_ctx
->session
, nb_uri
, uris
);
3721 if (ret
!= LTTNG_OK
) {
3728 case LTTNG_START_TRACE
:
3731 * On the first start, if we have a kernel session and we have
3732 * enabled time or size-based rotations, we have to make sure
3733 * the kernel tracer supports it.
3735 if (!cmd_ctx
->session
->has_been_started
&& \
3736 cmd_ctx
->session
->kernel_session
&& \
3737 (cmd_ctx
->session
->rotate_timer_period
|| \
3738 cmd_ctx
->session
->rotate_size
) && \
3739 !check_rotate_compatible()) {
3740 DBG("Kernel tracer version is not compatible with the rotation feature");
3741 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
3744 ret
= cmd_start_trace(cmd_ctx
->session
);
3747 case LTTNG_STOP_TRACE
:
3749 ret
= cmd_stop_trace(cmd_ctx
->session
);
3752 case LTTNG_CREATE_SESSION
:
3755 struct lttng_uri
*uris
= NULL
;
3757 nb_uri
= cmd_ctx
->lsm
->u
.uri
.size
;
3758 len
= nb_uri
* sizeof(struct lttng_uri
);
3761 uris
= zmalloc(len
);
3763 ret
= LTTNG_ERR_FATAL
;
3767 /* Receive variable len data */
3768 DBG("Waiting for %zu URIs from client ...", nb_uri
);
3769 ret
= lttcomm_recv_unix_sock(sock
, uris
, len
);
3771 DBG("No URIs received from client... continuing");
3773 ret
= LTTNG_ERR_SESSION_FAIL
;
3778 if (nb_uri
== 1 && uris
[0].dtype
!= LTTNG_DST_PATH
) {
3779 DBG("Creating session with ONE network URI is a bad call");
3780 ret
= LTTNG_ERR_SESSION_FAIL
;
3786 ret
= cmd_create_session_uri(cmd_ctx
->lsm
->session
.name
, uris
, nb_uri
,
3787 &cmd_ctx
->creds
, 0);
3793 case LTTNG_DESTROY_SESSION
:
3795 ret
= cmd_destroy_session(cmd_ctx
->session
, kernel_poll_pipe
[1],
3796 notification_thread_handle
);
3798 /* Set session to NULL so we do not unlock it after free. */
3799 cmd_ctx
->session
= NULL
;
3802 case LTTNG_LIST_DOMAINS
:
3805 struct lttng_domain
*domains
= NULL
;
3807 nb_dom
= cmd_list_domains(cmd_ctx
->session
, &domains
);
3809 /* Return value is a negative lttng_error_code. */
3814 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, domains
,
3815 nb_dom
* sizeof(struct lttng_domain
));
3825 case LTTNG_LIST_CHANNELS
:
3827 ssize_t payload_size
;
3828 struct lttng_channel
*channels
= NULL
;
3830 payload_size
= cmd_list_channels(cmd_ctx
->lsm
->domain
.type
,
3831 cmd_ctx
->session
, &channels
);
3832 if (payload_size
< 0) {
3833 /* Return value is a negative lttng_error_code. */
3834 ret
= -payload_size
;
3838 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, channels
,
3849 case LTTNG_LIST_EVENTS
:
3852 struct lttng_event
*events
= NULL
;
3853 struct lttcomm_event_command_header cmd_header
;
3856 memset(&cmd_header
, 0, sizeof(cmd_header
));
3857 /* Extended infos are included at the end of events */
3858 nb_event
= cmd_list_events(cmd_ctx
->lsm
->domain
.type
,
3859 cmd_ctx
->session
, cmd_ctx
->lsm
->u
.list
.channel_name
,
3860 &events
, &total_size
);
3863 /* Return value is a negative lttng_error_code. */
3868 cmd_header
.nb_events
= nb_event
;
3869 ret
= setup_lttng_msg(cmd_ctx
, events
, total_size
,
3870 &cmd_header
, sizeof(cmd_header
));
3880 case LTTNG_LIST_SESSIONS
:
3882 unsigned int nr_sessions
;
3883 void *sessions_payload
;
3886 session_lock_list();
3887 nr_sessions
= lttng_sessions_count(
3888 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
3889 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
3890 payload_len
= sizeof(struct lttng_session
) * nr_sessions
;
3891 sessions_payload
= zmalloc(payload_len
);
3893 if (!sessions_payload
) {
3894 session_unlock_list();
3899 cmd_list_lttng_sessions(sessions_payload
,
3900 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
3901 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
3902 session_unlock_list();
3904 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, sessions_payload
,
3906 free(sessions_payload
);
3915 case LTTNG_REGISTER_CONSUMER
:
3917 struct consumer_data
*cdata
;
3919 switch (cmd_ctx
->lsm
->domain
.type
) {
3920 case LTTNG_DOMAIN_KERNEL
:
3921 cdata
= &kconsumer_data
;
3924 ret
= LTTNG_ERR_UND
;
3928 ret
= cmd_register_consumer(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
3929 cmd_ctx
->lsm
->u
.reg
.path
, cdata
);
3932 case LTTNG_DATA_PENDING
:
3935 uint8_t pending_ret_byte
;
3937 pending_ret
= cmd_data_pending(cmd_ctx
->session
);
3942 * This function may returns 0 or 1 to indicate whether or not
3943 * there is data pending. In case of error, it should return an
3944 * LTTNG_ERR code. However, some code paths may still return
3945 * a nondescript error code, which we handle by returning an
3948 if (pending_ret
== 0 || pending_ret
== 1) {
3950 * ret will be set to LTTNG_OK at the end of
3953 } else if (pending_ret
< 0) {
3954 ret
= LTTNG_ERR_UNK
;
3961 pending_ret_byte
= (uint8_t) pending_ret
;
3963 /* 1 byte to return whether or not data is pending */
3964 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
3965 &pending_ret_byte
, 1);
3974 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
3976 struct lttcomm_lttng_output_id reply
;
3978 ret
= cmd_snapshot_add_output(cmd_ctx
->session
,
3979 &cmd_ctx
->lsm
->u
.snapshot_output
.output
, &reply
.id
);
3980 if (ret
!= LTTNG_OK
) {
3984 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &reply
,
3990 /* Copy output list into message payload */
3994 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
3996 ret
= cmd_snapshot_del_output(cmd_ctx
->session
,
3997 &cmd_ctx
->lsm
->u
.snapshot_output
.output
);
4000 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
4003 struct lttng_snapshot_output
*outputs
= NULL
;
4005 nb_output
= cmd_snapshot_list_outputs(cmd_ctx
->session
, &outputs
);
4006 if (nb_output
< 0) {
4011 assert((nb_output
> 0 && outputs
) || nb_output
== 0);
4012 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, outputs
,
4013 nb_output
* sizeof(struct lttng_snapshot_output
));
4023 case LTTNG_SNAPSHOT_RECORD
:
4025 ret
= cmd_snapshot_record(cmd_ctx
->session
,
4026 &cmd_ctx
->lsm
->u
.snapshot_record
.output
,
4027 cmd_ctx
->lsm
->u
.snapshot_record
.wait
);
4030 case LTTNG_CREATE_SESSION_SNAPSHOT
:
4033 struct lttng_uri
*uris
= NULL
;
4035 nb_uri
= cmd_ctx
->lsm
->u
.uri
.size
;
4036 len
= nb_uri
* sizeof(struct lttng_uri
);
4039 uris
= zmalloc(len
);
4041 ret
= LTTNG_ERR_FATAL
;
4045 /* Receive variable len data */
4046 DBG("Waiting for %zu URIs from client ...", nb_uri
);
4047 ret
= lttcomm_recv_unix_sock(sock
, uris
, len
);
4049 DBG("No URIs received from client... continuing");
4051 ret
= LTTNG_ERR_SESSION_FAIL
;
4056 if (nb_uri
== 1 && uris
[0].dtype
!= LTTNG_DST_PATH
) {
4057 DBG("Creating session with ONE network URI is a bad call");
4058 ret
= LTTNG_ERR_SESSION_FAIL
;
4064 ret
= cmd_create_session_snapshot(cmd_ctx
->lsm
->session
.name
, uris
,
4065 nb_uri
, &cmd_ctx
->creds
);
4069 case LTTNG_CREATE_SESSION_LIVE
:
4072 struct lttng_uri
*uris
= NULL
;
4074 nb_uri
= cmd_ctx
->lsm
->u
.uri
.size
;
4075 len
= nb_uri
* sizeof(struct lttng_uri
);
4078 uris
= zmalloc(len
);
4080 ret
= LTTNG_ERR_FATAL
;
4084 /* Receive variable len data */
4085 DBG("Waiting for %zu URIs from client ...", nb_uri
);
4086 ret
= lttcomm_recv_unix_sock(sock
, uris
, len
);
4088 DBG("No URIs received from client... continuing");
4090 ret
= LTTNG_ERR_SESSION_FAIL
;
4095 if (nb_uri
== 1 && uris
[0].dtype
!= LTTNG_DST_PATH
) {
4096 DBG("Creating session with ONE network URI is a bad call");
4097 ret
= LTTNG_ERR_SESSION_FAIL
;
4103 ret
= cmd_create_session_uri(cmd_ctx
->lsm
->session
.name
, uris
,
4104 nb_uri
, &cmd_ctx
->creds
, cmd_ctx
->lsm
->u
.session_live
.timer_interval
);
4108 case LTTNG_SAVE_SESSION
:
4110 ret
= cmd_save_sessions(&cmd_ctx
->lsm
->u
.save_session
.attr
,
4114 case LTTNG_SET_SESSION_SHM_PATH
:
4116 ret
= cmd_set_session_shm_path(cmd_ctx
->session
,
4117 cmd_ctx
->lsm
->u
.set_shm_path
.shm_path
);
4120 case LTTNG_REGENERATE_METADATA
:
4122 ret
= cmd_regenerate_metadata(cmd_ctx
->session
);
4125 case LTTNG_REGENERATE_STATEDUMP
:
4127 ret
= cmd_regenerate_statedump(cmd_ctx
->session
);
4130 case LTTNG_REGISTER_TRIGGER
:
4132 ret
= cmd_register_trigger(cmd_ctx
, sock
,
4133 notification_thread_handle
);
4136 case LTTNG_UNREGISTER_TRIGGER
:
4138 ret
= cmd_unregister_trigger(cmd_ctx
, sock
,
4139 notification_thread_handle
);
4142 case LTTNG_ROTATE_SESSION
:
4144 struct lttng_rotate_session_return rotate_return
;
4146 DBG("Client rotate session \"%s\"", cmd_ctx
->session
->name
);
4148 memset(&rotate_return
, 0, sizeof(rotate_return
));
4149 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
4150 DBG("Kernel tracer version is not compatible with the rotation feature");
4151 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
4155 ret
= cmd_rotate_session(cmd_ctx
->session
, &rotate_return
);
4161 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &rotate_return
,
4162 sizeof(rotate_return
));
4171 case LTTNG_ROTATION_GET_INFO
:
4173 struct lttng_rotation_get_info_return get_info_return
;
4175 memset(&get_info_return
, 0, sizeof(get_info_return
));
4176 ret
= cmd_rotate_get_info(cmd_ctx
->session
, &get_info_return
,
4177 cmd_ctx
->lsm
->u
.get_rotation_info
.rotation_id
);
4183 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &get_info_return
,
4184 sizeof(get_info_return
));
4193 case LTTNG_SESSION_GET_CURRENT_OUTPUT
:
4195 struct lttng_session_get_current_output_return output_return
;
4197 memset(&output_return
, 0, sizeof(output_return
));
4198 ret
= cmd_session_get_current_output(cmd_ctx
->session
,
4205 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &output_return
,
4206 sizeof(output_return
));
4215 case LTTNG_ROTATION_SET_SCHEDULE
:
4217 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
4218 DBG("Kernel tracer version does not support session rotations");
4219 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
4223 ret
= cmd_rotation_set_schedule(cmd_ctx
->session
,
4224 cmd_ctx
->lsm
->u
.rotate_setup
.timer_us
,
4225 cmd_ctx
->lsm
->u
.rotate_setup
.size
,
4226 notification_thread_handle
);
4227 if (ret
!= LTTNG_OK
) {
4233 case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD
:
4235 struct lttng_rotation_schedule_get_timer_period
*get_timer
;
4237 get_timer
= zmalloc(sizeof(struct lttng_rotation_schedule_get_timer_period
));
4242 get_timer
->rotate_timer
= cmd_ctx
->session
->rotate_timer_period
;
4244 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, get_timer
,
4245 sizeof(struct lttng_rotation_schedule_get_timer_period
));
4255 case LTTNG_ROTATION_SCHEDULE_GET_SIZE
:
4257 struct lttng_rotation_schedule_get_size
*get_size
;
4259 get_size
= zmalloc(sizeof(struct lttng_rotation_schedule_get_size
));
4264 get_size
->rotate_size
= cmd_ctx
->session
->rotate_size
;
4266 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, get_size
,
4267 sizeof(struct lttng_rotation_schedule_get_size
));
4278 ret
= LTTNG_ERR_UND
;
4283 if (cmd_ctx
->llm
== NULL
) {
4284 DBG("Missing llm structure. Allocating one.");
4285 if (setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0) < 0) {
4289 /* Set return code */
4290 cmd_ctx
->llm
->ret_code
= ret
;
4292 if (cmd_ctx
->session
) {
4293 session_unlock(cmd_ctx
->session
);
4295 if (need_tracing_session
) {
4296 session_unlock_list();
4299 assert(!rcu_read_ongoing());
4304 * Thread managing health check socket.
4306 static void *thread_manage_health(void *data
)
4308 int sock
= -1, new_sock
= -1, ret
, i
, pollfd
, err
= -1;
4309 uint32_t revents
, nb_fd
;
4310 struct lttng_poll_event events
;
4311 struct health_comm_msg msg
;
4312 struct health_comm_reply reply
;
4314 DBG("[thread] Manage health check started");
4316 rcu_register_thread();
4318 /* We might hit an error path before this is created. */
4319 lttng_poll_init(&events
);
4321 /* Create unix socket */
4322 sock
= lttcomm_create_unix_sock(config
.health_unix_sock_path
.value
);
4324 ERR("Unable to create health check Unix socket");
4329 /* lttng health client socket path permissions */
4330 ret
= chown(config
.health_unix_sock_path
.value
, 0,
4331 utils_get_group_id(config
.tracing_group_name
.value
));
4333 ERR("Unable to set group on %s", config
.health_unix_sock_path
.value
);
4338 ret
= chmod(config
.health_unix_sock_path
.value
,
4339 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
4341 ERR("Unable to set permissions on %s", config
.health_unix_sock_path
.value
);
4348 * Set the CLOEXEC flag. Return code is useless because either way, the
4351 (void) utils_set_fd_cloexec(sock
);
4353 ret
= lttcomm_listen_unix_sock(sock
);
4359 * Pass 2 as size here for the thread quit pipe and client_sock. Nothing
4360 * more will be added to this poll set.
4362 ret
= sessiond_set_thread_pollset(&events
, 2);
4367 /* Add the application registration socket */
4368 ret
= lttng_poll_add(&events
, sock
, LPOLLIN
| LPOLLPRI
);
4373 sessiond_notify_ready();
4376 DBG("Health check ready");
4378 /* Inifinite blocking call, waiting for transmission */
4380 ret
= lttng_poll_wait(&events
, -1);
4383 * Restart interrupted system call.
4385 if (errno
== EINTR
) {
4393 for (i
= 0; i
< nb_fd
; i
++) {
4394 /* Fetch once the poll data */
4395 revents
= LTTNG_POLL_GETEV(&events
, i
);
4396 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
4399 /* No activity for this FD (poll implementation). */
4403 /* Thread quit pipe has been closed. Killing thread. */
4404 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
4410 /* Event on the registration socket */
4411 if (pollfd
== sock
) {
4412 if (revents
& LPOLLIN
) {
4414 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
4415 ERR("Health socket poll error");
4418 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
4424 new_sock
= lttcomm_accept_unix_sock(sock
);
4430 * Set the CLOEXEC flag. Return code is useless because either way, the
4433 (void) utils_set_fd_cloexec(new_sock
);
4435 DBG("Receiving data from client for health...");
4436 ret
= lttcomm_recv_unix_sock(new_sock
, (void *)&msg
, sizeof(msg
));
4438 DBG("Nothing recv() from client... continuing");
4439 ret
= close(new_sock
);
4446 rcu_thread_online();
4448 memset(&reply
, 0, sizeof(reply
));
4449 for (i
= 0; i
< NR_HEALTH_SESSIOND_TYPES
; i
++) {
4451 * health_check_state returns 0 if health is
4454 if (!health_check_state(health_sessiond
, i
)) {
4455 reply
.ret_code
|= 1ULL << i
;
4459 DBG2("Health check return value %" PRIx64
, reply
.ret_code
);
4461 ret
= send_unix_sock(new_sock
, (void *) &reply
, sizeof(reply
));
4463 ERR("Failed to send health data back to client");
4466 /* End of transmission */
4467 ret
= close(new_sock
);
4476 ERR("Health error occurred in %s", __func__
);
4478 DBG("Health check thread dying");
4479 unlink(config
.health_unix_sock_path
.value
);
4487 lttng_poll_clean(&events
);
4489 rcu_unregister_thread();
4494 * This thread manage all clients request using the unix client socket for
4497 static void *thread_manage_clients(void *data
)
4499 int sock
= -1, ret
, i
, pollfd
, err
= -1;
4501 uint32_t revents
, nb_fd
;
4502 struct command_ctx
*cmd_ctx
= NULL
;
4503 struct lttng_poll_event events
;
4505 DBG("[thread] Manage client started");
4507 rcu_register_thread();
4509 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_CMD
);
4511 health_code_update();
4513 ret
= lttcomm_listen_unix_sock(client_sock
);
4519 * Pass 2 as size here for the thread quit pipe and client_sock. Nothing
4520 * more will be added to this poll set.
4522 ret
= sessiond_set_thread_pollset(&events
, 2);
4524 goto error_create_poll
;
4527 /* Add the application registration socket */
4528 ret
= lttng_poll_add(&events
, client_sock
, LPOLLIN
| LPOLLPRI
);
4533 ret
= sem_post(&load_info
->message_thread_ready
);
4535 PERROR("sem_post message_thread_ready");
4540 * Wait until all support threads are initialized before accepting
4543 while (uatomic_read(<tng_sessiond_ready
) != 0) {
4545 struct timeval timeout
;
4548 FD_SET(thread_quit_pipe
[0], &read_fds
);
4549 memset(&timeout
, 0, sizeof(timeout
));
4550 timeout
.tv_usec
= 1000;
4553 * If a support thread failed to launch, it may signal that
4554 * we must exit and the sessiond would never be marked as
4557 * The timeout is set to 1ms, which serves as a way to
4558 * pace down this check.
4560 ret
= select(thread_quit_pipe
[0] + 1, &read_fds
, NULL
, NULL
,
4562 if (ret
> 0 || (ret
< 0 && errno
!= EINTR
)) {
4568 /* This testpoint is after we signal readiness to the parent. */
4569 if (testpoint(sessiond_thread_manage_clients
)) {
4573 if (testpoint(sessiond_thread_manage_clients_before_loop
)) {
4577 health_code_update();
4580 DBG("Accepting client command ...");
4582 /* Inifinite blocking call, waiting for transmission */
4584 health_poll_entry();
4585 ret
= lttng_poll_wait(&events
, -1);
4589 * Restart interrupted system call.
4591 if (errno
== EINTR
) {
4599 for (i
= 0; i
< nb_fd
; i
++) {
4600 /* Fetch once the poll data */
4601 revents
= LTTNG_POLL_GETEV(&events
, i
);
4602 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
4604 health_code_update();
4607 /* No activity for this FD (poll implementation). */
4611 /* Thread quit pipe has been closed. Killing thread. */
4612 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
4618 /* Event on the registration socket */
4619 if (pollfd
== client_sock
) {
4620 if (revents
& LPOLLIN
) {
4622 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
4623 ERR("Client socket poll error");
4626 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
4632 DBG("Wait for client response");
4634 health_code_update();
4636 sock
= lttcomm_accept_unix_sock(client_sock
);
4642 * Set the CLOEXEC flag. Return code is useless because either way, the
4645 (void) utils_set_fd_cloexec(sock
);
4647 /* Set socket option for credentials retrieval */
4648 ret
= lttcomm_setsockopt_creds_unix_sock(sock
);
4653 /* Allocate context command to process the client request */
4654 cmd_ctx
= zmalloc(sizeof(struct command_ctx
));
4655 if (cmd_ctx
== NULL
) {
4656 PERROR("zmalloc cmd_ctx");
4660 /* Allocate data buffer for reception */
4661 cmd_ctx
->lsm
= zmalloc(sizeof(struct lttcomm_session_msg
));
4662 if (cmd_ctx
->lsm
== NULL
) {
4663 PERROR("zmalloc cmd_ctx->lsm");
4667 cmd_ctx
->llm
= NULL
;
4668 cmd_ctx
->session
= NULL
;
4670 health_code_update();
4673 * Data is received from the lttng client. The struct
4674 * lttcomm_session_msg (lsm) contains the command and data request of
4677 DBG("Receiving data from client ...");
4678 ret
= lttcomm_recv_creds_unix_sock(sock
, cmd_ctx
->lsm
,
4679 sizeof(struct lttcomm_session_msg
), &cmd_ctx
->creds
);
4681 DBG("Nothing recv() from client... continuing");
4687 clean_command_ctx(&cmd_ctx
);
4691 health_code_update();
4693 // TODO: Validate cmd_ctx including sanity check for
4694 // security purpose.
4696 rcu_thread_online();
4698 * This function dispatch the work to the kernel or userspace tracer
4699 * libs and fill the lttcomm_lttng_msg data structure of all the needed
4700 * informations for the client. The command context struct contains
4701 * everything this function may needs.
4703 ret
= process_client_msg(cmd_ctx
, sock
, &sock_error
);
4704 rcu_thread_offline();
4712 * TODO: Inform client somehow of the fatal error. At
4713 * this point, ret < 0 means that a zmalloc failed
4714 * (ENOMEM). Error detected but still accept
4715 * command, unless a socket error has been
4718 clean_command_ctx(&cmd_ctx
);
4722 health_code_update();
4724 DBG("Sending response (size: %d, retcode: %s (%d))",
4725 cmd_ctx
->lttng_msg_size
,
4726 lttng_strerror(-cmd_ctx
->llm
->ret_code
),
4727 cmd_ctx
->llm
->ret_code
);
4728 ret
= send_unix_sock(sock
, cmd_ctx
->llm
, cmd_ctx
->lttng_msg_size
);
4730 ERR("Failed to send data back to client");
4733 /* End of transmission */
4740 clean_command_ctx(&cmd_ctx
);
4742 health_code_update();
4754 lttng_poll_clean(&events
);
4755 clean_command_ctx(&cmd_ctx
);
4759 unlink(config
.client_unix_sock_path
.value
);
4760 if (client_sock
>= 0) {
4761 ret
= close(client_sock
);
4769 ERR("Health error occurred in %s", __func__
);
4772 health_unregister(health_sessiond
);
4774 DBG("Client thread dying");
4776 rcu_unregister_thread();
4779 * Since we are creating the consumer threads, we own them, so we need
4780 * to join them before our thread exits.
4782 ret
= join_consumer_thread(&kconsumer_data
);
4785 PERROR("join_consumer");
4788 ret
= join_consumer_thread(&ustconsumer32_data
);
4791 PERROR("join_consumer ust32");
4794 ret
= join_consumer_thread(&ustconsumer64_data
);
4797 PERROR("join_consumer ust64");
4802 static int string_match(const char *str1
, const char *str2
)
4804 return (str1
&& str2
) && !strcmp(str1
, str2
);
4808 * Take an option from the getopt output and set it in the right variable to be
4811 * Return 0 on success else a negative value.
4813 static int set_option(int opt
, const char *arg
, const char *optname
)
4817 if (string_match(optname
, "client-sock") || opt
== 'c') {
4818 if (!arg
|| *arg
== '\0') {
4822 if (lttng_is_setuid_setgid()) {
4823 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4824 "-c, --client-sock");
4826 config_string_set(&config
.client_unix_sock_path
,
4828 if (!config
.client_unix_sock_path
.value
) {
4833 } else if (string_match(optname
, "apps-sock") || opt
== 'a') {
4834 if (!arg
|| *arg
== '\0') {
4838 if (lttng_is_setuid_setgid()) {
4839 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4842 config_string_set(&config
.apps_unix_sock_path
,
4844 if (!config
.apps_unix_sock_path
.value
) {
4849 } else if (string_match(optname
, "daemonize") || opt
== 'd') {
4850 config
.daemonize
= true;
4851 } else if (string_match(optname
, "background") || opt
== 'b') {
4852 config
.background
= true;
4853 } else if (string_match(optname
, "group") || opt
== 'g') {
4854 if (!arg
|| *arg
== '\0') {
4858 if (lttng_is_setuid_setgid()) {
4859 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4862 config_string_set(&config
.tracing_group_name
,
4864 if (!config
.tracing_group_name
.value
) {
4869 } else if (string_match(optname
, "help") || opt
== 'h') {
4870 ret
= utils_show_help(8, "lttng-sessiond", help_msg
);
4872 ERR("Cannot show --help for `lttng-sessiond`");
4875 exit(ret
? EXIT_FAILURE
: EXIT_SUCCESS
);
4876 } else if (string_match(optname
, "version") || opt
== 'V') {
4877 fprintf(stdout
, "%s\n", VERSION
);
4879 } else if (string_match(optname
, "sig-parent") || opt
== 'S') {
4880 config
.sig_parent
= true;
4881 } else if (string_match(optname
, "kconsumerd-err-sock")) {
4882 if (!arg
|| *arg
== '\0') {
4886 if (lttng_is_setuid_setgid()) {
4887 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4888 "--kconsumerd-err-sock");
4890 config_string_set(&config
.kconsumerd_err_unix_sock_path
,
4892 if (!config
.kconsumerd_err_unix_sock_path
.value
) {
4897 } else if (string_match(optname
, "kconsumerd-cmd-sock")) {
4898 if (!arg
|| *arg
== '\0') {
4902 if (lttng_is_setuid_setgid()) {
4903 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4904 "--kconsumerd-cmd-sock");
4906 config_string_set(&config
.kconsumerd_cmd_unix_sock_path
,
4908 if (!config
.kconsumerd_cmd_unix_sock_path
.value
) {
4913 } else if (string_match(optname
, "ustconsumerd64-err-sock")) {
4914 if (!arg
|| *arg
== '\0') {
4918 if (lttng_is_setuid_setgid()) {
4919 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4920 "--ustconsumerd64-err-sock");
4922 config_string_set(&config
.consumerd64_err_unix_sock_path
,
4924 if (!config
.consumerd64_err_unix_sock_path
.value
) {
4929 } else if (string_match(optname
, "ustconsumerd64-cmd-sock")) {
4930 if (!arg
|| *arg
== '\0') {
4934 if (lttng_is_setuid_setgid()) {
4935 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4936 "--ustconsumerd64-cmd-sock");
4938 config_string_set(&config
.consumerd64_cmd_unix_sock_path
,
4940 if (!config
.consumerd64_cmd_unix_sock_path
.value
) {
4945 } else if (string_match(optname
, "ustconsumerd32-err-sock")) {
4946 if (!arg
|| *arg
== '\0') {
4950 if (lttng_is_setuid_setgid()) {
4951 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4952 "--ustconsumerd32-err-sock");
4954 config_string_set(&config
.consumerd32_err_unix_sock_path
,
4956 if (!config
.consumerd32_err_unix_sock_path
.value
) {
4961 } else if (string_match(optname
, "ustconsumerd32-cmd-sock")) {
4962 if (!arg
|| *arg
== '\0') {
4966 if (lttng_is_setuid_setgid()) {
4967 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
4968 "--ustconsumerd32-cmd-sock");
4970 config_string_set(&config
.consumerd32_cmd_unix_sock_path
,
4972 if (!config
.consumerd32_cmd_unix_sock_path
.value
) {
4977 } else if (string_match(optname
, "no-kernel")) {
4978 config
.no_kernel
= true;
4979 } else if (string_match(optname
, "quiet") || opt
== 'q') {
4980 config
.quiet
= true;
4981 } else if (string_match(optname
, "verbose") || opt
== 'v') {
4982 /* Verbose level can increase using multiple -v */
4984 /* Value obtained from config file */
4985 config
.verbose
= config_parse_value(arg
);
4987 /* -v used on command line */
4990 /* Clamp value to [0, 3] */
4991 config
.verbose
= config
.verbose
< 0 ? 0 :
4992 (config
.verbose
<= 3 ? config
.verbose
: 3);
4993 } else if (string_match(optname
, "verbose-consumer")) {
4995 config
.verbose_consumer
= config_parse_value(arg
);
4997 config
.verbose_consumer
++;
4999 } else if (string_match(optname
, "consumerd32-path")) {
5000 if (!arg
|| *arg
== '\0') {
5004 if (lttng_is_setuid_setgid()) {
5005 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5006 "--consumerd32-path");
5008 config_string_set(&config
.consumerd32_bin_path
,
5010 if (!config
.consumerd32_bin_path
.value
) {
5015 } else if (string_match(optname
, "consumerd32-libdir")) {
5016 if (!arg
|| *arg
== '\0') {
5020 if (lttng_is_setuid_setgid()) {
5021 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5022 "--consumerd32-libdir");
5024 config_string_set(&config
.consumerd32_lib_dir
,
5026 if (!config
.consumerd32_lib_dir
.value
) {
5031 } else if (string_match(optname
, "consumerd64-path")) {
5032 if (!arg
|| *arg
== '\0') {
5036 if (lttng_is_setuid_setgid()) {
5037 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5038 "--consumerd64-path");
5040 config_string_set(&config
.consumerd64_bin_path
,
5042 if (!config
.consumerd64_bin_path
.value
) {
5047 } else if (string_match(optname
, "consumerd64-libdir")) {
5048 if (!arg
|| *arg
== '\0') {
5052 if (lttng_is_setuid_setgid()) {
5053 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5054 "--consumerd64-libdir");
5056 config_string_set(&config
.consumerd64_lib_dir
,
5058 if (!config
.consumerd64_lib_dir
.value
) {
5063 } else if (string_match(optname
, "pidfile") || opt
== 'p') {
5064 if (!arg
|| *arg
== '\0') {
5068 if (lttng_is_setuid_setgid()) {
5069 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5072 config_string_set(&config
.pid_file_path
, strdup(arg
));
5073 if (!config
.pid_file_path
.value
) {
5078 } else if (string_match(optname
, "agent-tcp-port")) {
5079 if (!arg
|| *arg
== '\0') {
5083 if (lttng_is_setuid_setgid()) {
5084 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5085 "--agent-tcp-port");
5090 v
= strtoul(arg
, NULL
, 0);
5091 if (errno
!= 0 || !isdigit(arg
[0])) {
5092 ERR("Wrong value in --agent-tcp-port parameter: %s", arg
);
5095 if (v
== 0 || v
>= 65535) {
5096 ERR("Port overflow in --agent-tcp-port parameter: %s", arg
);
5099 config
.agent_tcp_port
.begin
= config
.agent_tcp_port
.end
= (int) v
;
5100 DBG3("Agent TCP port set to non default: %i", (int) v
);
5102 } else if (string_match(optname
, "load") || opt
== 'l') {
5103 if (!arg
|| *arg
== '\0') {
5107 if (lttng_is_setuid_setgid()) {
5108 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5111 config_string_set(&config
.load_session_path
, strdup(arg
));
5112 if (!config
.load_session_path
.value
) {
5117 } else if (string_match(optname
, "kmod-probes")) {
5118 if (!arg
|| *arg
== '\0') {
5122 if (lttng_is_setuid_setgid()) {
5123 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5126 config_string_set(&config
.kmod_probes_list
, strdup(arg
));
5127 if (!config
.kmod_probes_list
.value
) {
5132 } else if (string_match(optname
, "extra-kmod-probes")) {
5133 if (!arg
|| *arg
== '\0') {
5137 if (lttng_is_setuid_setgid()) {
5138 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5139 "--extra-kmod-probes");
5141 config_string_set(&config
.kmod_extra_probes_list
,
5143 if (!config
.kmod_extra_probes_list
.value
) {
5148 } else if (string_match(optname
, "config") || opt
== 'f') {
5149 /* This is handled in set_options() thus silent skip. */
5152 /* Unknown option or other error.
5153 * Error is printed by getopt, just return */
5158 if (ret
== -EINVAL
) {
5159 const char *opt_name
= "unknown";
5162 for (i
= 0; i
< sizeof(long_options
) / sizeof(struct option
);
5164 if (opt
== long_options
[i
].val
) {
5165 opt_name
= long_options
[i
].name
;
5170 WARN("Invalid argument provided for option \"%s\", using default value.",
5178 * config_entry_handler_cb used to handle options read from a config file.
5179 * See config_entry_handler_cb comment in common/config/session-config.h for the
5180 * return value conventions.
5182 static int config_entry_handler(const struct config_entry
*entry
, void *unused
)
5186 if (!entry
|| !entry
->name
|| !entry
->value
) {
5191 /* Check if the option is to be ignored */
5192 for (i
= 0; i
< sizeof(config_ignore_options
) / sizeof(char *); i
++) {
5193 if (!strcmp(entry
->name
, config_ignore_options
[i
])) {
5198 for (i
= 0; i
< (sizeof(long_options
) / sizeof(struct option
)) - 1;
5201 /* Ignore if not fully matched. */
5202 if (strcmp(entry
->name
, long_options
[i
].name
)) {
5207 * If the option takes no argument on the command line, we have to
5208 * check if the value is "true". We support non-zero numeric values,
5211 if (!long_options
[i
].has_arg
) {
5212 ret
= config_parse_value(entry
->value
);
5215 WARN("Invalid configuration value \"%s\" for option %s",
5216 entry
->value
, entry
->name
);
5218 /* False, skip boolean config option. */
5223 ret
= set_option(long_options
[i
].val
, entry
->value
, entry
->name
);
5227 WARN("Unrecognized option \"%s\" in daemon configuration file.", entry
->name
);
5234 * daemon configuration loading and argument parsing
5236 static int set_options(int argc
, char **argv
)
5238 int ret
= 0, c
= 0, option_index
= 0;
5239 int orig_optopt
= optopt
, orig_optind
= optind
;
5241 const char *config_path
= NULL
;
5243 optstring
= utils_generate_optstring(long_options
,
5244 sizeof(long_options
) / sizeof(struct option
));
5250 /* Check for the --config option */
5251 while ((c
= getopt_long(argc
, argv
, optstring
, long_options
,
5252 &option_index
)) != -1) {
5256 } else if (c
!= 'f') {
5257 /* if not equal to --config option. */
5261 if (lttng_is_setuid_setgid()) {
5262 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
5265 config_path
= utils_expand_path(optarg
);
5267 ERR("Failed to resolve path: %s", optarg
);
5272 ret
= config_get_section_entries(config_path
, config_section_name
,
5273 config_entry_handler
, NULL
);
5276 ERR("Invalid configuration option at line %i", ret
);
5282 /* Reset getopt's global state */
5283 optopt
= orig_optopt
;
5284 optind
= orig_optind
;
5288 * getopt_long() will not set option_index if it encounters a
5291 c
= getopt_long(argc
, argv
, optstring
, long_options
,
5298 * Pass NULL as the long option name if popt left the index
5301 ret
= set_option(c
, optarg
,
5302 option_index
< 0 ? NULL
:
5303 long_options
[option_index
].name
);
5315 * Creates the two needed socket by the daemon.
5316 * apps_sock - The communication socket for all UST apps.
5317 * client_sock - The communication of the cli tool (lttng).
5319 static int init_daemon_socket(void)
5324 old_umask
= umask(0);
5326 /* Create client tool unix socket */
5327 client_sock
= lttcomm_create_unix_sock(config
.client_unix_sock_path
.value
);
5328 if (client_sock
< 0) {
5329 ERR("Create unix sock failed: %s", config
.client_unix_sock_path
.value
);
5334 /* Set the cloexec flag */
5335 ret
= utils_set_fd_cloexec(client_sock
);
5337 ERR("Unable to set CLOEXEC flag to the client Unix socket (fd: %d). "
5338 "Continuing but note that the consumer daemon will have a "
5339 "reference to this socket on exec()", client_sock
);
5342 /* File permission MUST be 660 */
5343 ret
= chmod(config
.client_unix_sock_path
.value
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
5345 ERR("Set file permissions failed: %s", config
.client_unix_sock_path
.value
);
5350 /* Create the application unix socket */
5351 apps_sock
= lttcomm_create_unix_sock(config
.apps_unix_sock_path
.value
);
5352 if (apps_sock
< 0) {
5353 ERR("Create unix sock failed: %s", config
.apps_unix_sock_path
.value
);
5358 /* Set the cloexec flag */
5359 ret
= utils_set_fd_cloexec(apps_sock
);
5361 ERR("Unable to set CLOEXEC flag to the app Unix socket (fd: %d). "
5362 "Continuing but note that the consumer daemon will have a "
5363 "reference to this socket on exec()", apps_sock
);
5366 /* File permission MUST be 666 */
5367 ret
= chmod(config
.apps_unix_sock_path
.value
,
5368 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
);
5370 ERR("Set file permissions failed: %s", config
.apps_unix_sock_path
.value
);
5375 DBG3("Session daemon client socket %d and application socket %d created",
5376 client_sock
, apps_sock
);
5384 * Create lockfile using the rundir and return its fd.
5386 static int create_lockfile(void)
5388 return utils_create_lock_file(config
.lock_file_path
.value
);
5392 * Check if the global socket is available, and if a daemon is answering at the
5393 * other side. If yes, error is returned.
5395 * Also attempts to create and hold the lock file.
5397 static int check_existing_daemon(void)
5401 /* Is there anybody out there ? */
5402 if (lttng_session_daemon_alive()) {
5407 lockfile_fd
= create_lockfile();
5408 if (lockfile_fd
< 0) {
5416 static void sessiond_cleanup_lock_file(void)
5421 * Cleanup lock file by deleting it and finaly closing it which will
5422 * release the file system lock.
5424 if (lockfile_fd
>= 0) {
5425 ret
= remove(config
.lock_file_path
.value
);
5427 PERROR("remove lock file");
5429 ret
= close(lockfile_fd
);
5431 PERROR("close lock file");
5437 * Set the tracing group gid onto the client socket.
5439 * Race window between mkdir and chown is OK because we are going from more
5440 * permissive (root.root) to less permissive (root.tracing).
5442 static int set_permissions(char *rundir
)
5447 gid
= utils_get_group_id(config
.tracing_group_name
.value
);
5449 /* Set lttng run dir */
5450 ret
= chown(rundir
, 0, gid
);
5452 ERR("Unable to set group on %s", rundir
);
5457 * Ensure all applications and tracing group can search the run
5458 * dir. Allow everyone to read the directory, since it does not
5459 * buy us anything to hide its content.
5461 ret
= chmod(rundir
, S_IRWXU
| S_IRGRP
| S_IXGRP
| S_IROTH
| S_IXOTH
);
5463 ERR("Unable to set permissions on %s", rundir
);
5467 /* lttng client socket path */
5468 ret
= chown(config
.client_unix_sock_path
.value
, 0, gid
);
5470 ERR("Unable to set group on %s", config
.client_unix_sock_path
.value
);
5474 /* kconsumer error socket path */
5475 ret
= chown(kconsumer_data
.err_unix_sock_path
, 0, 0);
5477 ERR("Unable to set group on %s", kconsumer_data
.err_unix_sock_path
);
5481 /* 64-bit ustconsumer error socket path */
5482 ret
= chown(ustconsumer64_data
.err_unix_sock_path
, 0, 0);
5484 ERR("Unable to set group on %s", ustconsumer64_data
.err_unix_sock_path
);
5488 /* 32-bit ustconsumer compat32 error socket path */
5489 ret
= chown(ustconsumer32_data
.err_unix_sock_path
, 0, 0);
5491 ERR("Unable to set group on %s", ustconsumer32_data
.err_unix_sock_path
);
5495 DBG("All permissions are set");
5501 * Create the lttng run directory needed for all global sockets and pipe.
5503 static int create_lttng_rundir(void)
5507 DBG3("Creating LTTng run directory: %s", config
.rundir
.value
);
5509 ret
= mkdir(config
.rundir
.value
, S_IRWXU
);
5511 if (errno
!= EEXIST
) {
5512 ERR("Unable to create %s", config
.rundir
.value
);
5524 * Setup sockets and directory needed by the consumerds' communication with the
5527 static int set_consumer_sockets(struct consumer_data
*consumer_data
)
5532 switch (consumer_data
->type
) {
5533 case LTTNG_CONSUMER_KERNEL
:
5534 path
= config
.kconsumerd_path
.value
;
5536 case LTTNG_CONSUMER64_UST
:
5537 path
= config
.consumerd64_path
.value
;
5539 case LTTNG_CONSUMER32_UST
:
5540 path
= config
.consumerd32_path
.value
;
5543 ERR("Consumer type unknown");
5549 DBG2("Creating consumer directory: %s", path
);
5551 ret
= mkdir(path
, S_IRWXU
| S_IRGRP
| S_IXGRP
);
5552 if (ret
< 0 && errno
!= EEXIST
) {
5554 ERR("Failed to create %s", path
);
5558 ret
= chown(path
, 0, utils_get_group_id(config
.tracing_group_name
.value
));
5560 ERR("Unable to set group on %s", path
);
5566 /* Create the consumerd error unix socket */
5567 consumer_data
->err_sock
=
5568 lttcomm_create_unix_sock(consumer_data
->err_unix_sock_path
);
5569 if (consumer_data
->err_sock
< 0) {
5570 ERR("Create unix sock failed: %s", consumer_data
->err_unix_sock_path
);
5576 * Set the CLOEXEC flag. Return code is useless because either way, the
5579 ret
= utils_set_fd_cloexec(consumer_data
->err_sock
);
5581 PERROR("utils_set_fd_cloexec");
5582 /* continue anyway */
5585 /* File permission MUST be 660 */
5586 ret
= chmod(consumer_data
->err_unix_sock_path
,
5587 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
5589 ERR("Set file permissions failed: %s", consumer_data
->err_unix_sock_path
);
5599 * Signal handler for the daemon
5601 * Simply stop all worker threads, leaving main() return gracefully after
5602 * joining all threads and calling cleanup().
5604 static void sighandler(int sig
)
5608 DBG("SIGINT caught");
5612 DBG("SIGTERM caught");
5616 CMM_STORE_SHARED(recv_child_signal
, 1);
5624 * Setup signal handler for :
5625 * SIGINT, SIGTERM, SIGPIPE
5627 static int set_signal_handler(void)
5630 struct sigaction sa
;
5633 if ((ret
= sigemptyset(&sigset
)) < 0) {
5634 PERROR("sigemptyset");
5638 sa
.sa_mask
= sigset
;
5641 sa
.sa_handler
= sighandler
;
5642 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
5643 PERROR("sigaction");
5647 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
5648 PERROR("sigaction");
5652 if ((ret
= sigaction(SIGUSR1
, &sa
, NULL
)) < 0) {
5653 PERROR("sigaction");
5657 sa
.sa_handler
= SIG_IGN
;
5658 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
5659 PERROR("sigaction");
5663 DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
5669 * Set open files limit to unlimited. This daemon can open a large number of
5670 * file descriptors in order to consume multiple kernel traces.
5672 static void set_ulimit(void)
5677 /* The kernel does not allow an infinite limit for open files */
5678 lim
.rlim_cur
= 65535;
5679 lim
.rlim_max
= 65535;
5681 ret
= setrlimit(RLIMIT_NOFILE
, &lim
);
5683 PERROR("failed to set open files limit");
5687 static int write_pidfile(void)
5689 return utils_create_pid_file(getpid(), config
.pid_file_path
.value
);
5692 static int set_clock_plugin_env(void)
5695 char *env_value
= NULL
;
5697 if (!config
.lttng_ust_clock_plugin
.value
) {
5701 ret
= asprintf(&env_value
, "LTTNG_UST_CLOCK_PLUGIN=%s",
5702 config
.lttng_ust_clock_plugin
.value
);
5708 ret
= putenv(env_value
);
5711 PERROR("putenv of LTTNG_UST_CLOCK_PLUGIN");
5715 DBG("Updated LTTNG_UST_CLOCK_PLUGIN environment variable to \"%s\"",
5716 config
.lttng_ust_clock_plugin
.value
);
5722 struct rotation_thread_timer_queue
*create_rotate_timer_queue(void)
5724 struct rotation_thread_timer_queue
*queue
= NULL
;
5726 queue
= zmalloc(sizeof(struct rotation_thread_timer_queue
));
5728 PERROR("Failed to allocate timer rotate queue");
5732 queue
->event_pipe
= lttng_pipe_open(FD_CLOEXEC
| O_NONBLOCK
);
5733 CDS_INIT_LIST_HEAD(&queue
->list
);
5734 pthread_mutex_init(&queue
->lock
, NULL
);
5741 void destroy_rotate_timer_queue(struct rotation_thread_timer_queue
*queue
)
5743 struct sessiond_rotation_timer
*node
, *tmp_node
;
5749 lttng_pipe_destroy(queue
->event_pipe
);
5751 pthread_mutex_lock(&queue
->lock
);
5752 /* Empty wait queue. */
5753 cds_list_for_each_entry_safe(node
, tmp_node
, &queue
->list
, head
) {
5754 cds_list_del(&node
->head
);
5757 pthread_mutex_unlock(&queue
->lock
);
5759 pthread_mutex_destroy(&queue
->lock
);
5766 int main(int argc
, char **argv
)
5768 int ret
= 0, retval
= 0;
5770 const char *env_app_timeout
;
5771 struct lttng_pipe
*ust32_channel_monitor_pipe
= NULL
,
5772 *ust64_channel_monitor_pipe
= NULL
,
5773 *kernel_channel_monitor_pipe
= NULL
;
5774 bool notification_thread_launched
= false;
5775 bool rotation_thread_launched
= false;
5776 bool timer_thread_launched
= false;
5777 struct lttng_pipe
*ust32_channel_rotate_pipe
= NULL
,
5778 *ust64_channel_rotate_pipe
= NULL
,
5779 *kernel_channel_rotate_pipe
= NULL
;
5780 struct timer_thread_parameters timer_thread_ctx
;
5781 /* Queue of rotation jobs populated by the sessiond-timer. */
5782 struct rotation_thread_timer_queue
*rotation_timer_queue
= NULL
;
5783 sem_t notification_thread_ready
;
5785 init_kernel_workarounds();
5787 rcu_register_thread();
5789 if (set_signal_handler()) {
5791 goto exit_set_signal_handler
;
5794 if (sessiond_timer_signal_init()) {
5796 goto exit_set_signal_handler
;
5799 page_size
= sysconf(_SC_PAGESIZE
);
5800 if (page_size
< 0) {
5801 PERROR("sysconf _SC_PAGESIZE");
5802 page_size
= LONG_MAX
;
5803 WARN("Fallback page size to %ld", page_size
);
5806 ret
= sessiond_config_init(&config
);
5809 goto exit_set_signal_handler
;
5813 * Parse arguments and load the daemon configuration file.
5815 * We have an exit_options exit path to free memory reserved by
5816 * set_options. This is needed because the rest of sessiond_cleanup()
5817 * depends on ht_cleanup_thread, which depends on lttng_daemonize, which
5818 * depends on set_options.
5821 if (set_options(argc
, argv
)) {
5826 /* Init config from environment variables. */
5827 sessiond_config_apply_env_config(&config
);
5830 * Resolve all paths received as arguments, configuration option, or
5831 * through environment variable as absolute paths. This is necessary
5832 * since daemonizing causes the sessiond's current working directory
5835 ret
= sessiond_config_resolve_paths(&config
);
5841 lttng_opt_verbose
= config
.verbose
;
5842 lttng_opt_quiet
= config
.quiet
;
5843 kconsumer_data
.err_unix_sock_path
=
5844 config
.kconsumerd_err_unix_sock_path
.value
;
5845 kconsumer_data
.cmd_unix_sock_path
=
5846 config
.kconsumerd_cmd_unix_sock_path
.value
;
5847 ustconsumer32_data
.err_unix_sock_path
=
5848 config
.consumerd32_err_unix_sock_path
.value
;
5849 ustconsumer32_data
.cmd_unix_sock_path
=
5850 config
.consumerd32_cmd_unix_sock_path
.value
;
5851 ustconsumer64_data
.err_unix_sock_path
=
5852 config
.consumerd64_err_unix_sock_path
.value
;
5853 ustconsumer64_data
.cmd_unix_sock_path
=
5854 config
.consumerd64_cmd_unix_sock_path
.value
;
5855 set_clock_plugin_env();
5857 sessiond_config_log(&config
);
5859 if (create_lttng_rundir()) {
5864 /* Abort launch if a session daemon is already running. */
5865 if (check_existing_daemon()) {
5866 ERR("A session daemon is already running.");
5872 if (config
.daemonize
|| config
.background
) {
5875 ret
= lttng_daemonize(&child_ppid
, &recv_child_signal
,
5876 !config
.background
);
5883 * We are in the child. Make sure all other file descriptors are
5884 * closed, in case we are called with more opened file
5885 * descriptors than the standard ones and the lock file.
5887 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
5888 if (i
== lockfile_fd
) {
5895 if (run_as_create_worker(argv
[0]) < 0) {
5896 goto exit_create_run_as_worker_cleanup
;
5900 * Starting from here, we can create threads. This needs to be after
5901 * lttng_daemonize due to RCU.
5905 * Initialize the health check subsystem. This call should set the
5906 * appropriate time values.
5908 health_sessiond
= health_app_create(NR_HEALTH_SESSIOND_TYPES
);
5909 if (!health_sessiond
) {
5910 PERROR("health_app_create error");
5912 goto exit_health_sessiond_cleanup
;
5915 /* Create thread to clean up RCU hash tables */
5916 if (init_ht_cleanup_thread(&ht_cleanup_thread
)) {
5918 goto exit_ht_cleanup
;
5921 /* Create thread quit pipe */
5922 if (init_thread_quit_pipe()) {
5924 goto exit_init_data
;
5927 /* Check if daemon is UID = 0 */
5928 is_root
= !getuid();
5930 /* Create global run dir with root access */
5932 kernel_channel_monitor_pipe
= lttng_pipe_open(0);
5933 if (!kernel_channel_monitor_pipe
) {
5934 ERR("Failed to create kernel consumer channel monitor pipe");
5936 goto exit_init_data
;
5938 kconsumer_data
.channel_monitor_pipe
=
5939 lttng_pipe_release_writefd(
5940 kernel_channel_monitor_pipe
);
5941 if (kconsumer_data
.channel_monitor_pipe
< 0) {
5943 goto exit_init_data
;
5945 kernel_channel_rotate_pipe
= lttng_pipe_open(0);
5946 if (!kernel_channel_rotate_pipe
) {
5947 ERR("Failed to create kernel consumer channel rotate pipe");
5949 goto exit_init_data
;
5951 kconsumer_data
.channel_rotate_pipe
=
5952 lttng_pipe_release_writefd(
5953 kernel_channel_rotate_pipe
);
5954 if (kconsumer_data
.channel_rotate_pipe
< 0) {
5956 goto exit_init_data
;
5960 /* Set consumer initial state */
5961 kernel_consumerd_state
= CONSUMER_STOPPED
;
5962 ust_consumerd_state
= CONSUMER_STOPPED
;
5964 ust32_channel_monitor_pipe
= lttng_pipe_open(0);
5965 if (!ust32_channel_monitor_pipe
) {
5966 ERR("Failed to create 32-bit user space consumer channel monitor pipe");
5968 goto exit_init_data
;
5970 ustconsumer32_data
.channel_monitor_pipe
= lttng_pipe_release_writefd(
5971 ust32_channel_monitor_pipe
);
5972 if (ustconsumer32_data
.channel_monitor_pipe
< 0) {
5974 goto exit_init_data
;
5976 ust32_channel_rotate_pipe
= lttng_pipe_open(0);
5977 if (!ust32_channel_rotate_pipe
) {
5978 ERR("Failed to create 32-bit user space consumer channel rotate pipe");
5980 goto exit_init_data
;
5982 ustconsumer32_data
.channel_rotate_pipe
= lttng_pipe_release_writefd(
5983 ust32_channel_rotate_pipe
);
5984 if (ustconsumer32_data
.channel_rotate_pipe
< 0) {
5986 goto exit_init_data
;
5990 * The rotation_timer_queue structure is shared between the sessiond timer
5991 * thread and the rotation thread. The main() keeps the ownership and
5992 * destroys it when both threads have quit.
5994 rotation_timer_queue
= create_rotate_timer_queue();
5995 if (!rotation_timer_queue
) {
5997 goto exit_init_data
;
5999 timer_thread_ctx
.rotation_timer_queue
= rotation_timer_queue
;
6001 ust64_channel_monitor_pipe
= lttng_pipe_open(0);
6002 if (!ust64_channel_monitor_pipe
) {
6003 ERR("Failed to create 64-bit user space consumer channel monitor pipe");
6005 goto exit_init_data
;
6007 ustconsumer64_data
.channel_monitor_pipe
= lttng_pipe_release_writefd(
6008 ust64_channel_monitor_pipe
);
6009 if (ustconsumer64_data
.channel_monitor_pipe
< 0) {
6011 goto exit_init_data
;
6013 ust64_channel_rotate_pipe
= lttng_pipe_open(0);
6014 if (!ust64_channel_rotate_pipe
) {
6015 ERR("Failed to create 64-bit user space consumer channel rotate pipe");
6017 goto exit_init_data
;
6019 ustconsumer64_data
.channel_rotate_pipe
= lttng_pipe_release_writefd(
6020 ust64_channel_rotate_pipe
);
6021 if (ustconsumer64_data
.channel_rotate_pipe
< 0) {
6023 goto exit_init_data
;
6027 * Init UST app hash table. Alloc hash table before this point since
6028 * cleanup() can get called after that point.
6030 if (ust_app_ht_alloc()) {
6031 ERR("Failed to allocate UST app hash table");
6033 goto exit_init_data
;
6037 * Initialize agent app hash table. We allocate the hash table here
6038 * since cleanup() can get called after this point.
6040 if (agent_app_ht_alloc()) {
6041 ERR("Failed to allocate Agent app hash table");
6043 goto exit_init_data
;
6047 * These actions must be executed as root. We do that *after* setting up
6048 * the sockets path because we MUST make the check for another daemon using
6049 * those paths *before* trying to set the kernel consumer sockets and init
6053 if (set_consumer_sockets(&kconsumer_data
)) {
6055 goto exit_init_data
;
6058 /* Setup kernel tracer */
6059 if (!config
.no_kernel
) {
6060 init_kernel_tracer();
6061 if (kernel_tracer_fd
>= 0) {
6062 ret
= syscall_init_table();
6064 ERR("Unable to populate syscall table. "
6065 "Syscall tracing won't work "
6066 "for this session daemon.");
6071 /* Set ulimit for open files */
6074 /* init lttng_fd tracking must be done after set_ulimit. */
6077 if (set_consumer_sockets(&ustconsumer64_data
)) {
6079 goto exit_init_data
;
6082 if (set_consumer_sockets(&ustconsumer32_data
)) {
6084 goto exit_init_data
;
6087 /* Setup the needed unix socket */
6088 if (init_daemon_socket()) {
6090 goto exit_init_data
;
6093 /* Set credentials to socket */
6094 if (is_root
&& set_permissions(config
.rundir
.value
)) {
6096 goto exit_init_data
;
6099 /* Get parent pid if -S, --sig-parent is specified. */
6100 if (config
.sig_parent
) {
6104 /* Setup the kernel pipe for waking up the kernel thread */
6105 if (is_root
&& !config
.no_kernel
) {
6106 if (utils_create_pipe_cloexec(kernel_poll_pipe
)) {
6108 goto exit_init_data
;
6112 /* Setup the thread apps communication pipe. */
6113 if (utils_create_pipe_cloexec(apps_cmd_pipe
)) {
6115 goto exit_init_data
;
6118 /* Setup the thread apps notify communication pipe. */
6119 if (utils_create_pipe_cloexec(apps_cmd_notify_pipe
)) {
6121 goto exit_init_data
;
6124 /* Initialize global buffer per UID and PID registry. */
6125 buffer_reg_init_uid_registry();
6126 buffer_reg_init_pid_registry();
6128 /* Init UST command queue. */
6129 cds_wfcq_init(&ust_cmd_queue
.head
, &ust_cmd_queue
.tail
);
6132 * Get session list pointer. This pointer MUST NOT be free'd. This list
6133 * is statically declared in session.c
6135 session_list_ptr
= session_get_list();
6139 /* Check for the application socket timeout env variable. */
6140 env_app_timeout
= getenv(DEFAULT_APP_SOCKET_TIMEOUT_ENV
);
6141 if (env_app_timeout
) {
6142 config
.app_socket_timeout
= atoi(env_app_timeout
);
6144 config
.app_socket_timeout
= DEFAULT_APP_SOCKET_RW_TIMEOUT
;
6147 ret
= write_pidfile();
6149 ERR("Error in write_pidfile");
6151 goto exit_init_data
;
6154 /* Initialize communication library */
6156 /* Initialize TCP timeout values */
6157 lttcomm_inet_init();
6159 if (load_session_init_data(&load_info
) < 0) {
6161 goto exit_init_data
;
6163 load_info
->path
= config
.load_session_path
.value
;
6165 /* Create health-check thread. */
6166 ret
= pthread_create(&health_thread
, default_pthread_attr(),
6167 thread_manage_health
, (void *) NULL
);
6170 PERROR("pthread_create health");
6176 * The rotation thread needs the notification thread to be ready before
6177 * creating the rotate_notification_channel, so we use this semaphore as
6178 * a rendez-vous point.
6180 sem_init(¬ification_thread_ready
, 0, 0);
6182 /* notification_thread_data acquires the pipes' read side. */
6183 notification_thread_handle
= notification_thread_handle_create(
6184 ust32_channel_monitor_pipe
,
6185 ust64_channel_monitor_pipe
,
6186 kernel_channel_monitor_pipe
,
6187 ¬ification_thread_ready
);
6188 if (!notification_thread_handle
) {
6190 ERR("Failed to create notification thread shared data");
6192 goto exit_notification
;
6195 /* Create notification thread. */
6196 ret
= pthread_create(¬ification_thread
, default_pthread_attr(),
6197 thread_notification
, notification_thread_handle
);
6200 PERROR("pthread_create notification");
6203 goto exit_notification
;
6205 notification_thread_launched
= true;
6207 /* Create timer thread. */
6208 ret
= pthread_create(&timer_thread
, default_pthread_attr(),
6209 sessiond_timer_thread
, &timer_thread_ctx
);
6212 PERROR("pthread_create timer");
6215 goto exit_notification
;
6217 timer_thread_launched
= true;
6219 /* rotation_thread_data acquires the pipes' read side. */
6220 rotation_thread_handle
= rotation_thread_handle_create(
6221 ust32_channel_rotate_pipe
,
6222 ust64_channel_rotate_pipe
,
6223 kernel_channel_rotate_pipe
,
6224 thread_quit_pipe
[0],
6225 rotation_timer_queue
,
6226 notification_thread_handle
,
6227 ¬ification_thread_ready
);
6228 if (!rotation_thread_handle
) {
6230 ERR("Failed to create rotation thread shared data");
6235 /* Create rotation thread. */
6236 ret
= pthread_create(&rotation_thread
, default_pthread_attr(),
6237 thread_rotation
, rotation_thread_handle
);
6240 PERROR("pthread_create rotation");
6245 rotation_thread_launched
= true;
6247 /* Create thread to manage the client socket */
6248 ret
= pthread_create(&client_thread
, default_pthread_attr(),
6249 thread_manage_clients
, (void *) NULL
);
6252 PERROR("pthread_create clients");
6258 /* Create thread to dispatch registration */
6259 ret
= pthread_create(&dispatch_thread
, default_pthread_attr(),
6260 thread_dispatch_ust_registration
, (void *) NULL
);
6263 PERROR("pthread_create dispatch");
6269 /* Create thread to manage application registration. */
6270 ret
= pthread_create(®_apps_thread
, default_pthread_attr(),
6271 thread_registration_apps
, (void *) NULL
);
6274 PERROR("pthread_create registration");
6280 /* Create thread to manage application socket */
6281 ret
= pthread_create(&apps_thread
, default_pthread_attr(),
6282 thread_manage_apps
, (void *) NULL
);
6285 PERROR("pthread_create apps");
6291 /* Create thread to manage application notify socket */
6292 ret
= pthread_create(&apps_notify_thread
, default_pthread_attr(),
6293 ust_thread_manage_notify
, (void *) NULL
);
6296 PERROR("pthread_create notify");
6299 goto exit_apps_notify
;
6302 /* Create agent registration thread. */
6303 ret
= pthread_create(&agent_reg_thread
, default_pthread_attr(),
6304 agent_thread_manage_registration
, (void *) NULL
);
6307 PERROR("pthread_create agent");
6310 goto exit_agent_reg
;
6313 /* Don't start this thread if kernel tracing is not requested nor root */
6314 if (is_root
&& !config
.no_kernel
) {
6315 /* Create kernel thread to manage kernel event */
6316 ret
= pthread_create(&kernel_thread
, default_pthread_attr(),
6317 thread_manage_kernel
, (void *) NULL
);
6320 PERROR("pthread_create kernel");
6327 /* Create session loading thread. */
6328 ret
= pthread_create(&load_session_thread
, default_pthread_attr(),
6329 thread_load_session
, load_info
);
6332 PERROR("pthread_create load_session_thread");
6335 goto exit_load_session
;
6339 * This is where we start awaiting program completion (e.g. through
6340 * signal that asks threads to teardown).
6343 ret
= pthread_join(load_session_thread
, &status
);
6346 PERROR("pthread_join load_session_thread");
6351 if (is_root
&& !config
.no_kernel
) {
6352 ret
= pthread_join(kernel_thread
, &status
);
6355 PERROR("pthread_join");
6361 ret
= pthread_join(agent_reg_thread
, &status
);
6364 PERROR("pthread_join agent");
6369 ret
= pthread_join(apps_notify_thread
, &status
);
6372 PERROR("pthread_join apps notify");
6377 ret
= pthread_join(apps_thread
, &status
);
6380 PERROR("pthread_join apps");
6385 ret
= pthread_join(reg_apps_thread
, &status
);
6388 PERROR("pthread_join");
6394 * Join dispatch thread after joining reg_apps_thread to ensure
6395 * we don't leak applications in the queue.
6397 ret
= pthread_join(dispatch_thread
, &status
);
6400 PERROR("pthread_join");
6405 ret
= pthread_join(client_thread
, &status
);
6408 PERROR("pthread_join");
6415 sem_destroy(¬ification_thread_ready
);
6416 ret
= pthread_join(health_thread
, &status
);
6419 PERROR("pthread_join health thread");
6426 * Wait for all pending call_rcu work to complete before tearing
6427 * down data structures. call_rcu worker may be trying to
6428 * perform lookups in those structures.
6432 * sessiond_cleanup() is called when no other thread is running, except
6433 * the ht_cleanup thread, which is needed to destroy the hash tables.
6435 rcu_thread_online();
6439 * Ensure all prior call_rcu are done. call_rcu callbacks may push
6440 * hash tables to the ht_cleanup thread. Therefore, we ensure that
6441 * the queue is empty before shutting down the clean-up thread.
6446 * The teardown of the notification system is performed after the
6447 * session daemon's teardown in order to allow it to be notified
6448 * of the active session and channels at the moment of the teardown.
6450 if (notification_thread_handle
) {
6451 if (notification_thread_launched
) {
6452 notification_thread_command_quit(
6453 notification_thread_handle
);
6454 ret
= pthread_join(notification_thread
, &status
);
6457 PERROR("pthread_join notification thread");
6461 notification_thread_handle_destroy(notification_thread_handle
);
6464 if (rotation_thread_handle
) {
6465 if (rotation_thread_launched
) {
6466 ret
= pthread_join(rotation_thread
, &status
);
6469 PERROR("pthread_join rotation thread");
6473 rotation_thread_handle_destroy(rotation_thread_handle
);
6476 if (timer_thread_launched
) {
6477 kill(getpid(), LTTNG_SESSIOND_SIG_EXIT
);
6478 ret
= pthread_join(timer_thread
, &status
);
6481 PERROR("pthread_join timer thread");
6487 * After the rotation and timer thread have quit, we can safely destroy
6488 * the rotation_timer_queue.
6490 destroy_rotate_timer_queue(rotation_timer_queue
);
6492 rcu_thread_offline();
6493 rcu_unregister_thread();
6495 ret
= fini_ht_cleanup_thread(&ht_cleanup_thread
);
6499 lttng_pipe_destroy(ust32_channel_monitor_pipe
);
6500 lttng_pipe_destroy(ust64_channel_monitor_pipe
);
6501 lttng_pipe_destroy(kernel_channel_monitor_pipe
);
6502 lttng_pipe_destroy(ust32_channel_rotate_pipe
);
6503 lttng_pipe_destroy(ust64_channel_rotate_pipe
);
6504 lttng_pipe_destroy(kernel_channel_rotate_pipe
);
6507 health_app_destroy(health_sessiond
);
6508 exit_health_sessiond_cleanup
:
6509 exit_create_run_as_worker_cleanup
:
6512 sessiond_cleanup_lock_file();
6513 sessiond_cleanup_options();
6515 exit_set_signal_handler
: