2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
10 #include "common/buffer-view.h"
11 #include "common/compat/socket.h"
12 #include "common/dynamic-buffer.h"
13 #include "common/dynamic-array.h"
14 #include "common/payload.h"
15 #include "common/payload-view.h"
16 #include "common/fd-handle.h"
17 #include "common/sessiond-comm/sessiond-comm.h"
18 #include "common/payload.h"
19 #include "common/payload-view.h"
20 #include "lttng/lttng-error.h"
21 #include "lttng/tracker.h"
22 #include <common/compat/getenv.h>
23 #include <common/tracker.h>
24 #include <common/unix.h>
25 #include <common/utils.h>
26 #include <lttng/event-internal.h>
27 #include <lttng/session-descriptor-internal.h>
28 #include <lttng/session-internal.h>
29 #include <lttng/userspace-probe-internal.h>
36 #include "lttng-sessiond.h"
40 #include "health-sessiond.h"
41 #include "testpoint.h"
43 #include "manage-consumer.h"
48 static struct thread_state
{
54 static void set_thread_status(bool running
)
56 DBG("Marking client thread's state as %s", running
? "running" : "error");
57 thread_state
.running
= running
;
58 sem_post(&thread_state
.ready
);
61 static bool wait_thread_status(void)
63 DBG("Waiting for client thread to be ready");
64 sem_wait(&thread_state
.ready
);
65 if (thread_state
.running
) {
66 DBG("Client thread is ready");
68 ERR("Initialization of client thread failed");
71 return thread_state
.running
;
75 * Setup the outgoing data buffer for the response (llm) by allocating the
76 * right amount of memory and copying the original information from the lsm
79 * Return 0 on success, negative value on error.
81 static int setup_lttng_msg(struct command_ctx
*cmd_ctx
,
82 const void *payload_buf
, size_t payload_len
,
83 const void *cmd_header_buf
, size_t cmd_header_len
)
86 const size_t header_len
= sizeof(struct lttcomm_lttng_msg
);
87 const size_t total_msg_size
= header_len
+ cmd_header_len
+ payload_len
;
88 const struct lttcomm_lttng_msg llm
= {
89 .cmd_type
= cmd_ctx
->lsm
.cmd_type
,
90 .pid
= cmd_ctx
->lsm
.domain
.attr
.pid
,
91 .cmd_header_size
= cmd_header_len
,
92 .data_size
= payload_len
,
95 lttng_dynamic_buffer_set_size(&cmd_ctx
->reply_payload
.buffer
, 0);
96 lttng_dynamic_pointer_array_clear(&cmd_ctx
->reply_payload
._fd_handles
);
98 cmd_ctx
->lttng_msg_size
= total_msg_size
;
100 /* Append reply header. */
101 ret
= lttng_dynamic_buffer_append(
102 &cmd_ctx
->reply_payload
.buffer
, &llm
, sizeof(llm
));
107 /* Append command header. */
108 if (cmd_header_len
) {
109 ret
= lttng_dynamic_buffer_append(
110 &cmd_ctx
->reply_payload
.buffer
, cmd_header_buf
,
117 /* Append payload. */
119 ret
= lttng_dynamic_buffer_append(
120 &cmd_ctx
->reply_payload
.buffer
, payload_buf
,
131 static int setup_empty_lttng_msg(struct command_ctx
*cmd_ctx
)
134 const struct lttcomm_lttng_msg llm
= {};
136 lttng_dynamic_buffer_set_size(&cmd_ctx
->reply_payload
.buffer
, 0);
138 /* Append place-holder reply header. */
139 ret
= lttng_dynamic_buffer_append(
140 &cmd_ctx
->reply_payload
.buffer
, &llm
, sizeof(llm
));
145 cmd_ctx
->lttng_msg_size
= sizeof(llm
);
150 static void update_lttng_msg(struct command_ctx
*cmd_ctx
, size_t cmd_header_len
,
153 const size_t header_len
= sizeof(struct lttcomm_lttng_msg
);
154 const size_t total_msg_size
= header_len
+ cmd_header_len
+ payload_len
;
155 const struct lttcomm_lttng_msg llm
= {
156 .cmd_type
= cmd_ctx
->lsm
.cmd_type
,
157 .pid
= cmd_ctx
->lsm
.domain
.attr
.pid
,
158 .cmd_header_size
= cmd_header_len
,
159 .data_size
= payload_len
,
161 struct lttcomm_lttng_msg
*p_llm
;
163 assert(cmd_ctx
->reply_payload
.buffer
.size
>= sizeof(llm
));
165 p_llm
= (typeof(p_llm
)) cmd_ctx
->reply_payload
.buffer
.data
;
167 /* Update existing header. */
168 memcpy(p_llm
, &llm
, sizeof(llm
));
170 cmd_ctx
->lttng_msg_size
= total_msg_size
;
174 * Start the thread_manage_consumer. This must be done after a lttng-consumerd
175 * exec or it will fail.
177 static int spawn_consumer_thread(struct consumer_data
*consumer_data
)
179 return launch_consumer_management_thread(consumer_data
) ? 0 : -1;
183 * Fork and exec a consumer daemon (consumerd).
185 * Return pid if successful else -1.
187 static pid_t
spawn_consumerd(struct consumer_data
*consumer_data
)
191 const char *consumer_to_use
;
192 const char *verbosity
;
195 DBG("Spawning consumerd");
202 if (config
.verbose_consumer
) {
203 verbosity
= "--verbose";
204 } else if (lttng_opt_quiet
) {
205 verbosity
= "--quiet";
210 switch (consumer_data
->type
) {
211 case LTTNG_CONSUMER_KERNEL
:
213 * Find out which consumerd to execute. We will first try the
214 * 64-bit path, then the sessiond's installation directory, and
215 * fallback on the 32-bit one,
217 DBG3("Looking for a kernel consumer at these locations:");
218 DBG3(" 1) %s", config
.consumerd64_bin_path
.value
? : "NULL");
219 DBG3(" 2) %s/%s", INSTALL_BIN_PATH
, DEFAULT_CONSUMERD_FILE
);
220 DBG3(" 3) %s", config
.consumerd32_bin_path
.value
? : "NULL");
221 if (stat(config
.consumerd64_bin_path
.value
, &st
) == 0) {
222 DBG3("Found location #1");
223 consumer_to_use
= config
.consumerd64_bin_path
.value
;
224 } else if (stat(INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
, &st
) == 0) {
225 DBG3("Found location #2");
226 consumer_to_use
= INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
;
227 } else if (config
.consumerd32_bin_path
.value
&&
228 stat(config
.consumerd32_bin_path
.value
, &st
) == 0) {
229 DBG3("Found location #3");
230 consumer_to_use
= config
.consumerd32_bin_path
.value
;
232 DBG("Could not find any valid consumerd executable");
236 DBG("Using kernel consumer at: %s", consumer_to_use
);
237 (void) execl(consumer_to_use
,
238 "lttng-consumerd", verbosity
, "-k",
239 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
240 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
241 "--group", config
.tracing_group_name
.value
,
244 case LTTNG_CONSUMER64_UST
:
246 if (config
.consumerd64_lib_dir
.value
) {
251 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
255 tmplen
= strlen(config
.consumerd64_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
256 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
261 strcat(tmpnew
, config
.consumerd64_lib_dir
.value
);
262 if (tmp
[0] != '\0') {
266 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
273 DBG("Using 64-bit UST consumer at: %s", config
.consumerd64_bin_path
.value
);
274 (void) execl(config
.consumerd64_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
275 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
276 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
277 "--group", config
.tracing_group_name
.value
,
281 case LTTNG_CONSUMER32_UST
:
283 if (config
.consumerd32_lib_dir
.value
) {
288 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
292 tmplen
= strlen(config
.consumerd32_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
293 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
298 strcat(tmpnew
, config
.consumerd32_lib_dir
.value
);
299 if (tmp
[0] != '\0') {
303 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
310 DBG("Using 32-bit UST consumer at: %s", config
.consumerd32_bin_path
.value
);
311 (void) execl(config
.consumerd32_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
312 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
313 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
314 "--group", config
.tracing_group_name
.value
,
319 ERR("unknown consumer type");
323 PERROR("Consumer execl()");
325 /* Reaching this point, we got a failure on our execl(). */
327 } else if (pid
> 0) {
330 PERROR("start consumer fork");
338 * Spawn the consumerd daemon and session daemon thread.
340 static int start_consumerd(struct consumer_data
*consumer_data
)
345 * Set the listen() state on the socket since there is a possible race
346 * between the exec() of the consumer daemon and this call if place in the
347 * consumer thread. See bug #366 for more details.
349 ret
= lttcomm_listen_unix_sock(consumer_data
->err_sock
);
354 pthread_mutex_lock(&consumer_data
->pid_mutex
);
355 if (consumer_data
->pid
!= 0) {
356 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
360 ret
= spawn_consumerd(consumer_data
);
362 ERR("Spawning consumerd failed");
363 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
367 /* Setting up the consumer_data pid */
368 consumer_data
->pid
= ret
;
369 DBG2("Consumer pid %d", consumer_data
->pid
);
370 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
372 DBG2("Spawning consumer control thread");
373 ret
= spawn_consumer_thread(consumer_data
);
375 ERR("Fatal error spawning consumer control thread");
383 /* Cleanup already created sockets on error. */
384 if (consumer_data
->err_sock
>= 0) {
387 err
= close(consumer_data
->err_sock
);
389 PERROR("close consumer data error socket");
396 * Copy consumer output from the tracing session to the domain session. The
397 * function also applies the right modification on a per domain basis for the
398 * trace files destination directory.
400 * Should *NOT* be called with RCU read-side lock held.
402 static int copy_session_consumer(int domain
, struct ltt_session
*session
)
405 const char *dir_name
;
406 struct consumer_output
*consumer
;
409 assert(session
->consumer
);
412 case LTTNG_DOMAIN_KERNEL
:
413 DBG3("Copying tracing session consumer output in kernel session");
415 * XXX: We should audit the session creation and what this function
416 * does "extra" in order to avoid a destroy since this function is used
417 * in the domain session creation (kernel and ust) only. Same for UST
420 if (session
->kernel_session
->consumer
) {
421 consumer_output_put(session
->kernel_session
->consumer
);
423 session
->kernel_session
->consumer
=
424 consumer_copy_output(session
->consumer
);
425 /* Ease our life a bit for the next part */
426 consumer
= session
->kernel_session
->consumer
;
427 dir_name
= DEFAULT_KERNEL_TRACE_DIR
;
429 case LTTNG_DOMAIN_JUL
:
430 case LTTNG_DOMAIN_LOG4J
:
431 case LTTNG_DOMAIN_PYTHON
:
432 case LTTNG_DOMAIN_UST
:
433 DBG3("Copying tracing session consumer output in UST session");
434 if (session
->ust_session
->consumer
) {
435 consumer_output_put(session
->ust_session
->consumer
);
437 session
->ust_session
->consumer
=
438 consumer_copy_output(session
->consumer
);
439 /* Ease our life a bit for the next part */
440 consumer
= session
->ust_session
->consumer
;
441 dir_name
= DEFAULT_UST_TRACE_DIR
;
444 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
448 /* Append correct directory to subdir */
449 ret
= lttng_strncpy(consumer
->domain_subdir
, dir_name
,
450 sizeof(consumer
->domain_subdir
));
455 DBG3("Copy session consumer subdir %s", consumer
->domain_subdir
);
463 * Create an UST session and add it to the session ust list.
465 * Should *NOT* be called with RCU read-side lock held.
467 static int create_ust_session(struct ltt_session
*session
,
468 const struct lttng_domain
*domain
)
471 struct ltt_ust_session
*lus
= NULL
;
475 assert(session
->consumer
);
477 switch (domain
->type
) {
478 case LTTNG_DOMAIN_JUL
:
479 case LTTNG_DOMAIN_LOG4J
:
480 case LTTNG_DOMAIN_PYTHON
:
481 case LTTNG_DOMAIN_UST
:
484 ERR("Unknown UST domain on create session %d", domain
->type
);
485 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
489 DBG("Creating UST session");
491 lus
= trace_ust_create_session(session
->id
);
493 ret
= LTTNG_ERR_UST_SESS_FAIL
;
497 lus
->uid
= session
->uid
;
498 lus
->gid
= session
->gid
;
499 lus
->output_traces
= session
->output_traces
;
500 lus
->snapshot_mode
= session
->snapshot_mode
;
501 lus
->live_timer_interval
= session
->live_timer
;
502 session
->ust_session
= lus
;
503 if (session
->shm_path
[0]) {
504 strncpy(lus
->root_shm_path
, session
->shm_path
,
505 sizeof(lus
->root_shm_path
));
506 lus
->root_shm_path
[sizeof(lus
->root_shm_path
) - 1] = '\0';
507 strncpy(lus
->shm_path
, session
->shm_path
,
508 sizeof(lus
->shm_path
));
509 lus
->shm_path
[sizeof(lus
->shm_path
) - 1] = '\0';
510 strncat(lus
->shm_path
, "/ust",
511 sizeof(lus
->shm_path
) - strlen(lus
->shm_path
) - 1);
513 /* Copy session output to the newly created UST session */
514 ret
= copy_session_consumer(domain
->type
, session
);
515 if (ret
!= LTTNG_OK
) {
523 session
->ust_session
= NULL
;
528 * Create a kernel tracer session then create the default channel.
530 static int create_kernel_session(struct ltt_session
*session
)
534 DBG("Creating kernel session");
536 ret
= kernel_create_session(session
);
538 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
542 /* Code flow safety */
543 assert(session
->kernel_session
);
545 /* Copy session output to the newly created Kernel session */
546 ret
= copy_session_consumer(LTTNG_DOMAIN_KERNEL
, session
);
547 if (ret
!= LTTNG_OK
) {
551 session
->kernel_session
->uid
= session
->uid
;
552 session
->kernel_session
->gid
= session
->gid
;
553 session
->kernel_session
->output_traces
= session
->output_traces
;
554 session
->kernel_session
->snapshot_mode
= session
->snapshot_mode
;
555 session
->kernel_session
->is_live_session
= session
->live_timer
!= 0;
560 trace_kernel_destroy_session(session
->kernel_session
);
561 session
->kernel_session
= NULL
;
567 * Count number of session permitted by uid/gid.
569 static unsigned int lttng_sessions_count(uid_t uid
, gid_t gid
)
572 struct ltt_session
*session
;
573 const struct ltt_session_list
*session_list
= session_get_list();
575 DBG("Counting number of available session for UID %d GID %d",
577 cds_list_for_each_entry(session
, &session_list
->head
, list
) {
578 if (!session_get(session
)) {
581 session_lock(session
);
582 /* Only count the sessions the user can control. */
583 if (session_access_ok(session
, uid
, gid
) &&
584 !session
->destroyed
) {
587 session_unlock(session
);
588 session_put(session
);
593 static int receive_userspace_probe(struct command_ctx
*cmd_ctx
, int sock
,
594 int *sock_error
, struct lttng_event
*event
)
597 struct lttng_userspace_probe_location
*probe_location
;
598 struct lttng_payload probe_location_payload
;
599 struct fd_handle
*handle
= NULL
;
602 * Create a payload to store the serialized version of the probe
605 lttng_payload_init(&probe_location_payload
);
607 ret
= lttng_dynamic_buffer_set_size(&probe_location_payload
.buffer
,
608 cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
);
610 ret
= LTTNG_ERR_NOMEM
;
615 * Receive the probe location.
617 ret
= lttcomm_recv_unix_sock(sock
, probe_location_payload
.buffer
.data
,
618 probe_location_payload
.buffer
.size
);
620 DBG("Nothing recv() from client var len data... continuing");
622 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
627 * Receive the file descriptor to the target binary from the client.
629 DBG("Receiving userspace probe target FD from client ...");
630 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
632 DBG("Nothing recv() from client userspace probe fd... continuing");
634 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
638 handle
= fd_handle_create(fd
);
640 ret
= LTTNG_ERR_NOMEM
;
644 /* Transferred to the handle. */
647 ret
= lttng_payload_push_fd_handle(&probe_location_payload
, handle
);
649 ERR("Failed to add userspace probe file descriptor to payload");
650 ret
= LTTNG_ERR_NOMEM
;
654 fd_handle_put(handle
);
658 struct lttng_payload_view view
= lttng_payload_view_from_payload(
659 &probe_location_payload
, 0, -1);
661 /* Extract the probe location from the serialized version. */
662 ret
= lttng_userspace_probe_location_create_from_payload(
663 &view
, &probe_location
);
666 WARN("Failed to create a userspace probe location from the received buffer");
667 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
671 /* Attach the probe location to the event. */
672 ret
= lttng_event_set_userspace_probe_location(event
, probe_location
);
674 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
681 PERROR("Failed to close userspace probe location binary fd");
685 fd_handle_put(handle
);
686 lttng_payload_reset(&probe_location_payload
);
691 * Version of setup_lttng_msg() without command header.
693 static int setup_lttng_msg_no_cmd_header(struct command_ctx
*cmd_ctx
,
694 void *payload_buf
, size_t payload_len
)
696 return setup_lttng_msg(cmd_ctx
, payload_buf
, payload_len
, NULL
, 0);
700 * Check if the current kernel tracer supports the session rotation feature.
701 * Return 1 if it does, 0 otherwise.
703 static int check_rotate_compatible(void)
707 if (kernel_tracer_version
.major
!= 2 || kernel_tracer_version
.minor
< 11) {
708 DBG("Kernel tracer version is not compatible with the rotation feature");
716 * Send data on a unix socket using the liblttsessiondcomm API.
718 * Return lttcomm error code.
720 static int send_unix_sock(int sock
, struct lttng_payload_view
*view
)
723 const int fd_count
= lttng_payload_view_get_fd_handle_count(view
);
725 /* Check valid length */
726 if (view
->buffer
.size
== 0) {
731 ret
= lttcomm_send_unix_sock(
732 sock
, view
->buffer
.data
, view
->buffer
.size
);
739 struct lttng_dynamic_array raw_fds
;
742 * Never holds ownership of the FDs; this is just used
743 * to put the FDs in a contiguous array.
745 lttng_dynamic_array_init(&raw_fds
, sizeof(int), NULL
);
747 for (i
= 0; i
< fd_count
; i
++) {
748 struct fd_handle
*handle
=
749 lttng_payload_view_pop_fd_handle(view
);
750 const int raw_fd
= fd_handle_get_fd(handle
);
752 ret
= lttng_dynamic_array_add_element(&raw_fds
, &raw_fd
);
753 fd_handle_put(handle
);
755 lttng_dynamic_array_reset(&raw_fds
);
760 ret
= lttcomm_send_fds_unix_sock(sock
,
761 (const int *) raw_fds
.buffer
.data
,
763 lttng_dynamic_array_reset(&raw_fds
);
771 * Process the command requested by the lttng client within the command
772 * context structure. This function make sure that the return structure (llm)
773 * is set and ready for transmission before returning.
775 * Return any error encountered or 0 for success.
777 * "sock" is only used for special-case var. len data.
778 * A command may assume the ownership of the socket, in which case its value
779 * should be set to -1.
781 * Should *NOT* be called with RCU read-side lock held.
783 static int process_client_msg(struct command_ctx
*cmd_ctx
, int *sock
,
787 int need_tracing_session
= 1;
790 DBG("Processing client command %d", cmd_ctx
->lsm
.cmd_type
);
792 assert(!rcu_read_ongoing());
796 switch (cmd_ctx
->lsm
.cmd_type
) {
797 case LTTNG_CREATE_SESSION_EXT
:
798 case LTTNG_DESTROY_SESSION
:
799 case LTTNG_LIST_SESSIONS
:
800 case LTTNG_LIST_DOMAINS
:
801 case LTTNG_START_TRACE
:
802 case LTTNG_STOP_TRACE
:
803 case LTTNG_DATA_PENDING
:
804 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
805 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
806 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
807 case LTTNG_SNAPSHOT_RECORD
:
808 case LTTNG_SAVE_SESSION
:
809 case LTTNG_SET_SESSION_SHM_PATH
:
810 case LTTNG_REGENERATE_METADATA
:
811 case LTTNG_REGENERATE_STATEDUMP
:
812 case LTTNG_REGISTER_TRIGGER
:
813 case LTTNG_UNREGISTER_TRIGGER
:
814 case LTTNG_ROTATE_SESSION
:
815 case LTTNG_ROTATION_GET_INFO
:
816 case LTTNG_ROTATION_SET_SCHEDULE
:
817 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
818 case LTTNG_CLEAR_SESSION
:
825 if (config
.no_kernel
&& need_domain
826 && cmd_ctx
->lsm
.domain
.type
== LTTNG_DOMAIN_KERNEL
) {
828 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
830 ret
= LTTNG_ERR_KERN_NA
;
835 /* Deny register consumer if we already have a spawned consumer. */
836 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_REGISTER_CONSUMER
) {
837 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
838 if (kconsumer_data
.pid
> 0) {
839 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
840 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
843 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
847 * Check for command that don't needs to allocate a returned payload. We do
848 * this here so we don't have to make the call for no payload at each
851 switch(cmd_ctx
->lsm
.cmd_type
) {
852 case LTTNG_LIST_SESSIONS
:
853 case LTTNG_LIST_TRACEPOINTS
:
854 case LTTNG_LIST_TRACEPOINT_FIELDS
:
855 case LTTNG_LIST_DOMAINS
:
856 case LTTNG_LIST_CHANNELS
:
857 case LTTNG_LIST_EVENTS
:
858 case LTTNG_LIST_SYSCALLS
:
859 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
860 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
861 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
862 case LTTNG_DATA_PENDING
:
863 case LTTNG_ROTATE_SESSION
:
864 case LTTNG_ROTATION_GET_INFO
:
867 /* Setup lttng message with no payload */
868 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0);
870 /* This label does not try to unlock the session */
871 goto init_setup_error
;
875 /* Commands that DO NOT need a session. */
876 switch (cmd_ctx
->lsm
.cmd_type
) {
877 case LTTNG_CREATE_SESSION_EXT
:
878 case LTTNG_LIST_SESSIONS
:
879 case LTTNG_LIST_TRACEPOINTS
:
880 case LTTNG_LIST_SYSCALLS
:
881 case LTTNG_LIST_TRACEPOINT_FIELDS
:
882 case LTTNG_SAVE_SESSION
:
883 case LTTNG_REGISTER_TRIGGER
:
884 case LTTNG_UNREGISTER_TRIGGER
:
885 need_tracing_session
= 0;
888 DBG("Getting session %s by name", cmd_ctx
->lsm
.session
.name
);
890 * We keep the session list lock across _all_ commands
891 * for now, because the per-session lock does not
892 * handle teardown properly.
895 cmd_ctx
->session
= session_find_by_name(cmd_ctx
->lsm
.session
.name
);
896 if (cmd_ctx
->session
== NULL
) {
897 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
900 /* Acquire lock for the session */
901 session_lock(cmd_ctx
->session
);
907 * Commands that need a valid session but should NOT create one if none
908 * exists. Instead of creating one and destroying it when the command is
909 * handled, process that right before so we save some round trip in useless
912 switch (cmd_ctx
->lsm
.cmd_type
) {
913 case LTTNG_DISABLE_CHANNEL
:
914 case LTTNG_DISABLE_EVENT
:
915 switch (cmd_ctx
->lsm
.domain
.type
) {
916 case LTTNG_DOMAIN_KERNEL
:
917 if (!cmd_ctx
->session
->kernel_session
) {
918 ret
= LTTNG_ERR_NO_CHANNEL
;
922 case LTTNG_DOMAIN_JUL
:
923 case LTTNG_DOMAIN_LOG4J
:
924 case LTTNG_DOMAIN_PYTHON
:
925 case LTTNG_DOMAIN_UST
:
926 if (!cmd_ctx
->session
->ust_session
) {
927 ret
= LTTNG_ERR_NO_CHANNEL
;
932 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
944 * Check domain type for specific "pre-action".
946 switch (cmd_ctx
->lsm
.domain
.type
) {
947 case LTTNG_DOMAIN_KERNEL
:
949 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
953 /* Kernel tracer check */
954 if (!kernel_tracer_is_initialized()) {
955 /* Basically, load kernel tracer modules */
956 ret
= init_kernel_tracer();
962 /* Consumer is in an ERROR state. Report back to client */
963 if (uatomic_read(&kernel_consumerd_state
) == CONSUMER_ERROR
) {
964 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
968 /* Need a session for kernel command */
969 if (need_tracing_session
) {
970 if (cmd_ctx
->session
->kernel_session
== NULL
) {
971 ret
= create_kernel_session(cmd_ctx
->session
);
972 if (ret
!= LTTNG_OK
) {
973 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
978 /* Start the kernel consumer daemon */
979 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
980 if (kconsumer_data
.pid
== 0 &&
981 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
982 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
983 ret
= start_consumerd(&kconsumer_data
);
985 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
988 uatomic_set(&kernel_consumerd_state
, CONSUMER_STARTED
);
990 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
994 * The consumer was just spawned so we need to add the socket to
995 * the consumer output of the session if exist.
997 ret
= consumer_create_socket(&kconsumer_data
,
998 cmd_ctx
->session
->kernel_session
->consumer
);
1005 case LTTNG_DOMAIN_JUL
:
1006 case LTTNG_DOMAIN_LOG4J
:
1007 case LTTNG_DOMAIN_PYTHON
:
1008 case LTTNG_DOMAIN_UST
:
1010 if (!ust_app_supported()) {
1011 ret
= LTTNG_ERR_NO_UST
;
1014 /* Consumer is in an ERROR state. Report back to client */
1015 if (uatomic_read(&ust_consumerd_state
) == CONSUMER_ERROR
) {
1016 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1020 if (need_tracing_session
) {
1021 /* Create UST session if none exist. */
1022 if (cmd_ctx
->session
->ust_session
== NULL
) {
1023 ret
= create_ust_session(cmd_ctx
->session
,
1024 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
));
1025 if (ret
!= LTTNG_OK
) {
1030 /* Start the UST consumer daemons */
1032 pthread_mutex_lock(&ustconsumer64_data
.pid_mutex
);
1033 if (config
.consumerd64_bin_path
.value
&&
1034 ustconsumer64_data
.pid
== 0 &&
1035 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1036 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1037 ret
= start_consumerd(&ustconsumer64_data
);
1039 ret
= LTTNG_ERR_UST_CONSUMER64_FAIL
;
1040 uatomic_set(&ust_consumerd64_fd
, -EINVAL
);
1044 uatomic_set(&ust_consumerd64_fd
, ustconsumer64_data
.cmd_sock
);
1045 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1047 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1051 * Setup socket for consumer 64 bit. No need for atomic access
1052 * since it was set above and can ONLY be set in this thread.
1054 ret
= consumer_create_socket(&ustconsumer64_data
,
1055 cmd_ctx
->session
->ust_session
->consumer
);
1061 pthread_mutex_lock(&ustconsumer32_data
.pid_mutex
);
1062 if (config
.consumerd32_bin_path
.value
&&
1063 ustconsumer32_data
.pid
== 0 &&
1064 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1065 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1066 ret
= start_consumerd(&ustconsumer32_data
);
1068 ret
= LTTNG_ERR_UST_CONSUMER32_FAIL
;
1069 uatomic_set(&ust_consumerd32_fd
, -EINVAL
);
1073 uatomic_set(&ust_consumerd32_fd
, ustconsumer32_data
.cmd_sock
);
1074 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1076 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1080 * Setup socket for consumer 32 bit. No need for atomic access
1081 * since it was set above and can ONLY be set in this thread.
1083 ret
= consumer_create_socket(&ustconsumer32_data
,
1084 cmd_ctx
->session
->ust_session
->consumer
);
1096 /* Validate consumer daemon state when start/stop trace command */
1097 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_START_TRACE
||
1098 cmd_ctx
->lsm
.cmd_type
== LTTNG_STOP_TRACE
) {
1099 switch (cmd_ctx
->lsm
.domain
.type
) {
1100 case LTTNG_DOMAIN_NONE
:
1102 case LTTNG_DOMAIN_JUL
:
1103 case LTTNG_DOMAIN_LOG4J
:
1104 case LTTNG_DOMAIN_PYTHON
:
1105 case LTTNG_DOMAIN_UST
:
1106 if (uatomic_read(&ust_consumerd_state
) != CONSUMER_STARTED
) {
1107 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1111 case LTTNG_DOMAIN_KERNEL
:
1112 if (uatomic_read(&kernel_consumerd_state
) != CONSUMER_STARTED
) {
1113 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
1118 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1124 * Check that the UID or GID match that of the tracing session.
1125 * The root user can interact with all sessions.
1127 if (need_tracing_session
) {
1128 if (!session_access_ok(cmd_ctx
->session
,
1129 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1130 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
)) ||
1131 cmd_ctx
->session
->destroyed
) {
1132 ret
= LTTNG_ERR_EPERM
;
1138 * Send relayd information to consumer as soon as we have a domain and a
1141 if (cmd_ctx
->session
&& need_domain
) {
1143 * Setup relayd if not done yet. If the relayd information was already
1144 * sent to the consumer, this call will gracefully return.
1146 ret
= cmd_setup_relayd(cmd_ctx
->session
);
1147 if (ret
!= LTTNG_OK
) {
1152 /* Process by command type */
1153 switch (cmd_ctx
->lsm
.cmd_type
) {
1154 case LTTNG_ADD_CONTEXT
:
1157 * An LTTNG_ADD_CONTEXT command might have a supplementary
1158 * payload if the context being added is an application context.
1160 if (cmd_ctx
->lsm
.u
.context
.ctx
.ctx
==
1161 LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1162 char *provider_name
= NULL
, *context_name
= NULL
;
1163 size_t provider_name_len
=
1164 cmd_ctx
->lsm
.u
.context
.provider_name_len
;
1165 size_t context_name_len
=
1166 cmd_ctx
->lsm
.u
.context
.context_name_len
;
1168 if (provider_name_len
== 0 || context_name_len
== 0) {
1170 * Application provider and context names MUST
1173 ret
= -LTTNG_ERR_INVALID
;
1177 provider_name
= zmalloc(provider_name_len
+ 1);
1178 if (!provider_name
) {
1179 ret
= -LTTNG_ERR_NOMEM
;
1182 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
=
1185 context_name
= zmalloc(context_name_len
+ 1);
1186 if (!context_name
) {
1187 ret
= -LTTNG_ERR_NOMEM
;
1188 goto error_add_context
;
1190 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
=
1193 ret
= lttcomm_recv_unix_sock(*sock
, provider_name
,
1196 goto error_add_context
;
1199 ret
= lttcomm_recv_unix_sock(*sock
, context_name
,
1202 goto error_add_context
;
1207 * cmd_add_context assumes ownership of the provider and context
1210 ret
= cmd_add_context(cmd_ctx
->session
,
1211 cmd_ctx
->lsm
.domain
.type
,
1212 cmd_ctx
->lsm
.u
.context
.channel_name
,
1213 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.context
.ctx
),
1214 kernel_poll_pipe
[1]);
1216 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
1217 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
1219 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
);
1220 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
);
1226 case LTTNG_DISABLE_CHANNEL
:
1228 ret
= cmd_disable_channel(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1229 cmd_ctx
->lsm
.u
.disable
.channel_name
);
1232 case LTTNG_DISABLE_EVENT
:
1236 * FIXME: handle filter; for now we just receive the filter's
1237 * bytecode along with the filter expression which are sent by
1238 * liblttng-ctl and discard them.
1240 * This fixes an issue where the client may block while sending
1241 * the filter payload and encounter an error because the session
1242 * daemon closes the socket without ever handling this data.
1244 size_t count
= cmd_ctx
->lsm
.u
.disable
.expression_len
+
1245 cmd_ctx
->lsm
.u
.disable
.bytecode_len
;
1248 char data
[LTTNG_FILTER_MAX_LEN
];
1250 DBG("Discarding disable event command payload of size %zu", count
);
1252 ret
= lttcomm_recv_unix_sock(*sock
, data
,
1253 count
> sizeof(data
) ? sizeof(data
) : count
);
1258 count
-= (size_t) ret
;
1261 ret
= cmd_disable_event(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1262 cmd_ctx
->lsm
.u
.disable
.channel_name
,
1263 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.disable
.event
));
1266 case LTTNG_ENABLE_CHANNEL
:
1268 cmd_ctx
->lsm
.u
.channel
.chan
.attr
.extended
.ptr
=
1269 (struct lttng_channel_extended
*) &cmd_ctx
->lsm
.u
.channel
.extended
;
1270 ret
= cmd_enable_channel(cmd_ctx
->session
,
1271 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1272 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.channel
.chan
),
1273 kernel_poll_pipe
[1]);
1276 case LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
:
1277 case LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE
:
1279 struct lttng_dynamic_buffer payload
;
1280 struct lttng_buffer_view payload_view
;
1281 const bool add_value
=
1282 cmd_ctx
->lsm
.cmd_type
==
1283 LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
;
1284 const size_t name_len
=
1285 cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1287 const enum lttng_domain_type domain_type
=
1288 (enum lttng_domain_type
)
1289 cmd_ctx
->lsm
.domain
.type
;
1290 const enum lttng_process_attr process_attr
=
1291 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1292 .process_attr_tracker_add_remove_include_value
1294 const enum lttng_process_attr_value_type value_type
=
1295 (enum lttng_process_attr_value_type
) cmd_ctx
1297 .process_attr_tracker_add_remove_include_value
1299 struct process_attr_value
*value
;
1300 enum lttng_error_code ret_code
;
1302 /* Receive remaining variable length payload if applicable. */
1303 if (name_len
> LOGIN_NAME_MAX
) {
1305 * POSIX mandates user and group names that are at least
1306 * 8 characters long. Note that although shadow-utils
1307 * (useradd, groupaadd, etc.) use 32 chars as their
1308 * limit (from bits/utmp.h, UT_NAMESIZE),
1309 * LOGIN_NAME_MAX is defined to 256.
1311 ERR("Rejecting process attribute tracker value %s as the provided exceeds the maximal allowed length: argument length = %zu, maximal length = %d",
1312 add_value
? "addition" : "removal",
1313 name_len
, LOGIN_NAME_MAX
);
1314 ret
= LTTNG_ERR_INVALID
;
1318 lttng_dynamic_buffer_init(&payload
);
1319 if (name_len
!= 0) {
1321 * Receive variable payload for user/group name
1324 ret
= lttng_dynamic_buffer_set_size(&payload
, name_len
);
1326 ERR("Failed to allocate buffer to receive payload of %s process attribute tracker value argument",
1327 add_value
? "add" : "remove");
1328 ret
= LTTNG_ERR_NOMEM
;
1329 goto error_add_remove_tracker_value
;
1332 ret
= lttcomm_recv_unix_sock(
1333 *sock
, payload
.data
, name_len
);
1335 ERR("Failed to receive payload of %s process attribute tracker value argument",
1336 add_value
? "add" : "remove");
1338 ret
= LTTNG_ERR_INVALID_PROTOCOL
;
1339 goto error_add_remove_tracker_value
;
1343 payload_view
= lttng_buffer_view_from_dynamic_buffer(
1344 &payload
, 0, name_len
);
1346 * Validate the value type and domains are legal for the process
1347 * attribute tracker that is specified and convert the value to
1348 * add/remove to the internal sessiond representation.
1350 ret_code
= process_attr_value_from_comm(domain_type
,
1351 process_attr
, value_type
,
1352 &cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1354 &payload_view
, &value
);
1355 if (ret_code
!= LTTNG_OK
) {
1357 goto error_add_remove_tracker_value
;
1361 ret
= cmd_process_attr_tracker_inclusion_set_add_value(
1362 cmd_ctx
->session
, domain_type
,
1363 process_attr
, value
);
1365 ret
= cmd_process_attr_tracker_inclusion_set_remove_value(
1366 cmd_ctx
->session
, domain_type
,
1367 process_attr
, value
);
1369 process_attr_value_destroy(value
);
1370 error_add_remove_tracker_value
:
1371 lttng_dynamic_buffer_reset(&payload
);
1374 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
1376 enum lttng_tracking_policy tracking_policy
;
1377 const enum lttng_domain_type domain_type
=
1378 (enum lttng_domain_type
)
1379 cmd_ctx
->lsm
.domain
.type
;
1380 const enum lttng_process_attr process_attr
=
1381 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1382 .process_attr_tracker_get_tracking_policy
1385 ret
= cmd_process_attr_tracker_get_tracking_policy(
1386 cmd_ctx
->session
, domain_type
, process_attr
,
1388 if (ret
!= LTTNG_OK
) {
1392 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1393 &(uint32_t){tracking_policy
}, sizeof(uint32_t));
1395 ret
= LTTNG_ERR_NOMEM
;
1401 case LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY
:
1403 const enum lttng_tracking_policy tracking_policy
=
1404 (enum lttng_tracking_policy
) cmd_ctx
->lsm
.u
1405 .process_attr_tracker_set_tracking_policy
1407 const enum lttng_domain_type domain_type
=
1408 (enum lttng_domain_type
)
1409 cmd_ctx
->lsm
.domain
.type
;
1410 const enum lttng_process_attr process_attr
=
1411 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1412 .process_attr_tracker_set_tracking_policy
1415 ret
= cmd_process_attr_tracker_set_tracking_policy(
1416 cmd_ctx
->session
, domain_type
, process_attr
,
1418 if (ret
!= LTTNG_OK
) {
1423 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
1425 struct lttng_process_attr_values
*values
;
1426 struct lttng_dynamic_buffer reply
;
1427 const enum lttng_domain_type domain_type
=
1428 (enum lttng_domain_type
)
1429 cmd_ctx
->lsm
.domain
.type
;
1430 const enum lttng_process_attr process_attr
=
1431 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1432 .process_attr_tracker_get_inclusion_set
1435 ret
= cmd_process_attr_tracker_get_inclusion_set(
1436 cmd_ctx
->session
, domain_type
, process_attr
,
1438 if (ret
!= LTTNG_OK
) {
1442 lttng_dynamic_buffer_init(&reply
);
1443 ret
= lttng_process_attr_values_serialize(values
, &reply
);
1445 goto error_tracker_get_inclusion_set
;
1448 ret
= setup_lttng_msg_no_cmd_header(
1449 cmd_ctx
, reply
.data
, reply
.size
);
1451 ret
= LTTNG_ERR_NOMEM
;
1452 goto error_tracker_get_inclusion_set
;
1456 error_tracker_get_inclusion_set
:
1457 lttng_process_attr_values_destroy(values
);
1458 lttng_dynamic_buffer_reset(&reply
);
1461 case LTTNG_ENABLE_EVENT
:
1463 struct lttng_event
*ev
= NULL
;
1464 struct lttng_event_exclusion
*exclusion
= NULL
;
1465 struct lttng_filter_bytecode
*bytecode
= NULL
;
1466 char *filter_expression
= NULL
;
1468 /* Handle exclusion events and receive it from the client. */
1469 if (cmd_ctx
->lsm
.u
.enable
.exclusion_count
> 0) {
1470 size_t count
= cmd_ctx
->lsm
.u
.enable
.exclusion_count
;
1472 exclusion
= zmalloc(sizeof(struct lttng_event_exclusion
) +
1473 (count
* LTTNG_SYMBOL_NAME_LEN
));
1475 ret
= LTTNG_ERR_EXCLUSION_NOMEM
;
1479 DBG("Receiving var len exclusion event list from client ...");
1480 exclusion
->count
= count
;
1481 ret
= lttcomm_recv_unix_sock(*sock
, exclusion
->names
,
1482 count
* LTTNG_SYMBOL_NAME_LEN
);
1484 DBG("Nothing recv() from client var len data... continuing");
1487 ret
= LTTNG_ERR_EXCLUSION_INVAL
;
1492 /* Get filter expression from client. */
1493 if (cmd_ctx
->lsm
.u
.enable
.expression_len
> 0) {
1494 size_t expression_len
=
1495 cmd_ctx
->lsm
.u
.enable
.expression_len
;
1497 if (expression_len
> LTTNG_FILTER_MAX_LEN
) {
1498 ret
= LTTNG_ERR_FILTER_INVAL
;
1503 filter_expression
= zmalloc(expression_len
);
1504 if (!filter_expression
) {
1506 ret
= LTTNG_ERR_FILTER_NOMEM
;
1510 /* Receive var. len. data */
1511 DBG("Receiving var len filter's expression from client ...");
1512 ret
= lttcomm_recv_unix_sock(*sock
, filter_expression
,
1515 DBG("Nothing recv() from client var len data... continuing");
1517 free(filter_expression
);
1519 ret
= LTTNG_ERR_FILTER_INVAL
;
1524 /* Handle filter and get bytecode from client. */
1525 if (cmd_ctx
->lsm
.u
.enable
.bytecode_len
> 0) {
1526 size_t bytecode_len
= cmd_ctx
->lsm
.u
.enable
.bytecode_len
;
1528 if (bytecode_len
> LTTNG_FILTER_MAX_LEN
) {
1529 ret
= LTTNG_ERR_FILTER_INVAL
;
1530 free(filter_expression
);
1535 bytecode
= zmalloc(bytecode_len
);
1537 free(filter_expression
);
1539 ret
= LTTNG_ERR_FILTER_NOMEM
;
1543 /* Receive var. len. data */
1544 DBG("Receiving var len filter's bytecode from client ...");
1545 ret
= lttcomm_recv_unix_sock(*sock
, bytecode
, bytecode_len
);
1547 DBG("Nothing recv() from client var len data... continuing");
1549 free(filter_expression
);
1552 ret
= LTTNG_ERR_FILTER_INVAL
;
1556 if ((bytecode
->len
+ sizeof(*bytecode
)) != bytecode_len
) {
1557 free(filter_expression
);
1560 ret
= LTTNG_ERR_FILTER_INVAL
;
1565 ev
= lttng_event_copy(ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.enable
.event
));
1567 DBG("Failed to copy event: %s",
1568 cmd_ctx
->lsm
.u
.enable
.event
.name
);
1569 free(filter_expression
);
1572 ret
= LTTNG_ERR_NOMEM
;
1577 if (cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
> 0) {
1578 /* Expect a userspace probe description. */
1579 ret
= receive_userspace_probe(cmd_ctx
, *sock
, sock_error
, ev
);
1581 free(filter_expression
);
1584 lttng_event_destroy(ev
);
1589 ret
= cmd_enable_event(cmd_ctx
->session
,
1590 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1591 cmd_ctx
->lsm
.u
.enable
.channel_name
,
1593 filter_expression
, bytecode
, exclusion
,
1594 kernel_poll_pipe
[1]);
1595 lttng_event_destroy(ev
);
1598 case LTTNG_LIST_TRACEPOINTS
:
1600 struct lttng_event
*events
;
1603 session_lock_list();
1604 nb_events
= cmd_list_tracepoints(cmd_ctx
->lsm
.domain
.type
, &events
);
1605 session_unlock_list();
1606 if (nb_events
< 0) {
1607 /* Return value is a negative lttng_error_code. */
1613 * Setup lttng message with payload size set to the event list size in
1614 * bytes and then copy list into the llm payload.
1616 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1617 sizeof(struct lttng_event
) * nb_events
);
1627 case LTTNG_LIST_TRACEPOINT_FIELDS
:
1629 struct lttng_event_field
*fields
;
1632 session_lock_list();
1633 nb_fields
= cmd_list_tracepoint_fields(cmd_ctx
->lsm
.domain
.type
,
1635 session_unlock_list();
1636 if (nb_fields
< 0) {
1637 /* Return value is a negative lttng_error_code. */
1643 * Setup lttng message with payload size set to the event list size in
1644 * bytes and then copy list into the llm payload.
1646 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, fields
,
1647 sizeof(struct lttng_event_field
) * nb_fields
);
1657 case LTTNG_LIST_SYSCALLS
:
1659 struct lttng_event
*events
;
1662 nb_events
= cmd_list_syscalls(&events
);
1663 if (nb_events
< 0) {
1664 /* Return value is a negative lttng_error_code. */
1670 * Setup lttng message with payload size set to the event list size in
1671 * bytes and then copy list into the llm payload.
1673 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1674 sizeof(struct lttng_event
) * nb_events
);
1684 case LTTNG_SET_CONSUMER_URI
:
1687 struct lttng_uri
*uris
;
1689 nb_uri
= cmd_ctx
->lsm
.u
.uri
.size
;
1690 len
= nb_uri
* sizeof(struct lttng_uri
);
1693 ret
= LTTNG_ERR_INVALID
;
1697 uris
= zmalloc(len
);
1699 ret
= LTTNG_ERR_FATAL
;
1703 /* Receive variable len data */
1704 DBG("Receiving %zu URI(s) from client ...", nb_uri
);
1705 ret
= lttcomm_recv_unix_sock(*sock
, uris
, len
);
1707 DBG("No URIs received from client... continuing");
1709 ret
= LTTNG_ERR_SESSION_FAIL
;
1714 ret
= cmd_set_consumer_uri(cmd_ctx
->session
, nb_uri
, uris
);
1716 if (ret
!= LTTNG_OK
) {
1723 case LTTNG_START_TRACE
:
1726 * On the first start, if we have a kernel session and we have
1727 * enabled time or size-based rotations, we have to make sure
1728 * the kernel tracer supports it.
1730 if (!cmd_ctx
->session
->has_been_started
&& \
1731 cmd_ctx
->session
->kernel_session
&& \
1732 (cmd_ctx
->session
->rotate_timer_period
|| \
1733 cmd_ctx
->session
->rotate_size
) && \
1734 !check_rotate_compatible()) {
1735 DBG("Kernel tracer version is not compatible with the rotation feature");
1736 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
1739 ret
= cmd_start_trace(cmd_ctx
->session
);
1742 case LTTNG_STOP_TRACE
:
1744 ret
= cmd_stop_trace(cmd_ctx
->session
);
1747 case LTTNG_DESTROY_SESSION
:
1749 ret
= cmd_destroy_session(cmd_ctx
->session
,
1750 notification_thread_handle
,
1754 case LTTNG_LIST_DOMAINS
:
1757 struct lttng_domain
*domains
= NULL
;
1759 nb_dom
= cmd_list_domains(cmd_ctx
->session
, &domains
);
1761 /* Return value is a negative lttng_error_code. */
1766 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, domains
,
1767 nb_dom
* sizeof(struct lttng_domain
));
1777 case LTTNG_LIST_CHANNELS
:
1779 ssize_t payload_size
;
1780 struct lttng_channel
*channels
= NULL
;
1782 payload_size
= cmd_list_channels(cmd_ctx
->lsm
.domain
.type
,
1783 cmd_ctx
->session
, &channels
);
1784 if (payload_size
< 0) {
1785 /* Return value is a negative lttng_error_code. */
1786 ret
= -payload_size
;
1790 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, channels
,
1801 case LTTNG_LIST_EVENTS
:
1804 struct lttcomm_event_command_header cmd_header
= {};
1805 size_t original_payload_size
;
1806 size_t payload_size
;
1808 ret
= setup_empty_lttng_msg(cmd_ctx
);
1810 ret
= LTTNG_ERR_NOMEM
;
1814 original_payload_size
= cmd_ctx
->reply_payload
.buffer
.size
;
1816 /* Extended infos are included at the end of the payload. */
1817 list_ret
= cmd_list_events(cmd_ctx
->lsm
.domain
.type
,
1819 cmd_ctx
->lsm
.u
.list
.channel_name
,
1820 &cmd_ctx
->reply_payload
);
1822 /* Return value is a negative lttng_error_code. */
1827 payload_size
= cmd_ctx
->reply_payload
.buffer
.size
-
1828 sizeof(cmd_header
) - original_payload_size
;
1829 update_lttng_msg(cmd_ctx
, sizeof(cmd_header
), payload_size
);
1834 case LTTNG_LIST_SESSIONS
:
1836 unsigned int nr_sessions
;
1837 void *sessions_payload
;
1840 session_lock_list();
1841 nr_sessions
= lttng_sessions_count(
1842 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1843 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1845 payload_len
= (sizeof(struct lttng_session
) * nr_sessions
) +
1846 (sizeof(struct lttng_session_extended
) * nr_sessions
);
1847 sessions_payload
= zmalloc(payload_len
);
1849 if (!sessions_payload
) {
1850 session_unlock_list();
1855 cmd_list_lttng_sessions(sessions_payload
, nr_sessions
,
1856 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1857 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1858 session_unlock_list();
1860 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, sessions_payload
,
1862 free(sessions_payload
);
1871 case LTTNG_REGISTER_CONSUMER
:
1873 struct consumer_data
*cdata
;
1875 switch (cmd_ctx
->lsm
.domain
.type
) {
1876 case LTTNG_DOMAIN_KERNEL
:
1877 cdata
= &kconsumer_data
;
1880 ret
= LTTNG_ERR_UND
;
1884 ret
= cmd_register_consumer(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1885 cmd_ctx
->lsm
.u
.reg
.path
, cdata
);
1888 case LTTNG_DATA_PENDING
:
1891 uint8_t pending_ret_byte
;
1893 pending_ret
= cmd_data_pending(cmd_ctx
->session
);
1898 * This function may returns 0 or 1 to indicate whether or not
1899 * there is data pending. In case of error, it should return an
1900 * LTTNG_ERR code. However, some code paths may still return
1901 * a nondescript error code, which we handle by returning an
1904 if (pending_ret
== 0 || pending_ret
== 1) {
1906 * ret will be set to LTTNG_OK at the end of
1909 } else if (pending_ret
< 0) {
1910 ret
= LTTNG_ERR_UNK
;
1917 pending_ret_byte
= (uint8_t) pending_ret
;
1919 /* 1 byte to return whether or not data is pending */
1920 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1921 &pending_ret_byte
, 1);
1930 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
1932 uint32_t snapshot_id
;
1933 struct lttcomm_lttng_output_id reply
;
1935 ret
= cmd_snapshot_add_output(cmd_ctx
->session
,
1936 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
),
1938 if (ret
!= LTTNG_OK
) {
1941 reply
.id
= snapshot_id
;
1943 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &reply
,
1949 /* Copy output list into message payload */
1953 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
1955 ret
= cmd_snapshot_del_output(cmd_ctx
->session
,
1956 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
));
1959 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
1962 struct lttng_snapshot_output
*outputs
= NULL
;
1964 nb_output
= cmd_snapshot_list_outputs(cmd_ctx
->session
, &outputs
);
1965 if (nb_output
< 0) {
1970 assert((nb_output
> 0 && outputs
) || nb_output
== 0);
1971 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, outputs
,
1972 nb_output
* sizeof(struct lttng_snapshot_output
));
1982 case LTTNG_SNAPSHOT_RECORD
:
1984 ret
= cmd_snapshot_record(cmd_ctx
->session
,
1985 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_record
.output
),
1986 cmd_ctx
->lsm
.u
.snapshot_record
.wait
);
1989 case LTTNG_CREATE_SESSION_EXT
:
1991 struct lttng_dynamic_buffer payload
;
1992 struct lttng_session_descriptor
*return_descriptor
= NULL
;
1994 lttng_dynamic_buffer_init(&payload
);
1995 ret
= cmd_create_session(cmd_ctx
, *sock
, &return_descriptor
);
1996 if (ret
!= LTTNG_OK
) {
2000 ret
= lttng_session_descriptor_serialize(return_descriptor
,
2003 ERR("Failed to serialize session descriptor in reply to \"create session\" command");
2004 lttng_session_descriptor_destroy(return_descriptor
);
2005 ret
= LTTNG_ERR_NOMEM
;
2008 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, payload
.data
,
2011 lttng_session_descriptor_destroy(return_descriptor
);
2012 ret
= LTTNG_ERR_NOMEM
;
2015 lttng_dynamic_buffer_reset(&payload
);
2016 lttng_session_descriptor_destroy(return_descriptor
);
2020 case LTTNG_SAVE_SESSION
:
2022 ret
= cmd_save_sessions(&cmd_ctx
->lsm
.u
.save_session
.attr
,
2026 case LTTNG_SET_SESSION_SHM_PATH
:
2028 ret
= cmd_set_session_shm_path(cmd_ctx
->session
,
2029 cmd_ctx
->lsm
.u
.set_shm_path
.shm_path
);
2032 case LTTNG_REGENERATE_METADATA
:
2034 ret
= cmd_regenerate_metadata(cmd_ctx
->session
);
2037 case LTTNG_REGENERATE_STATEDUMP
:
2039 ret
= cmd_regenerate_statedump(cmd_ctx
->session
);
2042 case LTTNG_REGISTER_TRIGGER
:
2044 ret
= cmd_register_trigger(cmd_ctx
, *sock
,
2045 notification_thread_handle
);
2048 case LTTNG_UNREGISTER_TRIGGER
:
2050 ret
= cmd_unregister_trigger(cmd_ctx
, *sock
,
2051 notification_thread_handle
);
2054 case LTTNG_ROTATE_SESSION
:
2056 struct lttng_rotate_session_return rotate_return
;
2058 DBG("Client rotate session \"%s\"", cmd_ctx
->session
->name
);
2060 memset(&rotate_return
, 0, sizeof(rotate_return
));
2061 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2062 DBG("Kernel tracer version is not compatible with the rotation feature");
2063 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2067 ret
= cmd_rotate_session(cmd_ctx
->session
, &rotate_return
,
2069 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED
);
2075 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &rotate_return
,
2076 sizeof(rotate_return
));
2085 case LTTNG_ROTATION_GET_INFO
:
2087 struct lttng_rotation_get_info_return get_info_return
;
2089 memset(&get_info_return
, 0, sizeof(get_info_return
));
2090 ret
= cmd_rotate_get_info(cmd_ctx
->session
, &get_info_return
,
2091 cmd_ctx
->lsm
.u
.get_rotation_info
.rotation_id
);
2097 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &get_info_return
,
2098 sizeof(get_info_return
));
2107 case LTTNG_ROTATION_SET_SCHEDULE
:
2110 enum lttng_rotation_schedule_type schedule_type
;
2113 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2114 DBG("Kernel tracer version does not support session rotations");
2115 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2119 set_schedule
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.set
== 1;
2120 schedule_type
= (enum lttng_rotation_schedule_type
) cmd_ctx
->lsm
.u
.rotation_set_schedule
.type
;
2121 value
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.value
;
2123 ret
= cmd_rotation_set_schedule(cmd_ctx
->session
,
2127 notification_thread_handle
);
2128 if (ret
!= LTTNG_OK
) {
2134 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
2136 struct lttng_session_list_schedules_return schedules
= {
2137 .periodic
.set
= !!cmd_ctx
->session
->rotate_timer_period
,
2138 .periodic
.value
= cmd_ctx
->session
->rotate_timer_period
,
2139 .size
.set
= !!cmd_ctx
->session
->rotate_size
,
2140 .size
.value
= cmd_ctx
->session
->rotate_size
,
2143 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &schedules
,
2153 case LTTNG_CLEAR_SESSION
:
2155 ret
= cmd_clear_session(cmd_ctx
->session
, sock
);
2159 ret
= LTTNG_ERR_UND
;
2164 if (cmd_ctx
->reply_payload
.buffer
.size
== 0) {
2165 DBG("Missing llm header, creating one.");
2166 if (setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0) < 0) {
2170 /* Set return code */
2171 ((struct lttcomm_lttng_msg
*) (cmd_ctx
->reply_payload
.buffer
.data
))->ret_code
= ret
;
2173 if (cmd_ctx
->session
) {
2174 session_unlock(cmd_ctx
->session
);
2175 session_put(cmd_ctx
->session
);
2176 cmd_ctx
->session
= NULL
;
2178 if (need_tracing_session
) {
2179 session_unlock_list();
2182 assert(!rcu_read_ongoing());
2186 static int create_client_sock(void)
2188 int ret
, client_sock
;
2189 const mode_t old_umask
= umask(0);
2191 /* Create client tool unix socket */
2192 client_sock
= lttcomm_create_unix_sock(config
.client_unix_sock_path
.value
);
2193 if (client_sock
< 0) {
2194 ERR("Create unix sock failed: %s", config
.client_unix_sock_path
.value
);
2199 /* Set the cloexec flag */
2200 ret
= utils_set_fd_cloexec(client_sock
);
2202 ERR("Unable to set CLOEXEC flag to the client Unix socket (fd: %d). "
2203 "Continuing but note that the consumer daemon will have a "
2204 "reference to this socket on exec()", client_sock
);
2207 /* File permission MUST be 660 */
2208 ret
= chmod(config
.client_unix_sock_path
.value
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
2210 ERR("Set file permissions failed: %s",
2211 config
.client_unix_sock_path
.value
);
2213 (void) lttcomm_close_unix_sock(client_sock
);
2217 DBG("Created client socket (fd = %i)", client_sock
);
2224 static void cleanup_client_thread(void *data
)
2226 struct lttng_pipe
*quit_pipe
= data
;
2228 lttng_pipe_destroy(quit_pipe
);
2231 static void thread_init_cleanup(void *data
)
2233 set_thread_status(false);
2237 * This thread manage all clients request using the unix client socket for
2240 static void *thread_manage_clients(void *data
)
2242 int sock
= -1, ret
, i
, pollfd
, err
= -1;
2244 uint32_t revents
, nb_fd
;
2245 struct lttng_poll_event events
;
2246 const int client_sock
= thread_state
.client_sock
;
2247 struct lttng_pipe
*quit_pipe
= data
;
2248 const int thread_quit_pipe_fd
= lttng_pipe_get_readfd(quit_pipe
);
2249 struct command_ctx cmd_ctx
= {};
2251 DBG("[thread] Manage client started");
2253 lttng_payload_init(&cmd_ctx
.reply_payload
);
2255 is_root
= (getuid() == 0);
2257 pthread_cleanup_push(thread_init_cleanup
, NULL
);
2259 rcu_register_thread();
2261 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_CMD
);
2263 health_code_update();
2265 ret
= lttcomm_listen_unix_sock(client_sock
);
2271 * Pass 2 as size here for the thread quit pipe and client_sock. Nothing
2272 * more will be added to this poll set.
2274 ret
= lttng_poll_create(&events
, 2, LTTNG_CLOEXEC
);
2276 goto error_create_poll
;
2279 /* Add the application registration socket */
2280 ret
= lttng_poll_add(&events
, client_sock
, LPOLLIN
| LPOLLPRI
);
2285 /* Add thread quit pipe */
2286 ret
= lttng_poll_add(&events
, thread_quit_pipe_fd
, LPOLLIN
| LPOLLERR
);
2291 /* Set state as running. */
2292 set_thread_status(true);
2293 pthread_cleanup_pop(0);
2295 /* This testpoint is after we signal readiness to the parent. */
2296 if (testpoint(sessiond_thread_manage_clients
)) {
2300 if (testpoint(sessiond_thread_manage_clients_before_loop
)) {
2304 health_code_update();
2307 const struct cmd_completion_handler
*cmd_completion_handler
;
2309 cmd_ctx
.creds
= (lttng_sock_cred
) {
2313 cmd_ctx
.session
= NULL
;
2314 lttng_payload_clear(&cmd_ctx
.reply_payload
);
2315 cmd_ctx
.lttng_msg_size
= 0;
2317 DBG("Accepting client command ...");
2319 /* Inifinite blocking call, waiting for transmission */
2321 health_poll_entry();
2322 ret
= lttng_poll_wait(&events
, -1);
2326 * Restart interrupted system call.
2328 if (errno
== EINTR
) {
2336 for (i
= 0; i
< nb_fd
; i
++) {
2337 revents
= LTTNG_POLL_GETEV(&events
, i
);
2338 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2340 health_code_update();
2342 if (pollfd
== thread_quit_pipe_fd
) {
2346 /* Event on the registration socket */
2347 if (revents
& LPOLLIN
) {
2349 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2350 ERR("Client socket poll error");
2353 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2359 DBG("Wait for client response");
2361 health_code_update();
2363 sock
= lttcomm_accept_unix_sock(client_sock
);
2369 * Set the CLOEXEC flag. Return code is useless because either way, the
2372 (void) utils_set_fd_cloexec(sock
);
2374 /* Set socket option for credentials retrieval */
2375 ret
= lttcomm_setsockopt_creds_unix_sock(sock
);
2380 health_code_update();
2383 * Data is received from the lttng client. The struct
2384 * lttcomm_session_msg (lsm) contains the command and data request of
2387 DBG("Receiving data from client ...");
2388 ret
= lttcomm_recv_creds_unix_sock(sock
, &cmd_ctx
.lsm
,
2389 sizeof(struct lttcomm_session_msg
), &cmd_ctx
.creds
);
2390 if (ret
!= sizeof(struct lttcomm_session_msg
)) {
2391 DBG("Incomplete recv() from client... continuing");
2400 health_code_update();
2402 // TODO: Validate cmd_ctx including sanity check for
2403 // security purpose.
2405 rcu_thread_online();
2407 * This function dispatch the work to the kernel or userspace tracer
2408 * libs and fill the lttcomm_lttng_msg data structure of all the needed
2409 * informations for the client. The command context struct contains
2410 * everything this function may needs.
2412 ret
= process_client_msg(&cmd_ctx
, &sock
, &sock_error
);
2413 rcu_thread_offline();
2423 * TODO: Inform client somehow of the fatal error. At
2424 * this point, ret < 0 means that a zmalloc failed
2425 * (ENOMEM). Error detected but still accept
2426 * command, unless a socket error has been
2432 cmd_completion_handler
= cmd_pop_completion_handler();
2433 if (cmd_completion_handler
) {
2434 enum lttng_error_code completion_code
;
2436 completion_code
= cmd_completion_handler
->run(
2437 cmd_completion_handler
->data
);
2438 if (completion_code
!= LTTNG_OK
) {
2443 health_code_update();
2446 struct lttng_payload_view view
=
2447 lttng_payload_view_from_payload(
2448 &cmd_ctx
.reply_payload
,
2450 struct lttcomm_lttng_msg
*llm
= (typeof(
2451 llm
)) cmd_ctx
.reply_payload
.buffer
.data
;
2453 assert(cmd_ctx
.reply_payload
.buffer
.size
>=
2455 assert(cmd_ctx
.lttng_msg_size
== cmd_ctx
.reply_payload
.buffer
.size
);
2457 llm
->fd_count
= lttng_payload_view_get_fd_handle_count(&view
);
2459 DBG("Sending response (size: %d, retcode: %s (%d))",
2460 cmd_ctx
.lttng_msg_size
,
2461 lttng_strerror(-llm
->ret_code
),
2463 ret
= send_unix_sock(sock
, &view
);
2465 ERR("Failed to send data back to client");
2468 /* End of transmission */
2476 health_code_update();
2488 lttng_poll_clean(&events
);
2492 unlink(config
.client_unix_sock_path
.value
);
2493 ret
= close(client_sock
);
2500 ERR("Health error occurred in %s", __func__
);
2503 health_unregister(health_sessiond
);
2505 DBG("Client thread dying");
2506 lttng_payload_reset(&cmd_ctx
.reply_payload
);
2507 rcu_unregister_thread();
2512 bool shutdown_client_thread(void *thread_data
)
2514 struct lttng_pipe
*client_quit_pipe
= thread_data
;
2515 const int write_fd
= lttng_pipe_get_writefd(client_quit_pipe
);
2517 return notify_thread_pipe(write_fd
) == 1;
2520 struct lttng_thread
*launch_client_thread(void)
2522 bool thread_running
;
2523 struct lttng_pipe
*client_quit_pipe
;
2524 struct lttng_thread
*thread
= NULL
;
2525 int client_sock_fd
= -1;
2527 sem_init(&thread_state
.ready
, 0, 0);
2528 client_quit_pipe
= lttng_pipe_open(FD_CLOEXEC
);
2529 if (!client_quit_pipe
) {
2533 client_sock_fd
= create_client_sock();
2534 if (client_sock_fd
< 0) {
2538 thread_state
.client_sock
= client_sock_fd
;
2539 thread
= lttng_thread_create("Client management",
2540 thread_manage_clients
,
2541 shutdown_client_thread
,
2542 cleanup_client_thread
,
2547 /* The client thread now owns the client sock fd and the quit pipe. */
2548 client_sock_fd
= -1;
2549 client_quit_pipe
= NULL
;
2552 * This thread is part of the threads that need to be fully
2553 * initialized before the session daemon is marked as "ready".
2555 thread_running
= wait_thread_status();
2556 if (!thread_running
) {
2561 if (client_sock_fd
>= 0) {
2562 if (close(client_sock_fd
)) {
2563 PERROR("Failed to close client socket");
2566 lttng_thread_put(thread
);
2567 cleanup_client_thread(client_quit_pipe
);