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 ret
= lttng_dynamic_buffer_set_size(&cmd_ctx
->reply_payload
.buffer
, 0);
100 lttng_dynamic_pointer_array_clear(&cmd_ctx
->reply_payload
._fd_handles
);
102 cmd_ctx
->lttng_msg_size
= total_msg_size
;
104 /* Append reply header. */
105 ret
= lttng_dynamic_buffer_append(
106 &cmd_ctx
->reply_payload
.buffer
, &llm
, sizeof(llm
));
111 /* Append command header. */
112 if (cmd_header_len
) {
113 ret
= lttng_dynamic_buffer_append(
114 &cmd_ctx
->reply_payload
.buffer
, cmd_header_buf
,
121 /* Append payload. */
123 ret
= lttng_dynamic_buffer_append(
124 &cmd_ctx
->reply_payload
.buffer
, payload_buf
,
135 static int setup_empty_lttng_msg(struct command_ctx
*cmd_ctx
)
138 const struct lttcomm_lttng_msg llm
= {};
140 ret
= lttng_dynamic_buffer_set_size(&cmd_ctx
->reply_payload
.buffer
, 0);
145 /* Append place-holder reply header. */
146 ret
= lttng_dynamic_buffer_append(
147 &cmd_ctx
->reply_payload
.buffer
, &llm
, sizeof(llm
));
152 cmd_ctx
->lttng_msg_size
= sizeof(llm
);
157 static void update_lttng_msg(struct command_ctx
*cmd_ctx
, size_t cmd_header_len
,
160 const size_t header_len
= sizeof(struct lttcomm_lttng_msg
);
161 const size_t total_msg_size
= header_len
+ cmd_header_len
+ payload_len
;
162 const struct lttcomm_lttng_msg llm
= {
163 .cmd_type
= cmd_ctx
->lsm
.cmd_type
,
164 .pid
= cmd_ctx
->lsm
.domain
.attr
.pid
,
165 .cmd_header_size
= cmd_header_len
,
166 .data_size
= payload_len
,
168 struct lttcomm_lttng_msg
*p_llm
;
170 assert(cmd_ctx
->reply_payload
.buffer
.size
>= sizeof(llm
));
172 p_llm
= (typeof(p_llm
)) cmd_ctx
->reply_payload
.buffer
.data
;
174 /* Update existing header. */
175 memcpy(p_llm
, &llm
, sizeof(llm
));
177 cmd_ctx
->lttng_msg_size
= total_msg_size
;
181 * Start the thread_manage_consumer. This must be done after a lttng-consumerd
182 * exec or it will fail.
184 static int spawn_consumer_thread(struct consumer_data
*consumer_data
)
186 return launch_consumer_management_thread(consumer_data
) ? 0 : -1;
190 * Fork and exec a consumer daemon (consumerd).
192 * Return pid if successful else -1.
194 static pid_t
spawn_consumerd(struct consumer_data
*consumer_data
)
198 const char *consumer_to_use
;
199 const char *verbosity
;
202 DBG("Spawning consumerd");
209 if (config
.verbose_consumer
) {
210 verbosity
= "--verbose";
211 } else if (lttng_opt_quiet
) {
212 verbosity
= "--quiet";
217 switch (consumer_data
->type
) {
218 case LTTNG_CONSUMER_KERNEL
:
220 * Find out which consumerd to execute. We will first try the
221 * 64-bit path, then the sessiond's installation directory, and
222 * fallback on the 32-bit one,
224 DBG3("Looking for a kernel consumer at these locations:");
225 DBG3(" 1) %s", config
.consumerd64_bin_path
.value
? : "NULL");
226 DBG3(" 2) %s/%s", INSTALL_BIN_PATH
, DEFAULT_CONSUMERD_FILE
);
227 DBG3(" 3) %s", config
.consumerd32_bin_path
.value
? : "NULL");
228 if (stat(config
.consumerd64_bin_path
.value
, &st
) == 0) {
229 DBG3("Found location #1");
230 consumer_to_use
= config
.consumerd64_bin_path
.value
;
231 } else if (stat(INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
, &st
) == 0) {
232 DBG3("Found location #2");
233 consumer_to_use
= INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
;
234 } else if (config
.consumerd32_bin_path
.value
&&
235 stat(config
.consumerd32_bin_path
.value
, &st
) == 0) {
236 DBG3("Found location #3");
237 consumer_to_use
= config
.consumerd32_bin_path
.value
;
239 DBG("Could not find any valid consumerd executable");
243 DBG("Using kernel consumer at: %s", consumer_to_use
);
244 (void) execl(consumer_to_use
,
245 "lttng-consumerd", verbosity
, "-k",
246 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
247 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
248 "--group", config
.tracing_group_name
.value
,
251 case LTTNG_CONSUMER64_UST
:
253 if (config
.consumerd64_lib_dir
.value
) {
258 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
262 tmplen
= strlen(config
.consumerd64_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
263 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
268 strcat(tmpnew
, config
.consumerd64_lib_dir
.value
);
269 if (tmp
[0] != '\0') {
273 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
280 DBG("Using 64-bit UST consumer at: %s", config
.consumerd64_bin_path
.value
);
281 (void) execl(config
.consumerd64_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
282 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
283 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
284 "--group", config
.tracing_group_name
.value
,
288 case LTTNG_CONSUMER32_UST
:
290 if (config
.consumerd32_lib_dir
.value
) {
295 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
299 tmplen
= strlen(config
.consumerd32_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
300 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
305 strcat(tmpnew
, config
.consumerd32_lib_dir
.value
);
306 if (tmp
[0] != '\0') {
310 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
317 DBG("Using 32-bit UST consumer at: %s", config
.consumerd32_bin_path
.value
);
318 (void) execl(config
.consumerd32_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
319 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
320 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
321 "--group", config
.tracing_group_name
.value
,
326 ERR("unknown consumer type");
330 PERROR("Consumer execl()");
332 /* Reaching this point, we got a failure on our execl(). */
334 } else if (pid
> 0) {
337 PERROR("start consumer fork");
345 * Spawn the consumerd daemon and session daemon thread.
347 static int start_consumerd(struct consumer_data
*consumer_data
)
352 * Set the listen() state on the socket since there is a possible race
353 * between the exec() of the consumer daemon and this call if place in the
354 * consumer thread. See bug #366 for more details.
356 ret
= lttcomm_listen_unix_sock(consumer_data
->err_sock
);
361 pthread_mutex_lock(&consumer_data
->pid_mutex
);
362 if (consumer_data
->pid
!= 0) {
363 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
367 ret
= spawn_consumerd(consumer_data
);
369 ERR("Spawning consumerd failed");
370 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
374 /* Setting up the consumer_data pid */
375 consumer_data
->pid
= ret
;
376 DBG2("Consumer pid %d", consumer_data
->pid
);
377 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
379 DBG2("Spawning consumer control thread");
380 ret
= spawn_consumer_thread(consumer_data
);
382 ERR("Fatal error spawning consumer control thread");
390 /* Cleanup already created sockets on error. */
391 if (consumer_data
->err_sock
>= 0) {
394 err
= close(consumer_data
->err_sock
);
396 PERROR("close consumer data error socket");
403 * Copy consumer output from the tracing session to the domain session. The
404 * function also applies the right modification on a per domain basis for the
405 * trace files destination directory.
407 * Should *NOT* be called with RCU read-side lock held.
409 static int copy_session_consumer(int domain
, struct ltt_session
*session
)
412 const char *dir_name
;
413 struct consumer_output
*consumer
;
416 assert(session
->consumer
);
419 case LTTNG_DOMAIN_KERNEL
:
420 DBG3("Copying tracing session consumer output in kernel session");
422 * XXX: We should audit the session creation and what this function
423 * does "extra" in order to avoid a destroy since this function is used
424 * in the domain session creation (kernel and ust) only. Same for UST
427 if (session
->kernel_session
->consumer
) {
428 consumer_output_put(session
->kernel_session
->consumer
);
430 session
->kernel_session
->consumer
=
431 consumer_copy_output(session
->consumer
);
432 /* Ease our life a bit for the next part */
433 consumer
= session
->kernel_session
->consumer
;
434 dir_name
= DEFAULT_KERNEL_TRACE_DIR
;
436 case LTTNG_DOMAIN_JUL
:
437 case LTTNG_DOMAIN_LOG4J
:
438 case LTTNG_DOMAIN_PYTHON
:
439 case LTTNG_DOMAIN_UST
:
440 DBG3("Copying tracing session consumer output in UST session");
441 if (session
->ust_session
->consumer
) {
442 consumer_output_put(session
->ust_session
->consumer
);
444 session
->ust_session
->consumer
=
445 consumer_copy_output(session
->consumer
);
446 /* Ease our life a bit for the next part */
447 consumer
= session
->ust_session
->consumer
;
448 dir_name
= DEFAULT_UST_TRACE_DIR
;
451 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
455 /* Append correct directory to subdir */
456 ret
= lttng_strncpy(consumer
->domain_subdir
, dir_name
,
457 sizeof(consumer
->domain_subdir
));
462 DBG3("Copy session consumer subdir %s", consumer
->domain_subdir
);
470 * Create an UST session and add it to the session ust list.
472 * Should *NOT* be called with RCU read-side lock held.
474 static int create_ust_session(struct ltt_session
*session
,
475 const struct lttng_domain
*domain
)
478 struct ltt_ust_session
*lus
= NULL
;
482 assert(session
->consumer
);
484 switch (domain
->type
) {
485 case LTTNG_DOMAIN_JUL
:
486 case LTTNG_DOMAIN_LOG4J
:
487 case LTTNG_DOMAIN_PYTHON
:
488 case LTTNG_DOMAIN_UST
:
491 ERR("Unknown UST domain on create session %d", domain
->type
);
492 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
496 DBG("Creating UST session");
498 lus
= trace_ust_create_session(session
->id
);
500 ret
= LTTNG_ERR_UST_SESS_FAIL
;
504 lus
->uid
= session
->uid
;
505 lus
->gid
= session
->gid
;
506 lus
->output_traces
= session
->output_traces
;
507 lus
->snapshot_mode
= session
->snapshot_mode
;
508 lus
->live_timer_interval
= session
->live_timer
;
509 session
->ust_session
= lus
;
510 if (session
->shm_path
[0]) {
511 strncpy(lus
->root_shm_path
, session
->shm_path
,
512 sizeof(lus
->root_shm_path
));
513 lus
->root_shm_path
[sizeof(lus
->root_shm_path
) - 1] = '\0';
514 strncpy(lus
->shm_path
, session
->shm_path
,
515 sizeof(lus
->shm_path
));
516 lus
->shm_path
[sizeof(lus
->shm_path
) - 1] = '\0';
517 strncat(lus
->shm_path
, "/ust",
518 sizeof(lus
->shm_path
) - strlen(lus
->shm_path
) - 1);
520 /* Copy session output to the newly created UST session */
521 ret
= copy_session_consumer(domain
->type
, session
);
522 if (ret
!= LTTNG_OK
) {
530 session
->ust_session
= NULL
;
535 * Create a kernel tracer session then create the default channel.
537 static int create_kernel_session(struct ltt_session
*session
)
541 DBG("Creating kernel session");
543 ret
= kernel_create_session(session
);
545 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
549 /* Code flow safety */
550 assert(session
->kernel_session
);
552 /* Copy session output to the newly created Kernel session */
553 ret
= copy_session_consumer(LTTNG_DOMAIN_KERNEL
, session
);
554 if (ret
!= LTTNG_OK
) {
558 session
->kernel_session
->uid
= session
->uid
;
559 session
->kernel_session
->gid
= session
->gid
;
560 session
->kernel_session
->output_traces
= session
->output_traces
;
561 session
->kernel_session
->snapshot_mode
= session
->snapshot_mode
;
562 session
->kernel_session
->is_live_session
= session
->live_timer
!= 0;
567 trace_kernel_destroy_session(session
->kernel_session
);
568 session
->kernel_session
= NULL
;
574 * Count number of session permitted by uid/gid.
576 static unsigned int lttng_sessions_count(uid_t uid
, gid_t gid
)
579 struct ltt_session
*session
;
580 const struct ltt_session_list
*session_list
= session_get_list();
582 DBG("Counting number of available session for UID %d GID %d",
584 cds_list_for_each_entry(session
, &session_list
->head
, list
) {
585 if (!session_get(session
)) {
588 session_lock(session
);
589 /* Only count the sessions the user can control. */
590 if (session_access_ok(session
, uid
, gid
) &&
591 !session
->destroyed
) {
594 session_unlock(session
);
595 session_put(session
);
600 static int receive_userspace_probe(struct command_ctx
*cmd_ctx
, int sock
,
601 int *sock_error
, struct lttng_event
*event
)
604 struct lttng_userspace_probe_location
*probe_location
;
605 struct lttng_payload probe_location_payload
;
606 struct fd_handle
*handle
= NULL
;
609 * Create a payload to store the serialized version of the probe
612 lttng_payload_init(&probe_location_payload
);
614 ret
= lttng_dynamic_buffer_set_size(&probe_location_payload
.buffer
,
615 cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
);
617 ret
= LTTNG_ERR_NOMEM
;
622 * Receive the probe location.
624 ret
= lttcomm_recv_unix_sock(sock
, probe_location_payload
.buffer
.data
,
625 probe_location_payload
.buffer
.size
);
627 DBG("Nothing recv() from client var len data... continuing");
629 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
634 * Receive the file descriptor to the target binary from the client.
636 DBG("Receiving userspace probe target FD from client ...");
637 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
639 DBG("Nothing recv() from client userspace probe fd... continuing");
641 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
645 handle
= fd_handle_create(fd
);
647 ret
= LTTNG_ERR_NOMEM
;
651 /* Transferred to the handle. */
654 ret
= lttng_payload_push_fd_handle(&probe_location_payload
, handle
);
656 ERR("Failed to add userspace probe file descriptor to payload");
657 ret
= LTTNG_ERR_NOMEM
;
661 fd_handle_put(handle
);
665 struct lttng_payload_view view
= lttng_payload_view_from_payload(
666 &probe_location_payload
, 0, -1);
668 /* Extract the probe location from the serialized version. */
669 ret
= lttng_userspace_probe_location_create_from_payload(
670 &view
, &probe_location
);
673 WARN("Failed to create a userspace probe location from the received buffer");
674 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
678 /* Attach the probe location to the event. */
679 ret
= lttng_event_set_userspace_probe_location(event
, probe_location
);
681 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
688 PERROR("Failed to close userspace probe location binary fd");
692 fd_handle_put(handle
);
693 lttng_payload_reset(&probe_location_payload
);
698 * Version of setup_lttng_msg() without command header.
700 static int setup_lttng_msg_no_cmd_header(struct command_ctx
*cmd_ctx
,
701 void *payload_buf
, size_t payload_len
)
703 return setup_lttng_msg(cmd_ctx
, payload_buf
, payload_len
, NULL
, 0);
707 * Check if the current kernel tracer supports the session rotation feature.
708 * Return 1 if it does, 0 otherwise.
710 static int check_rotate_compatible(void)
714 if (kernel_tracer_version
.major
!= 2 || kernel_tracer_version
.minor
< 11) {
715 DBG("Kernel tracer version is not compatible with the rotation feature");
723 * Send data on a unix socket using the liblttsessiondcomm API.
725 * Return lttcomm error code.
727 static int send_unix_sock(int sock
, struct lttng_payload_view
*view
)
730 const int fd_count
= lttng_payload_view_get_fd_handle_count(view
);
732 /* Check valid length */
733 if (view
->buffer
.size
== 0) {
738 ret
= lttcomm_send_unix_sock(
739 sock
, view
->buffer
.data
, view
->buffer
.size
);
745 ret
= lttcomm_send_payload_view_fds_unix_sock(sock
, view
);
756 * Process the command requested by the lttng client within the command
757 * context structure. This function make sure that the return structure (llm)
758 * is set and ready for transmission before returning.
760 * Return any error encountered or 0 for success.
762 * "sock" is only used for special-case var. len data.
763 * A command may assume the ownership of the socket, in which case its value
764 * should be set to -1.
766 * Should *NOT* be called with RCU read-side lock held.
768 static int process_client_msg(struct command_ctx
*cmd_ctx
, int *sock
,
772 int need_tracing_session
= 1;
775 DBG("Processing client command %d", cmd_ctx
->lsm
.cmd_type
);
777 assert(!rcu_read_ongoing());
781 switch (cmd_ctx
->lsm
.cmd_type
) {
782 case LTTNG_CREATE_SESSION_EXT
:
783 case LTTNG_DESTROY_SESSION
:
784 case LTTNG_LIST_SESSIONS
:
785 case LTTNG_LIST_DOMAINS
:
786 case LTTNG_START_TRACE
:
787 case LTTNG_STOP_TRACE
:
788 case LTTNG_DATA_PENDING
:
789 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
790 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
791 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
792 case LTTNG_SNAPSHOT_RECORD
:
793 case LTTNG_SAVE_SESSION
:
794 case LTTNG_SET_SESSION_SHM_PATH
:
795 case LTTNG_REGENERATE_METADATA
:
796 case LTTNG_REGENERATE_STATEDUMP
:
797 case LTTNG_REGISTER_TRIGGER
:
798 case LTTNG_UNREGISTER_TRIGGER
:
799 case LTTNG_ROTATE_SESSION
:
800 case LTTNG_ROTATION_GET_INFO
:
801 case LTTNG_ROTATION_SET_SCHEDULE
:
802 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
803 case LTTNG_CLEAR_SESSION
:
810 if (config
.no_kernel
&& need_domain
811 && cmd_ctx
->lsm
.domain
.type
== LTTNG_DOMAIN_KERNEL
) {
813 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
815 ret
= LTTNG_ERR_KERN_NA
;
820 /* Deny register consumer if we already have a spawned consumer. */
821 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_REGISTER_CONSUMER
) {
822 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
823 if (kconsumer_data
.pid
> 0) {
824 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
825 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
828 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
832 * Check for command that don't needs to allocate a returned payload. We do
833 * this here so we don't have to make the call for no payload at each
836 switch(cmd_ctx
->lsm
.cmd_type
) {
837 case LTTNG_LIST_SESSIONS
:
838 case LTTNG_LIST_TRACEPOINTS
:
839 case LTTNG_LIST_TRACEPOINT_FIELDS
:
840 case LTTNG_LIST_DOMAINS
:
841 case LTTNG_LIST_CHANNELS
:
842 case LTTNG_LIST_EVENTS
:
843 case LTTNG_LIST_SYSCALLS
:
844 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
845 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
846 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
847 case LTTNG_DATA_PENDING
:
848 case LTTNG_ROTATE_SESSION
:
849 case LTTNG_ROTATION_GET_INFO
:
852 /* Setup lttng message with no payload */
853 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0);
855 /* This label does not try to unlock the session */
856 goto init_setup_error
;
860 /* Commands that DO NOT need a session. */
861 switch (cmd_ctx
->lsm
.cmd_type
) {
862 case LTTNG_CREATE_SESSION_EXT
:
863 case LTTNG_LIST_SESSIONS
:
864 case LTTNG_LIST_TRACEPOINTS
:
865 case LTTNG_LIST_SYSCALLS
:
866 case LTTNG_LIST_TRACEPOINT_FIELDS
:
867 case LTTNG_SAVE_SESSION
:
868 case LTTNG_REGISTER_TRIGGER
:
869 case LTTNG_UNREGISTER_TRIGGER
:
870 need_tracing_session
= 0;
873 DBG("Getting session %s by name", cmd_ctx
->lsm
.session
.name
);
875 * We keep the session list lock across _all_ commands
876 * for now, because the per-session lock does not
877 * handle teardown properly.
880 cmd_ctx
->session
= session_find_by_name(cmd_ctx
->lsm
.session
.name
);
881 if (cmd_ctx
->session
== NULL
) {
882 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
885 /* Acquire lock for the session */
886 session_lock(cmd_ctx
->session
);
892 * Commands that need a valid session but should NOT create one if none
893 * exists. Instead of creating one and destroying it when the command is
894 * handled, process that right before so we save some round trip in useless
897 switch (cmd_ctx
->lsm
.cmd_type
) {
898 case LTTNG_DISABLE_CHANNEL
:
899 case LTTNG_DISABLE_EVENT
:
900 switch (cmd_ctx
->lsm
.domain
.type
) {
901 case LTTNG_DOMAIN_KERNEL
:
902 if (!cmd_ctx
->session
->kernel_session
) {
903 ret
= LTTNG_ERR_NO_CHANNEL
;
907 case LTTNG_DOMAIN_JUL
:
908 case LTTNG_DOMAIN_LOG4J
:
909 case LTTNG_DOMAIN_PYTHON
:
910 case LTTNG_DOMAIN_UST
:
911 if (!cmd_ctx
->session
->ust_session
) {
912 ret
= LTTNG_ERR_NO_CHANNEL
;
917 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
929 * Check domain type for specific "pre-action".
931 switch (cmd_ctx
->lsm
.domain
.type
) {
932 case LTTNG_DOMAIN_KERNEL
:
934 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
938 /* Kernel tracer check */
939 if (!kernel_tracer_is_initialized()) {
940 /* Basically, load kernel tracer modules */
941 ret
= init_kernel_tracer();
947 /* Consumer is in an ERROR state. Report back to client */
948 if (uatomic_read(&kernel_consumerd_state
) == CONSUMER_ERROR
) {
949 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
953 /* Need a session for kernel command */
954 if (need_tracing_session
) {
955 if (cmd_ctx
->session
->kernel_session
== NULL
) {
956 ret
= create_kernel_session(cmd_ctx
->session
);
957 if (ret
!= LTTNG_OK
) {
958 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
963 /* Start the kernel consumer daemon */
964 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
965 if (kconsumer_data
.pid
== 0 &&
966 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
967 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
968 ret
= start_consumerd(&kconsumer_data
);
970 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
973 uatomic_set(&kernel_consumerd_state
, CONSUMER_STARTED
);
975 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
979 * The consumer was just spawned so we need to add the socket to
980 * the consumer output of the session if exist.
982 ret
= consumer_create_socket(&kconsumer_data
,
983 cmd_ctx
->session
->kernel_session
->consumer
);
990 case LTTNG_DOMAIN_JUL
:
991 case LTTNG_DOMAIN_LOG4J
:
992 case LTTNG_DOMAIN_PYTHON
:
993 case LTTNG_DOMAIN_UST
:
995 if (!ust_app_supported()) {
996 ret
= LTTNG_ERR_NO_UST
;
999 /* Consumer is in an ERROR state. Report back to client */
1000 if (uatomic_read(&ust_consumerd_state
) == CONSUMER_ERROR
) {
1001 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1005 if (need_tracing_session
) {
1006 /* Create UST session if none exist. */
1007 if (cmd_ctx
->session
->ust_session
== NULL
) {
1008 ret
= create_ust_session(cmd_ctx
->session
,
1009 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
));
1010 if (ret
!= LTTNG_OK
) {
1015 /* Start the UST consumer daemons */
1017 pthread_mutex_lock(&ustconsumer64_data
.pid_mutex
);
1018 if (config
.consumerd64_bin_path
.value
&&
1019 ustconsumer64_data
.pid
== 0 &&
1020 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1021 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1022 ret
= start_consumerd(&ustconsumer64_data
);
1024 ret
= LTTNG_ERR_UST_CONSUMER64_FAIL
;
1025 uatomic_set(&ust_consumerd64_fd
, -EINVAL
);
1029 uatomic_set(&ust_consumerd64_fd
, ustconsumer64_data
.cmd_sock
);
1030 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1032 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1036 * Setup socket for consumer 64 bit. No need for atomic access
1037 * since it was set above and can ONLY be set in this thread.
1039 ret
= consumer_create_socket(&ustconsumer64_data
,
1040 cmd_ctx
->session
->ust_session
->consumer
);
1046 pthread_mutex_lock(&ustconsumer32_data
.pid_mutex
);
1047 if (config
.consumerd32_bin_path
.value
&&
1048 ustconsumer32_data
.pid
== 0 &&
1049 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1050 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1051 ret
= start_consumerd(&ustconsumer32_data
);
1053 ret
= LTTNG_ERR_UST_CONSUMER32_FAIL
;
1054 uatomic_set(&ust_consumerd32_fd
, -EINVAL
);
1058 uatomic_set(&ust_consumerd32_fd
, ustconsumer32_data
.cmd_sock
);
1059 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1061 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1065 * Setup socket for consumer 32 bit. No need for atomic access
1066 * since it was set above and can ONLY be set in this thread.
1068 ret
= consumer_create_socket(&ustconsumer32_data
,
1069 cmd_ctx
->session
->ust_session
->consumer
);
1081 /* Validate consumer daemon state when start/stop trace command */
1082 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_START_TRACE
||
1083 cmd_ctx
->lsm
.cmd_type
== LTTNG_STOP_TRACE
) {
1084 switch (cmd_ctx
->lsm
.domain
.type
) {
1085 case LTTNG_DOMAIN_NONE
:
1087 case LTTNG_DOMAIN_JUL
:
1088 case LTTNG_DOMAIN_LOG4J
:
1089 case LTTNG_DOMAIN_PYTHON
:
1090 case LTTNG_DOMAIN_UST
:
1091 if (uatomic_read(&ust_consumerd_state
) != CONSUMER_STARTED
) {
1092 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1096 case LTTNG_DOMAIN_KERNEL
:
1097 if (uatomic_read(&kernel_consumerd_state
) != CONSUMER_STARTED
) {
1098 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
1103 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1109 * Check that the UID or GID match that of the tracing session.
1110 * The root user can interact with all sessions.
1112 if (need_tracing_session
) {
1113 if (!session_access_ok(cmd_ctx
->session
,
1114 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1115 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
)) ||
1116 cmd_ctx
->session
->destroyed
) {
1117 ret
= LTTNG_ERR_EPERM
;
1123 * Send relayd information to consumer as soon as we have a domain and a
1126 if (cmd_ctx
->session
&& need_domain
) {
1128 * Setup relayd if not done yet. If the relayd information was already
1129 * sent to the consumer, this call will gracefully return.
1131 ret
= cmd_setup_relayd(cmd_ctx
->session
);
1132 if (ret
!= LTTNG_OK
) {
1137 /* Process by command type */
1138 switch (cmd_ctx
->lsm
.cmd_type
) {
1139 case LTTNG_ADD_CONTEXT
:
1142 * An LTTNG_ADD_CONTEXT command might have a supplementary
1143 * payload if the context being added is an application context.
1145 if (cmd_ctx
->lsm
.u
.context
.ctx
.ctx
==
1146 LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1147 char *provider_name
= NULL
, *context_name
= NULL
;
1148 size_t provider_name_len
=
1149 cmd_ctx
->lsm
.u
.context
.provider_name_len
;
1150 size_t context_name_len
=
1151 cmd_ctx
->lsm
.u
.context
.context_name_len
;
1153 if (provider_name_len
== 0 || context_name_len
== 0) {
1155 * Application provider and context names MUST
1158 ret
= -LTTNG_ERR_INVALID
;
1162 provider_name
= zmalloc(provider_name_len
+ 1);
1163 if (!provider_name
) {
1164 ret
= -LTTNG_ERR_NOMEM
;
1167 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
=
1170 context_name
= zmalloc(context_name_len
+ 1);
1171 if (!context_name
) {
1172 ret
= -LTTNG_ERR_NOMEM
;
1173 goto error_add_context
;
1175 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
=
1178 ret
= lttcomm_recv_unix_sock(*sock
, provider_name
,
1181 goto error_add_context
;
1184 ret
= lttcomm_recv_unix_sock(*sock
, context_name
,
1187 goto error_add_context
;
1192 * cmd_add_context assumes ownership of the provider and context
1195 ret
= cmd_add_context(cmd_ctx
->session
,
1196 cmd_ctx
->lsm
.domain
.type
,
1197 cmd_ctx
->lsm
.u
.context
.channel_name
,
1198 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.context
.ctx
),
1199 kernel_poll_pipe
[1]);
1201 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
1202 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
1204 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
);
1205 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
);
1211 case LTTNG_DISABLE_CHANNEL
:
1213 ret
= cmd_disable_channel(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1214 cmd_ctx
->lsm
.u
.disable
.channel_name
);
1217 case LTTNG_DISABLE_EVENT
:
1221 * FIXME: handle filter; for now we just receive the filter's
1222 * bytecode along with the filter expression which are sent by
1223 * liblttng-ctl and discard them.
1225 * This fixes an issue where the client may block while sending
1226 * the filter payload and encounter an error because the session
1227 * daemon closes the socket without ever handling this data.
1229 size_t count
= cmd_ctx
->lsm
.u
.disable
.expression_len
+
1230 cmd_ctx
->lsm
.u
.disable
.bytecode_len
;
1233 char data
[LTTNG_FILTER_MAX_LEN
];
1235 DBG("Discarding disable event command payload of size %zu", count
);
1237 ret
= lttcomm_recv_unix_sock(*sock
, data
,
1238 count
> sizeof(data
) ? sizeof(data
) : count
);
1243 count
-= (size_t) ret
;
1246 ret
= cmd_disable_event(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1247 cmd_ctx
->lsm
.u
.disable
.channel_name
,
1248 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.disable
.event
));
1251 case LTTNG_ENABLE_CHANNEL
:
1253 cmd_ctx
->lsm
.u
.channel
.chan
.attr
.extended
.ptr
=
1254 (struct lttng_channel_extended
*) &cmd_ctx
->lsm
.u
.channel
.extended
;
1255 ret
= cmd_enable_channel(cmd_ctx
->session
,
1256 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1257 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.channel
.chan
),
1258 kernel_poll_pipe
[1]);
1261 case LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
:
1262 case LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE
:
1264 struct lttng_dynamic_buffer payload
;
1265 struct lttng_buffer_view payload_view
;
1266 const bool add_value
=
1267 cmd_ctx
->lsm
.cmd_type
==
1268 LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
;
1269 const size_t name_len
=
1270 cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1272 const enum lttng_domain_type domain_type
=
1273 (enum lttng_domain_type
)
1274 cmd_ctx
->lsm
.domain
.type
;
1275 const enum lttng_process_attr process_attr
=
1276 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1277 .process_attr_tracker_add_remove_include_value
1279 const enum lttng_process_attr_value_type value_type
=
1280 (enum lttng_process_attr_value_type
) cmd_ctx
1282 .process_attr_tracker_add_remove_include_value
1284 struct process_attr_value
*value
;
1285 enum lttng_error_code ret_code
;
1287 /* Receive remaining variable length payload if applicable. */
1288 if (name_len
> LOGIN_NAME_MAX
) {
1290 * POSIX mandates user and group names that are at least
1291 * 8 characters long. Note that although shadow-utils
1292 * (useradd, groupaadd, etc.) use 32 chars as their
1293 * limit (from bits/utmp.h, UT_NAMESIZE),
1294 * LOGIN_NAME_MAX is defined to 256.
1296 ERR("Rejecting process attribute tracker value %s as the provided exceeds the maximal allowed length: argument length = %zu, maximal length = %d",
1297 add_value
? "addition" : "removal",
1298 name_len
, LOGIN_NAME_MAX
);
1299 ret
= LTTNG_ERR_INVALID
;
1303 lttng_dynamic_buffer_init(&payload
);
1304 if (name_len
!= 0) {
1306 * Receive variable payload for user/group name
1309 ret
= lttng_dynamic_buffer_set_size(&payload
, name_len
);
1311 ERR("Failed to allocate buffer to receive payload of %s process attribute tracker value argument",
1312 add_value
? "add" : "remove");
1313 ret
= LTTNG_ERR_NOMEM
;
1314 goto error_add_remove_tracker_value
;
1317 ret
= lttcomm_recv_unix_sock(
1318 *sock
, payload
.data
, name_len
);
1320 ERR("Failed to receive payload of %s process attribute tracker value argument",
1321 add_value
? "add" : "remove");
1323 ret
= LTTNG_ERR_INVALID_PROTOCOL
;
1324 goto error_add_remove_tracker_value
;
1328 payload_view
= lttng_buffer_view_from_dynamic_buffer(
1329 &payload
, 0, name_len
);
1331 * Validate the value type and domains are legal for the process
1332 * attribute tracker that is specified and convert the value to
1333 * add/remove to the internal sessiond representation.
1335 ret_code
= process_attr_value_from_comm(domain_type
,
1336 process_attr
, value_type
,
1337 &cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1339 &payload_view
, &value
);
1340 if (ret_code
!= LTTNG_OK
) {
1342 goto error_add_remove_tracker_value
;
1346 ret
= cmd_process_attr_tracker_inclusion_set_add_value(
1347 cmd_ctx
->session
, domain_type
,
1348 process_attr
, value
);
1350 ret
= cmd_process_attr_tracker_inclusion_set_remove_value(
1351 cmd_ctx
->session
, domain_type
,
1352 process_attr
, value
);
1354 process_attr_value_destroy(value
);
1355 error_add_remove_tracker_value
:
1356 lttng_dynamic_buffer_reset(&payload
);
1359 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
1361 enum lttng_tracking_policy tracking_policy
;
1362 const enum lttng_domain_type domain_type
=
1363 (enum lttng_domain_type
)
1364 cmd_ctx
->lsm
.domain
.type
;
1365 const enum lttng_process_attr process_attr
=
1366 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1367 .process_attr_tracker_get_tracking_policy
1370 ret
= cmd_process_attr_tracker_get_tracking_policy(
1371 cmd_ctx
->session
, domain_type
, process_attr
,
1373 if (ret
!= LTTNG_OK
) {
1377 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1378 &(uint32_t){tracking_policy
}, sizeof(uint32_t));
1380 ret
= LTTNG_ERR_NOMEM
;
1386 case LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY
:
1388 const enum lttng_tracking_policy tracking_policy
=
1389 (enum lttng_tracking_policy
) cmd_ctx
->lsm
.u
1390 .process_attr_tracker_set_tracking_policy
1392 const enum lttng_domain_type domain_type
=
1393 (enum lttng_domain_type
)
1394 cmd_ctx
->lsm
.domain
.type
;
1395 const enum lttng_process_attr process_attr
=
1396 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1397 .process_attr_tracker_set_tracking_policy
1400 ret
= cmd_process_attr_tracker_set_tracking_policy(
1401 cmd_ctx
->session
, domain_type
, process_attr
,
1403 if (ret
!= LTTNG_OK
) {
1408 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
1410 struct lttng_process_attr_values
*values
;
1411 struct lttng_dynamic_buffer reply
;
1412 const enum lttng_domain_type domain_type
=
1413 (enum lttng_domain_type
)
1414 cmd_ctx
->lsm
.domain
.type
;
1415 const enum lttng_process_attr process_attr
=
1416 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1417 .process_attr_tracker_get_inclusion_set
1420 ret
= cmd_process_attr_tracker_get_inclusion_set(
1421 cmd_ctx
->session
, domain_type
, process_attr
,
1423 if (ret
!= LTTNG_OK
) {
1427 lttng_dynamic_buffer_init(&reply
);
1428 ret
= lttng_process_attr_values_serialize(values
, &reply
);
1430 goto error_tracker_get_inclusion_set
;
1433 ret
= setup_lttng_msg_no_cmd_header(
1434 cmd_ctx
, reply
.data
, reply
.size
);
1436 ret
= LTTNG_ERR_NOMEM
;
1437 goto error_tracker_get_inclusion_set
;
1441 error_tracker_get_inclusion_set
:
1442 lttng_process_attr_values_destroy(values
);
1443 lttng_dynamic_buffer_reset(&reply
);
1446 case LTTNG_ENABLE_EVENT
:
1448 struct lttng_event
*ev
= NULL
;
1449 struct lttng_event_exclusion
*exclusion
= NULL
;
1450 struct lttng_filter_bytecode
*bytecode
= NULL
;
1451 char *filter_expression
= NULL
;
1453 /* Handle exclusion events and receive it from the client. */
1454 if (cmd_ctx
->lsm
.u
.enable
.exclusion_count
> 0) {
1455 size_t count
= cmd_ctx
->lsm
.u
.enable
.exclusion_count
;
1457 exclusion
= zmalloc(sizeof(struct lttng_event_exclusion
) +
1458 (count
* LTTNG_SYMBOL_NAME_LEN
));
1460 ret
= LTTNG_ERR_EXCLUSION_NOMEM
;
1464 DBG("Receiving var len exclusion event list from client ...");
1465 exclusion
->count
= count
;
1466 ret
= lttcomm_recv_unix_sock(*sock
, exclusion
->names
,
1467 count
* LTTNG_SYMBOL_NAME_LEN
);
1469 DBG("Nothing recv() from client var len data... continuing");
1472 ret
= LTTNG_ERR_EXCLUSION_INVAL
;
1477 /* Get filter expression from client. */
1478 if (cmd_ctx
->lsm
.u
.enable
.expression_len
> 0) {
1479 size_t expression_len
=
1480 cmd_ctx
->lsm
.u
.enable
.expression_len
;
1482 if (expression_len
> LTTNG_FILTER_MAX_LEN
) {
1483 ret
= LTTNG_ERR_FILTER_INVAL
;
1488 filter_expression
= zmalloc(expression_len
);
1489 if (!filter_expression
) {
1491 ret
= LTTNG_ERR_FILTER_NOMEM
;
1495 /* Receive var. len. data */
1496 DBG("Receiving var len filter's expression from client ...");
1497 ret
= lttcomm_recv_unix_sock(*sock
, filter_expression
,
1500 DBG("Nothing recv() from client var len data... continuing");
1502 free(filter_expression
);
1504 ret
= LTTNG_ERR_FILTER_INVAL
;
1509 /* Handle filter and get bytecode from client. */
1510 if (cmd_ctx
->lsm
.u
.enable
.bytecode_len
> 0) {
1511 size_t bytecode_len
= cmd_ctx
->lsm
.u
.enable
.bytecode_len
;
1513 if (bytecode_len
> LTTNG_FILTER_MAX_LEN
) {
1514 ret
= LTTNG_ERR_FILTER_INVAL
;
1515 free(filter_expression
);
1520 bytecode
= zmalloc(bytecode_len
);
1522 free(filter_expression
);
1524 ret
= LTTNG_ERR_FILTER_NOMEM
;
1528 /* Receive var. len. data */
1529 DBG("Receiving var len filter's bytecode from client ...");
1530 ret
= lttcomm_recv_unix_sock(*sock
, bytecode
, bytecode_len
);
1532 DBG("Nothing recv() from client var len data... continuing");
1534 free(filter_expression
);
1537 ret
= LTTNG_ERR_FILTER_INVAL
;
1541 if ((bytecode
->len
+ sizeof(*bytecode
)) != bytecode_len
) {
1542 free(filter_expression
);
1545 ret
= LTTNG_ERR_FILTER_INVAL
;
1550 ev
= lttng_event_copy(ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.enable
.event
));
1552 DBG("Failed to copy event: %s",
1553 cmd_ctx
->lsm
.u
.enable
.event
.name
);
1554 free(filter_expression
);
1557 ret
= LTTNG_ERR_NOMEM
;
1562 if (cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
> 0) {
1563 /* Expect a userspace probe description. */
1564 ret
= receive_userspace_probe(cmd_ctx
, *sock
, sock_error
, ev
);
1566 free(filter_expression
);
1569 lttng_event_destroy(ev
);
1574 ret
= cmd_enable_event(cmd_ctx
->session
,
1575 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1576 cmd_ctx
->lsm
.u
.enable
.channel_name
,
1578 filter_expression
, bytecode
, exclusion
,
1579 kernel_poll_pipe
[1]);
1580 lttng_event_destroy(ev
);
1583 case LTTNG_LIST_TRACEPOINTS
:
1585 struct lttng_event
*events
;
1588 session_lock_list();
1589 nb_events
= cmd_list_tracepoints(cmd_ctx
->lsm
.domain
.type
, &events
);
1590 session_unlock_list();
1591 if (nb_events
< 0) {
1592 /* Return value is a negative lttng_error_code. */
1598 * Setup lttng message with payload size set to the event list size in
1599 * bytes and then copy list into the llm payload.
1601 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1602 sizeof(struct lttng_event
) * nb_events
);
1612 case LTTNG_LIST_TRACEPOINT_FIELDS
:
1614 struct lttng_event_field
*fields
;
1617 session_lock_list();
1618 nb_fields
= cmd_list_tracepoint_fields(cmd_ctx
->lsm
.domain
.type
,
1620 session_unlock_list();
1621 if (nb_fields
< 0) {
1622 /* Return value is a negative lttng_error_code. */
1628 * Setup lttng message with payload size set to the event list size in
1629 * bytes and then copy list into the llm payload.
1631 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, fields
,
1632 sizeof(struct lttng_event_field
) * nb_fields
);
1642 case LTTNG_LIST_SYSCALLS
:
1644 struct lttng_event
*events
;
1647 nb_events
= cmd_list_syscalls(&events
);
1648 if (nb_events
< 0) {
1649 /* Return value is a negative lttng_error_code. */
1655 * Setup lttng message with payload size set to the event list size in
1656 * bytes and then copy list into the llm payload.
1658 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1659 sizeof(struct lttng_event
) * nb_events
);
1669 case LTTNG_SET_CONSUMER_URI
:
1672 struct lttng_uri
*uris
;
1674 nb_uri
= cmd_ctx
->lsm
.u
.uri
.size
;
1675 len
= nb_uri
* sizeof(struct lttng_uri
);
1678 ret
= LTTNG_ERR_INVALID
;
1682 uris
= zmalloc(len
);
1684 ret
= LTTNG_ERR_FATAL
;
1688 /* Receive variable len data */
1689 DBG("Receiving %zu URI(s) from client ...", nb_uri
);
1690 ret
= lttcomm_recv_unix_sock(*sock
, uris
, len
);
1692 DBG("No URIs received from client... continuing");
1694 ret
= LTTNG_ERR_SESSION_FAIL
;
1699 ret
= cmd_set_consumer_uri(cmd_ctx
->session
, nb_uri
, uris
);
1701 if (ret
!= LTTNG_OK
) {
1708 case LTTNG_START_TRACE
:
1711 * On the first start, if we have a kernel session and we have
1712 * enabled time or size-based rotations, we have to make sure
1713 * the kernel tracer supports it.
1715 if (!cmd_ctx
->session
->has_been_started
&& \
1716 cmd_ctx
->session
->kernel_session
&& \
1717 (cmd_ctx
->session
->rotate_timer_period
|| \
1718 cmd_ctx
->session
->rotate_size
) && \
1719 !check_rotate_compatible()) {
1720 DBG("Kernel tracer version is not compatible with the rotation feature");
1721 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
1724 ret
= cmd_start_trace(cmd_ctx
->session
);
1727 case LTTNG_STOP_TRACE
:
1729 ret
= cmd_stop_trace(cmd_ctx
->session
);
1732 case LTTNG_DESTROY_SESSION
:
1734 ret
= cmd_destroy_session(cmd_ctx
->session
,
1735 notification_thread_handle
,
1739 case LTTNG_LIST_DOMAINS
:
1742 struct lttng_domain
*domains
= NULL
;
1744 nb_dom
= cmd_list_domains(cmd_ctx
->session
, &domains
);
1746 /* Return value is a negative lttng_error_code. */
1751 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, domains
,
1752 nb_dom
* sizeof(struct lttng_domain
));
1762 case LTTNG_LIST_CHANNELS
:
1764 ssize_t payload_size
;
1765 struct lttng_channel
*channels
= NULL
;
1767 payload_size
= cmd_list_channels(cmd_ctx
->lsm
.domain
.type
,
1768 cmd_ctx
->session
, &channels
);
1769 if (payload_size
< 0) {
1770 /* Return value is a negative lttng_error_code. */
1771 ret
= -payload_size
;
1775 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, channels
,
1786 case LTTNG_LIST_EVENTS
:
1789 struct lttcomm_event_command_header cmd_header
= {};
1790 size_t original_payload_size
;
1791 size_t payload_size
;
1793 ret
= setup_empty_lttng_msg(cmd_ctx
);
1795 ret
= LTTNG_ERR_NOMEM
;
1799 original_payload_size
= cmd_ctx
->reply_payload
.buffer
.size
;
1801 /* Extended infos are included at the end of the payload. */
1802 list_ret
= cmd_list_events(cmd_ctx
->lsm
.domain
.type
,
1804 cmd_ctx
->lsm
.u
.list
.channel_name
,
1805 &cmd_ctx
->reply_payload
);
1807 /* Return value is a negative lttng_error_code. */
1812 payload_size
= cmd_ctx
->reply_payload
.buffer
.size
-
1813 sizeof(cmd_header
) - original_payload_size
;
1814 update_lttng_msg(cmd_ctx
, sizeof(cmd_header
), payload_size
);
1819 case LTTNG_LIST_SESSIONS
:
1821 unsigned int nr_sessions
;
1822 void *sessions_payload
;
1825 session_lock_list();
1826 nr_sessions
= lttng_sessions_count(
1827 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1828 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1830 payload_len
= (sizeof(struct lttng_session
) * nr_sessions
) +
1831 (sizeof(struct lttng_session_extended
) * nr_sessions
);
1832 sessions_payload
= zmalloc(payload_len
);
1834 if (!sessions_payload
) {
1835 session_unlock_list();
1840 cmd_list_lttng_sessions(sessions_payload
, nr_sessions
,
1841 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1842 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1843 session_unlock_list();
1845 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, sessions_payload
,
1847 free(sessions_payload
);
1856 case LTTNG_REGISTER_CONSUMER
:
1858 struct consumer_data
*cdata
;
1860 switch (cmd_ctx
->lsm
.domain
.type
) {
1861 case LTTNG_DOMAIN_KERNEL
:
1862 cdata
= &kconsumer_data
;
1865 ret
= LTTNG_ERR_UND
;
1869 ret
= cmd_register_consumer(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1870 cmd_ctx
->lsm
.u
.reg
.path
, cdata
);
1873 case LTTNG_DATA_PENDING
:
1876 uint8_t pending_ret_byte
;
1878 pending_ret
= cmd_data_pending(cmd_ctx
->session
);
1883 * This function may returns 0 or 1 to indicate whether or not
1884 * there is data pending. In case of error, it should return an
1885 * LTTNG_ERR code. However, some code paths may still return
1886 * a nondescript error code, which we handle by returning an
1889 if (pending_ret
== 0 || pending_ret
== 1) {
1891 * ret will be set to LTTNG_OK at the end of
1894 } else if (pending_ret
< 0) {
1895 ret
= LTTNG_ERR_UNK
;
1902 pending_ret_byte
= (uint8_t) pending_ret
;
1904 /* 1 byte to return whether or not data is pending */
1905 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1906 &pending_ret_byte
, 1);
1915 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
1917 uint32_t snapshot_id
;
1918 struct lttcomm_lttng_output_id reply
;
1920 ret
= cmd_snapshot_add_output(cmd_ctx
->session
,
1921 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
),
1923 if (ret
!= LTTNG_OK
) {
1926 reply
.id
= snapshot_id
;
1928 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &reply
,
1934 /* Copy output list into message payload */
1938 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
1940 ret
= cmd_snapshot_del_output(cmd_ctx
->session
,
1941 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
));
1944 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
1947 struct lttng_snapshot_output
*outputs
= NULL
;
1949 nb_output
= cmd_snapshot_list_outputs(cmd_ctx
->session
, &outputs
);
1950 if (nb_output
< 0) {
1955 assert((nb_output
> 0 && outputs
) || nb_output
== 0);
1956 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, outputs
,
1957 nb_output
* sizeof(struct lttng_snapshot_output
));
1967 case LTTNG_SNAPSHOT_RECORD
:
1969 ret
= cmd_snapshot_record(cmd_ctx
->session
,
1970 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_record
.output
),
1971 cmd_ctx
->lsm
.u
.snapshot_record
.wait
);
1974 case LTTNG_CREATE_SESSION_EXT
:
1976 struct lttng_dynamic_buffer payload
;
1977 struct lttng_session_descriptor
*return_descriptor
= NULL
;
1979 lttng_dynamic_buffer_init(&payload
);
1980 ret
= cmd_create_session(cmd_ctx
, *sock
, &return_descriptor
);
1981 if (ret
!= LTTNG_OK
) {
1985 ret
= lttng_session_descriptor_serialize(return_descriptor
,
1988 ERR("Failed to serialize session descriptor in reply to \"create session\" command");
1989 lttng_session_descriptor_destroy(return_descriptor
);
1990 ret
= LTTNG_ERR_NOMEM
;
1993 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, payload
.data
,
1996 lttng_session_descriptor_destroy(return_descriptor
);
1997 ret
= LTTNG_ERR_NOMEM
;
2000 lttng_dynamic_buffer_reset(&payload
);
2001 lttng_session_descriptor_destroy(return_descriptor
);
2005 case LTTNG_SAVE_SESSION
:
2007 ret
= cmd_save_sessions(&cmd_ctx
->lsm
.u
.save_session
.attr
,
2011 case LTTNG_SET_SESSION_SHM_PATH
:
2013 ret
= cmd_set_session_shm_path(cmd_ctx
->session
,
2014 cmd_ctx
->lsm
.u
.set_shm_path
.shm_path
);
2017 case LTTNG_REGENERATE_METADATA
:
2019 ret
= cmd_regenerate_metadata(cmd_ctx
->session
);
2022 case LTTNG_REGENERATE_STATEDUMP
:
2024 ret
= cmd_regenerate_statedump(cmd_ctx
->session
);
2027 case LTTNG_REGISTER_TRIGGER
:
2029 ret
= cmd_register_trigger(cmd_ctx
, *sock
,
2030 notification_thread_handle
);
2033 case LTTNG_UNREGISTER_TRIGGER
:
2035 ret
= cmd_unregister_trigger(cmd_ctx
, *sock
,
2036 notification_thread_handle
);
2039 case LTTNG_ROTATE_SESSION
:
2041 struct lttng_rotate_session_return rotate_return
;
2043 DBG("Client rotate session \"%s\"", cmd_ctx
->session
->name
);
2045 memset(&rotate_return
, 0, sizeof(rotate_return
));
2046 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2047 DBG("Kernel tracer version is not compatible with the rotation feature");
2048 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2052 ret
= cmd_rotate_session(cmd_ctx
->session
, &rotate_return
,
2054 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED
);
2060 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &rotate_return
,
2061 sizeof(rotate_return
));
2070 case LTTNG_ROTATION_GET_INFO
:
2072 struct lttng_rotation_get_info_return get_info_return
;
2074 memset(&get_info_return
, 0, sizeof(get_info_return
));
2075 ret
= cmd_rotate_get_info(cmd_ctx
->session
, &get_info_return
,
2076 cmd_ctx
->lsm
.u
.get_rotation_info
.rotation_id
);
2082 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &get_info_return
,
2083 sizeof(get_info_return
));
2092 case LTTNG_ROTATION_SET_SCHEDULE
:
2095 enum lttng_rotation_schedule_type schedule_type
;
2098 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2099 DBG("Kernel tracer version does not support session rotations");
2100 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2104 set_schedule
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.set
== 1;
2105 schedule_type
= (enum lttng_rotation_schedule_type
) cmd_ctx
->lsm
.u
.rotation_set_schedule
.type
;
2106 value
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.value
;
2108 ret
= cmd_rotation_set_schedule(cmd_ctx
->session
,
2112 notification_thread_handle
);
2113 if (ret
!= LTTNG_OK
) {
2119 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
2121 struct lttng_session_list_schedules_return schedules
= {
2122 .periodic
.set
= !!cmd_ctx
->session
->rotate_timer_period
,
2123 .periodic
.value
= cmd_ctx
->session
->rotate_timer_period
,
2124 .size
.set
= !!cmd_ctx
->session
->rotate_size
,
2125 .size
.value
= cmd_ctx
->session
->rotate_size
,
2128 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &schedules
,
2138 case LTTNG_CLEAR_SESSION
:
2140 ret
= cmd_clear_session(cmd_ctx
->session
, sock
);
2144 ret
= LTTNG_ERR_UND
;
2149 if (cmd_ctx
->reply_payload
.buffer
.size
== 0) {
2150 DBG("Missing llm header, creating one.");
2151 if (setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0) < 0) {
2155 /* Set return code */
2156 ((struct lttcomm_lttng_msg
*) (cmd_ctx
->reply_payload
.buffer
.data
))->ret_code
= ret
;
2158 if (cmd_ctx
->session
) {
2159 session_unlock(cmd_ctx
->session
);
2160 session_put(cmd_ctx
->session
);
2161 cmd_ctx
->session
= NULL
;
2163 if (need_tracing_session
) {
2164 session_unlock_list();
2167 assert(!rcu_read_ongoing());
2171 static int create_client_sock(void)
2173 int ret
, client_sock
;
2174 const mode_t old_umask
= umask(0);
2176 /* Create client tool unix socket */
2177 client_sock
= lttcomm_create_unix_sock(config
.client_unix_sock_path
.value
);
2178 if (client_sock
< 0) {
2179 ERR("Create unix sock failed: %s", config
.client_unix_sock_path
.value
);
2184 /* Set the cloexec flag */
2185 ret
= utils_set_fd_cloexec(client_sock
);
2187 ERR("Unable to set CLOEXEC flag to the client Unix socket (fd: %d). "
2188 "Continuing but note that the consumer daemon will have a "
2189 "reference to this socket on exec()", client_sock
);
2192 /* File permission MUST be 660 */
2193 ret
= chmod(config
.client_unix_sock_path
.value
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
2195 ERR("Set file permissions failed: %s",
2196 config
.client_unix_sock_path
.value
);
2198 (void) lttcomm_close_unix_sock(client_sock
);
2202 DBG("Created client socket (fd = %i)", client_sock
);
2209 static void cleanup_client_thread(void *data
)
2211 struct lttng_pipe
*quit_pipe
= data
;
2213 lttng_pipe_destroy(quit_pipe
);
2216 static void thread_init_cleanup(void *data
)
2218 set_thread_status(false);
2222 * This thread manage all clients request using the unix client socket for
2225 static void *thread_manage_clients(void *data
)
2227 int sock
= -1, ret
, i
, pollfd
, err
= -1;
2229 uint32_t revents
, nb_fd
;
2230 struct lttng_poll_event events
;
2231 const int client_sock
= thread_state
.client_sock
;
2232 struct lttng_pipe
*quit_pipe
= data
;
2233 const int thread_quit_pipe_fd
= lttng_pipe_get_readfd(quit_pipe
);
2234 struct command_ctx cmd_ctx
= {};
2236 DBG("[thread] Manage client started");
2238 lttng_payload_init(&cmd_ctx
.reply_payload
);
2240 is_root
= (getuid() == 0);
2242 pthread_cleanup_push(thread_init_cleanup
, NULL
);
2244 rcu_register_thread();
2246 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_CMD
);
2248 health_code_update();
2250 ret
= lttcomm_listen_unix_sock(client_sock
);
2256 * Pass 2 as size here for the thread quit pipe and client_sock. Nothing
2257 * more will be added to this poll set.
2259 ret
= lttng_poll_create(&events
, 2, LTTNG_CLOEXEC
);
2261 goto error_create_poll
;
2264 /* Add the application registration socket */
2265 ret
= lttng_poll_add(&events
, client_sock
, LPOLLIN
| LPOLLPRI
);
2270 /* Add thread quit pipe */
2271 ret
= lttng_poll_add(&events
, thread_quit_pipe_fd
, LPOLLIN
| LPOLLERR
);
2276 /* Set state as running. */
2277 set_thread_status(true);
2278 pthread_cleanup_pop(0);
2280 /* This testpoint is after we signal readiness to the parent. */
2281 if (testpoint(sessiond_thread_manage_clients
)) {
2285 if (testpoint(sessiond_thread_manage_clients_before_loop
)) {
2289 health_code_update();
2292 const struct cmd_completion_handler
*cmd_completion_handler
;
2294 cmd_ctx
.creds
= (lttng_sock_cred
) {
2298 cmd_ctx
.session
= NULL
;
2299 lttng_payload_clear(&cmd_ctx
.reply_payload
);
2300 cmd_ctx
.lttng_msg_size
= 0;
2302 DBG("Accepting client command ...");
2304 /* Inifinite blocking call, waiting for transmission */
2306 health_poll_entry();
2307 ret
= lttng_poll_wait(&events
, -1);
2311 * Restart interrupted system call.
2313 if (errno
== EINTR
) {
2321 for (i
= 0; i
< nb_fd
; i
++) {
2322 revents
= LTTNG_POLL_GETEV(&events
, i
);
2323 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2325 health_code_update();
2327 if (pollfd
== thread_quit_pipe_fd
) {
2331 /* Event on the registration socket */
2332 if (revents
& LPOLLIN
) {
2334 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2335 ERR("Client socket poll error");
2338 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2344 DBG("Wait for client response");
2346 health_code_update();
2348 sock
= lttcomm_accept_unix_sock(client_sock
);
2354 * Set the CLOEXEC flag. Return code is useless because either way, the
2357 (void) utils_set_fd_cloexec(sock
);
2359 /* Set socket option for credentials retrieval */
2360 ret
= lttcomm_setsockopt_creds_unix_sock(sock
);
2365 health_code_update();
2368 * Data is received from the lttng client. The struct
2369 * lttcomm_session_msg (lsm) contains the command and data request of
2372 DBG("Receiving data from client ...");
2373 ret
= lttcomm_recv_creds_unix_sock(sock
, &cmd_ctx
.lsm
,
2374 sizeof(struct lttcomm_session_msg
), &cmd_ctx
.creds
);
2375 if (ret
!= sizeof(struct lttcomm_session_msg
)) {
2376 DBG("Incomplete recv() from client... continuing");
2385 health_code_update();
2387 // TODO: Validate cmd_ctx including sanity check for
2388 // security purpose.
2390 rcu_thread_online();
2392 * This function dispatch the work to the kernel or userspace tracer
2393 * libs and fill the lttcomm_lttng_msg data structure of all the needed
2394 * informations for the client. The command context struct contains
2395 * everything this function may needs.
2397 ret
= process_client_msg(&cmd_ctx
, &sock
, &sock_error
);
2398 rcu_thread_offline();
2408 * TODO: Inform client somehow of the fatal error. At
2409 * this point, ret < 0 means that a zmalloc failed
2410 * (ENOMEM). Error detected but still accept
2411 * command, unless a socket error has been
2417 cmd_completion_handler
= cmd_pop_completion_handler();
2418 if (cmd_completion_handler
) {
2419 enum lttng_error_code completion_code
;
2421 completion_code
= cmd_completion_handler
->run(
2422 cmd_completion_handler
->data
);
2423 if (completion_code
!= LTTNG_OK
) {
2428 health_code_update();
2431 struct lttng_payload_view view
=
2432 lttng_payload_view_from_payload(
2433 &cmd_ctx
.reply_payload
,
2435 struct lttcomm_lttng_msg
*llm
= (typeof(
2436 llm
)) cmd_ctx
.reply_payload
.buffer
.data
;
2438 assert(cmd_ctx
.reply_payload
.buffer
.size
>=
2440 assert(cmd_ctx
.lttng_msg_size
== cmd_ctx
.reply_payload
.buffer
.size
);
2442 llm
->fd_count
= lttng_payload_view_get_fd_handle_count(&view
);
2444 DBG("Sending response (size: %d, retcode: %s (%d))",
2445 cmd_ctx
.lttng_msg_size
,
2446 lttng_strerror(-llm
->ret_code
),
2448 ret
= send_unix_sock(sock
, &view
);
2450 ERR("Failed to send data back to client");
2453 /* End of transmission */
2461 health_code_update();
2473 lttng_poll_clean(&events
);
2477 unlink(config
.client_unix_sock_path
.value
);
2478 ret
= close(client_sock
);
2485 ERR("Health error occurred in %s", __func__
);
2488 health_unregister(health_sessiond
);
2490 DBG("Client thread dying");
2491 lttng_payload_reset(&cmd_ctx
.reply_payload
);
2492 rcu_unregister_thread();
2497 bool shutdown_client_thread(void *thread_data
)
2499 struct lttng_pipe
*client_quit_pipe
= thread_data
;
2500 const int write_fd
= lttng_pipe_get_writefd(client_quit_pipe
);
2502 return notify_thread_pipe(write_fd
) == 1;
2505 struct lttng_thread
*launch_client_thread(void)
2507 bool thread_running
;
2508 struct lttng_pipe
*client_quit_pipe
;
2509 struct lttng_thread
*thread
= NULL
;
2510 int client_sock_fd
= -1;
2512 sem_init(&thread_state
.ready
, 0, 0);
2513 client_quit_pipe
= lttng_pipe_open(FD_CLOEXEC
);
2514 if (!client_quit_pipe
) {
2518 client_sock_fd
= create_client_sock();
2519 if (client_sock_fd
< 0) {
2523 thread_state
.client_sock
= client_sock_fd
;
2524 thread
= lttng_thread_create("Client management",
2525 thread_manage_clients
,
2526 shutdown_client_thread
,
2527 cleanup_client_thread
,
2532 /* The client thread now owns the client sock fd and the quit pipe. */
2533 client_sock_fd
= -1;
2534 client_quit_pipe
= NULL
;
2537 * This thread is part of the threads that need to be fully
2538 * initialized before the session daemon is marked as "ready".
2540 thread_running
= wait_thread_status();
2541 if (!thread_running
) {
2546 if (client_sock_fd
>= 0) {
2547 if (close(client_sock_fd
)) {
2548 PERROR("Failed to close client socket");
2551 lttng_thread_put(thread
);
2552 cleanup_client_thread(client_quit_pipe
);