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 ret
= lttng_dynamic_buffer_set_size(&cmd_ctx
->reply_payload
.buffer
, 0);
141 /* Append place-holder reply header. */
142 ret
= lttng_dynamic_buffer_append(
143 &cmd_ctx
->reply_payload
.buffer
, &llm
, sizeof(llm
));
148 cmd_ctx
->lttng_msg_size
= sizeof(llm
);
153 static void update_lttng_msg(struct command_ctx
*cmd_ctx
, size_t cmd_header_len
,
156 const size_t header_len
= sizeof(struct lttcomm_lttng_msg
);
157 const size_t total_msg_size
= header_len
+ cmd_header_len
+ payload_len
;
158 const struct lttcomm_lttng_msg llm
= {
159 .cmd_type
= cmd_ctx
->lsm
.cmd_type
,
160 .pid
= cmd_ctx
->lsm
.domain
.attr
.pid
,
161 .cmd_header_size
= cmd_header_len
,
162 .data_size
= payload_len
,
164 struct lttcomm_lttng_msg
*p_llm
;
166 assert(cmd_ctx
->reply_payload
.buffer
.size
>= sizeof(llm
));
168 p_llm
= (typeof(p_llm
)) cmd_ctx
->reply_payload
.buffer
.data
;
170 /* Update existing header. */
171 memcpy(p_llm
, &llm
, sizeof(llm
));
173 cmd_ctx
->lttng_msg_size
= total_msg_size
;
177 * Start the thread_manage_consumer. This must be done after a lttng-consumerd
178 * exec or it will fail.
180 static int spawn_consumer_thread(struct consumer_data
*consumer_data
)
182 return launch_consumer_management_thread(consumer_data
) ? 0 : -1;
186 * Fork and exec a consumer daemon (consumerd).
188 * Return pid if successful else -1.
190 static pid_t
spawn_consumerd(struct consumer_data
*consumer_data
)
194 const char *consumer_to_use
;
195 const char *verbosity
;
198 DBG("Spawning consumerd");
205 if (config
.verbose_consumer
) {
206 verbosity
= "--verbose";
207 } else if (lttng_opt_quiet
) {
208 verbosity
= "--quiet";
213 switch (consumer_data
->type
) {
214 case LTTNG_CONSUMER_KERNEL
:
216 * Find out which consumerd to execute. We will first try the
217 * 64-bit path, then the sessiond's installation directory, and
218 * fallback on the 32-bit one,
220 DBG3("Looking for a kernel consumer at these locations:");
221 DBG3(" 1) %s", config
.consumerd64_bin_path
.value
? : "NULL");
222 DBG3(" 2) %s/%s", INSTALL_BIN_PATH
, DEFAULT_CONSUMERD_FILE
);
223 DBG3(" 3) %s", config
.consumerd32_bin_path
.value
? : "NULL");
224 if (stat(config
.consumerd64_bin_path
.value
, &st
) == 0) {
225 DBG3("Found location #1");
226 consumer_to_use
= config
.consumerd64_bin_path
.value
;
227 } else if (stat(INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
, &st
) == 0) {
228 DBG3("Found location #2");
229 consumer_to_use
= INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
;
230 } else if (config
.consumerd32_bin_path
.value
&&
231 stat(config
.consumerd32_bin_path
.value
, &st
) == 0) {
232 DBG3("Found location #3");
233 consumer_to_use
= config
.consumerd32_bin_path
.value
;
235 DBG("Could not find any valid consumerd executable");
239 DBG("Using kernel consumer at: %s", consumer_to_use
);
240 (void) execl(consumer_to_use
,
241 "lttng-consumerd", verbosity
, "-k",
242 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
243 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
244 "--group", config
.tracing_group_name
.value
,
247 case LTTNG_CONSUMER64_UST
:
249 if (config
.consumerd64_lib_dir
.value
) {
254 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
258 tmplen
= strlen(config
.consumerd64_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
259 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
264 strcat(tmpnew
, config
.consumerd64_lib_dir
.value
);
265 if (tmp
[0] != '\0') {
269 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
276 DBG("Using 64-bit UST consumer at: %s", config
.consumerd64_bin_path
.value
);
277 (void) execl(config
.consumerd64_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
278 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
279 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
280 "--group", config
.tracing_group_name
.value
,
284 case LTTNG_CONSUMER32_UST
:
286 if (config
.consumerd32_lib_dir
.value
) {
291 tmp
= lttng_secure_getenv("LD_LIBRARY_PATH");
295 tmplen
= strlen(config
.consumerd32_lib_dir
.value
) + 1 /* : */ + strlen(tmp
);
296 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
301 strcat(tmpnew
, config
.consumerd32_lib_dir
.value
);
302 if (tmp
[0] != '\0') {
306 ret
= setenv("LD_LIBRARY_PATH", tmpnew
, 1);
313 DBG("Using 32-bit UST consumer at: %s", config
.consumerd32_bin_path
.value
);
314 (void) execl(config
.consumerd32_bin_path
.value
, "lttng-consumerd", verbosity
, "-u",
315 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
316 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
317 "--group", config
.tracing_group_name
.value
,
322 ERR("unknown consumer type");
326 PERROR("Consumer execl()");
328 /* Reaching this point, we got a failure on our execl(). */
330 } else if (pid
> 0) {
333 PERROR("start consumer fork");
341 * Spawn the consumerd daemon and session daemon thread.
343 static int start_consumerd(struct consumer_data
*consumer_data
)
348 * Set the listen() state on the socket since there is a possible race
349 * between the exec() of the consumer daemon and this call if place in the
350 * consumer thread. See bug #366 for more details.
352 ret
= lttcomm_listen_unix_sock(consumer_data
->err_sock
);
357 pthread_mutex_lock(&consumer_data
->pid_mutex
);
358 if (consumer_data
->pid
!= 0) {
359 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
363 ret
= spawn_consumerd(consumer_data
);
365 ERR("Spawning consumerd failed");
366 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
370 /* Setting up the consumer_data pid */
371 consumer_data
->pid
= ret
;
372 DBG2("Consumer pid %d", consumer_data
->pid
);
373 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
375 DBG2("Spawning consumer control thread");
376 ret
= spawn_consumer_thread(consumer_data
);
378 ERR("Fatal error spawning consumer control thread");
386 /* Cleanup already created sockets on error. */
387 if (consumer_data
->err_sock
>= 0) {
390 err
= close(consumer_data
->err_sock
);
392 PERROR("close consumer data error socket");
399 * Copy consumer output from the tracing session to the domain session. The
400 * function also applies the right modification on a per domain basis for the
401 * trace files destination directory.
403 * Should *NOT* be called with RCU read-side lock held.
405 static int copy_session_consumer(int domain
, struct ltt_session
*session
)
408 const char *dir_name
;
409 struct consumer_output
*consumer
;
412 assert(session
->consumer
);
415 case LTTNG_DOMAIN_KERNEL
:
416 DBG3("Copying tracing session consumer output in kernel session");
418 * XXX: We should audit the session creation and what this function
419 * does "extra" in order to avoid a destroy since this function is used
420 * in the domain session creation (kernel and ust) only. Same for UST
423 if (session
->kernel_session
->consumer
) {
424 consumer_output_put(session
->kernel_session
->consumer
);
426 session
->kernel_session
->consumer
=
427 consumer_copy_output(session
->consumer
);
428 /* Ease our life a bit for the next part */
429 consumer
= session
->kernel_session
->consumer
;
430 dir_name
= DEFAULT_KERNEL_TRACE_DIR
;
432 case LTTNG_DOMAIN_JUL
:
433 case LTTNG_DOMAIN_LOG4J
:
434 case LTTNG_DOMAIN_PYTHON
:
435 case LTTNG_DOMAIN_UST
:
436 DBG3("Copying tracing session consumer output in UST session");
437 if (session
->ust_session
->consumer
) {
438 consumer_output_put(session
->ust_session
->consumer
);
440 session
->ust_session
->consumer
=
441 consumer_copy_output(session
->consumer
);
442 /* Ease our life a bit for the next part */
443 consumer
= session
->ust_session
->consumer
;
444 dir_name
= DEFAULT_UST_TRACE_DIR
;
447 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
451 /* Append correct directory to subdir */
452 ret
= lttng_strncpy(consumer
->domain_subdir
, dir_name
,
453 sizeof(consumer
->domain_subdir
));
458 DBG3("Copy session consumer subdir %s", consumer
->domain_subdir
);
466 * Create an UST session and add it to the session ust list.
468 * Should *NOT* be called with RCU read-side lock held.
470 static int create_ust_session(struct ltt_session
*session
,
471 const struct lttng_domain
*domain
)
474 struct ltt_ust_session
*lus
= NULL
;
478 assert(session
->consumer
);
480 switch (domain
->type
) {
481 case LTTNG_DOMAIN_JUL
:
482 case LTTNG_DOMAIN_LOG4J
:
483 case LTTNG_DOMAIN_PYTHON
:
484 case LTTNG_DOMAIN_UST
:
487 ERR("Unknown UST domain on create session %d", domain
->type
);
488 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
492 DBG("Creating UST session");
494 lus
= trace_ust_create_session(session
->id
);
496 ret
= LTTNG_ERR_UST_SESS_FAIL
;
500 lus
->uid
= session
->uid
;
501 lus
->gid
= session
->gid
;
502 lus
->output_traces
= session
->output_traces
;
503 lus
->snapshot_mode
= session
->snapshot_mode
;
504 lus
->live_timer_interval
= session
->live_timer
;
505 session
->ust_session
= lus
;
506 if (session
->shm_path
[0]) {
507 strncpy(lus
->root_shm_path
, session
->shm_path
,
508 sizeof(lus
->root_shm_path
));
509 lus
->root_shm_path
[sizeof(lus
->root_shm_path
) - 1] = '\0';
510 strncpy(lus
->shm_path
, session
->shm_path
,
511 sizeof(lus
->shm_path
));
512 lus
->shm_path
[sizeof(lus
->shm_path
) - 1] = '\0';
513 strncat(lus
->shm_path
, "/ust",
514 sizeof(lus
->shm_path
) - strlen(lus
->shm_path
) - 1);
516 /* Copy session output to the newly created UST session */
517 ret
= copy_session_consumer(domain
->type
, session
);
518 if (ret
!= LTTNG_OK
) {
526 session
->ust_session
= NULL
;
531 * Create a kernel tracer session then create the default channel.
533 static int create_kernel_session(struct ltt_session
*session
)
537 DBG("Creating kernel session");
539 ret
= kernel_create_session(session
);
541 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
545 /* Code flow safety */
546 assert(session
->kernel_session
);
548 /* Copy session output to the newly created Kernel session */
549 ret
= copy_session_consumer(LTTNG_DOMAIN_KERNEL
, session
);
550 if (ret
!= LTTNG_OK
) {
554 session
->kernel_session
->uid
= session
->uid
;
555 session
->kernel_session
->gid
= session
->gid
;
556 session
->kernel_session
->output_traces
= session
->output_traces
;
557 session
->kernel_session
->snapshot_mode
= session
->snapshot_mode
;
558 session
->kernel_session
->is_live_session
= session
->live_timer
!= 0;
563 trace_kernel_destroy_session(session
->kernel_session
);
564 session
->kernel_session
= NULL
;
570 * Count number of session permitted by uid/gid.
572 static unsigned int lttng_sessions_count(uid_t uid
, gid_t gid
)
575 struct ltt_session
*session
;
576 const struct ltt_session_list
*session_list
= session_get_list();
578 DBG("Counting number of available session for UID %d GID %d",
580 cds_list_for_each_entry(session
, &session_list
->head
, list
) {
581 if (!session_get(session
)) {
584 session_lock(session
);
585 /* Only count the sessions the user can control. */
586 if (session_access_ok(session
, uid
, gid
) &&
587 !session
->destroyed
) {
590 session_unlock(session
);
591 session_put(session
);
596 static int receive_userspace_probe(struct command_ctx
*cmd_ctx
, int sock
,
597 int *sock_error
, struct lttng_event
*event
)
600 struct lttng_userspace_probe_location
*probe_location
;
601 struct lttng_payload probe_location_payload
;
602 struct fd_handle
*handle
= NULL
;
605 * Create a payload to store the serialized version of the probe
608 lttng_payload_init(&probe_location_payload
);
610 ret
= lttng_dynamic_buffer_set_size(&probe_location_payload
.buffer
,
611 cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
);
613 ret
= LTTNG_ERR_NOMEM
;
618 * Receive the probe location.
620 ret
= lttcomm_recv_unix_sock(sock
, probe_location_payload
.buffer
.data
,
621 probe_location_payload
.buffer
.size
);
623 DBG("Nothing recv() from client var len data... continuing");
625 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
630 * Receive the file descriptor to the target binary from the client.
632 DBG("Receiving userspace probe target FD from client ...");
633 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
635 DBG("Nothing recv() from client userspace probe fd... continuing");
637 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
641 handle
= fd_handle_create(fd
);
643 ret
= LTTNG_ERR_NOMEM
;
647 /* Transferred to the handle. */
650 ret
= lttng_payload_push_fd_handle(&probe_location_payload
, handle
);
652 ERR("Failed to add userspace probe file descriptor to payload");
653 ret
= LTTNG_ERR_NOMEM
;
657 fd_handle_put(handle
);
661 struct lttng_payload_view view
= lttng_payload_view_from_payload(
662 &probe_location_payload
, 0, -1);
664 /* Extract the probe location from the serialized version. */
665 ret
= lttng_userspace_probe_location_create_from_payload(
666 &view
, &probe_location
);
669 WARN("Failed to create a userspace probe location from the received buffer");
670 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
674 /* Attach the probe location to the event. */
675 ret
= lttng_event_set_userspace_probe_location(event
, probe_location
);
677 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
684 PERROR("Failed to close userspace probe location binary fd");
688 fd_handle_put(handle
);
689 lttng_payload_reset(&probe_location_payload
);
694 * Version of setup_lttng_msg() without command header.
696 static int setup_lttng_msg_no_cmd_header(struct command_ctx
*cmd_ctx
,
697 void *payload_buf
, size_t payload_len
)
699 return setup_lttng_msg(cmd_ctx
, payload_buf
, payload_len
, NULL
, 0);
703 * Check if the current kernel tracer supports the session rotation feature.
704 * Return 1 if it does, 0 otherwise.
706 static int check_rotate_compatible(void)
710 if (kernel_tracer_version
.major
!= 2 || kernel_tracer_version
.minor
< 11) {
711 DBG("Kernel tracer version is not compatible with the rotation feature");
719 * Send data on a unix socket using the liblttsessiondcomm API.
721 * Return lttcomm error code.
723 static int send_unix_sock(int sock
, struct lttng_payload_view
*view
)
726 const int fd_count
= lttng_payload_view_get_fd_handle_count(view
);
728 /* Check valid length */
729 if (view
->buffer
.size
== 0) {
734 ret
= lttcomm_send_unix_sock(
735 sock
, view
->buffer
.data
, view
->buffer
.size
);
741 ret
= lttcomm_send_payload_view_fds_unix_sock(sock
, view
);
752 * Process the command requested by the lttng client within the command
753 * context structure. This function make sure that the return structure (llm)
754 * is set and ready for transmission before returning.
756 * Return any error encountered or 0 for success.
758 * "sock" is only used for special-case var. len data.
759 * A command may assume the ownership of the socket, in which case its value
760 * should be set to -1.
762 * Should *NOT* be called with RCU read-side lock held.
764 static int process_client_msg(struct command_ctx
*cmd_ctx
, int *sock
,
768 int need_tracing_session
= 1;
771 DBG("Processing client command %d", cmd_ctx
->lsm
.cmd_type
);
773 assert(!rcu_read_ongoing());
777 switch (cmd_ctx
->lsm
.cmd_type
) {
778 case LTTNG_CREATE_SESSION_EXT
:
779 case LTTNG_DESTROY_SESSION
:
780 case LTTNG_LIST_SESSIONS
:
781 case LTTNG_LIST_DOMAINS
:
782 case LTTNG_START_TRACE
:
783 case LTTNG_STOP_TRACE
:
784 case LTTNG_DATA_PENDING
:
785 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
786 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
787 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
788 case LTTNG_SNAPSHOT_RECORD
:
789 case LTTNG_SAVE_SESSION
:
790 case LTTNG_SET_SESSION_SHM_PATH
:
791 case LTTNG_REGENERATE_METADATA
:
792 case LTTNG_REGENERATE_STATEDUMP
:
793 case LTTNG_REGISTER_TRIGGER
:
794 case LTTNG_UNREGISTER_TRIGGER
:
795 case LTTNG_ROTATE_SESSION
:
796 case LTTNG_ROTATION_GET_INFO
:
797 case LTTNG_ROTATION_SET_SCHEDULE
:
798 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
799 case LTTNG_CLEAR_SESSION
:
806 if (config
.no_kernel
&& need_domain
807 && cmd_ctx
->lsm
.domain
.type
== LTTNG_DOMAIN_KERNEL
) {
809 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
811 ret
= LTTNG_ERR_KERN_NA
;
816 /* Deny register consumer if we already have a spawned consumer. */
817 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_REGISTER_CONSUMER
) {
818 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
819 if (kconsumer_data
.pid
> 0) {
820 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
821 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
824 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
828 * Check for command that don't needs to allocate a returned payload. We do
829 * this here so we don't have to make the call for no payload at each
832 switch(cmd_ctx
->lsm
.cmd_type
) {
833 case LTTNG_LIST_SESSIONS
:
834 case LTTNG_LIST_TRACEPOINTS
:
835 case LTTNG_LIST_TRACEPOINT_FIELDS
:
836 case LTTNG_LIST_DOMAINS
:
837 case LTTNG_LIST_CHANNELS
:
838 case LTTNG_LIST_EVENTS
:
839 case LTTNG_LIST_SYSCALLS
:
840 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
841 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
842 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
843 case LTTNG_DATA_PENDING
:
844 case LTTNG_ROTATE_SESSION
:
845 case LTTNG_ROTATION_GET_INFO
:
848 /* Setup lttng message with no payload */
849 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0);
851 /* This label does not try to unlock the session */
852 goto init_setup_error
;
856 /* Commands that DO NOT need a session. */
857 switch (cmd_ctx
->lsm
.cmd_type
) {
858 case LTTNG_CREATE_SESSION_EXT
:
859 case LTTNG_LIST_SESSIONS
:
860 case LTTNG_LIST_TRACEPOINTS
:
861 case LTTNG_LIST_SYSCALLS
:
862 case LTTNG_LIST_TRACEPOINT_FIELDS
:
863 case LTTNG_SAVE_SESSION
:
864 case LTTNG_REGISTER_TRIGGER
:
865 case LTTNG_UNREGISTER_TRIGGER
:
866 need_tracing_session
= 0;
869 DBG("Getting session %s by name", cmd_ctx
->lsm
.session
.name
);
871 * We keep the session list lock across _all_ commands
872 * for now, because the per-session lock does not
873 * handle teardown properly.
876 cmd_ctx
->session
= session_find_by_name(cmd_ctx
->lsm
.session
.name
);
877 if (cmd_ctx
->session
== NULL
) {
878 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
881 /* Acquire lock for the session */
882 session_lock(cmd_ctx
->session
);
888 * Commands that need a valid session but should NOT create one if none
889 * exists. Instead of creating one and destroying it when the command is
890 * handled, process that right before so we save some round trip in useless
893 switch (cmd_ctx
->lsm
.cmd_type
) {
894 case LTTNG_DISABLE_CHANNEL
:
895 case LTTNG_DISABLE_EVENT
:
896 switch (cmd_ctx
->lsm
.domain
.type
) {
897 case LTTNG_DOMAIN_KERNEL
:
898 if (!cmd_ctx
->session
->kernel_session
) {
899 ret
= LTTNG_ERR_NO_CHANNEL
;
903 case LTTNG_DOMAIN_JUL
:
904 case LTTNG_DOMAIN_LOG4J
:
905 case LTTNG_DOMAIN_PYTHON
:
906 case LTTNG_DOMAIN_UST
:
907 if (!cmd_ctx
->session
->ust_session
) {
908 ret
= LTTNG_ERR_NO_CHANNEL
;
913 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
925 * Check domain type for specific "pre-action".
927 switch (cmd_ctx
->lsm
.domain
.type
) {
928 case LTTNG_DOMAIN_KERNEL
:
930 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
934 /* Kernel tracer check */
935 if (!kernel_tracer_is_initialized()) {
936 /* Basically, load kernel tracer modules */
937 ret
= init_kernel_tracer();
943 /* Consumer is in an ERROR state. Report back to client */
944 if (uatomic_read(&kernel_consumerd_state
) == CONSUMER_ERROR
) {
945 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
949 /* Need a session for kernel command */
950 if (need_tracing_session
) {
951 if (cmd_ctx
->session
->kernel_session
== NULL
) {
952 ret
= create_kernel_session(cmd_ctx
->session
);
953 if (ret
!= LTTNG_OK
) {
954 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
959 /* Start the kernel consumer daemon */
960 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
961 if (kconsumer_data
.pid
== 0 &&
962 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
963 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
964 ret
= start_consumerd(&kconsumer_data
);
966 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
969 uatomic_set(&kernel_consumerd_state
, CONSUMER_STARTED
);
971 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
975 * The consumer was just spawned so we need to add the socket to
976 * the consumer output of the session if exist.
978 ret
= consumer_create_socket(&kconsumer_data
,
979 cmd_ctx
->session
->kernel_session
->consumer
);
986 case LTTNG_DOMAIN_JUL
:
987 case LTTNG_DOMAIN_LOG4J
:
988 case LTTNG_DOMAIN_PYTHON
:
989 case LTTNG_DOMAIN_UST
:
991 if (!ust_app_supported()) {
992 ret
= LTTNG_ERR_NO_UST
;
995 /* Consumer is in an ERROR state. Report back to client */
996 if (uatomic_read(&ust_consumerd_state
) == CONSUMER_ERROR
) {
997 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1001 if (need_tracing_session
) {
1002 /* Create UST session if none exist. */
1003 if (cmd_ctx
->session
->ust_session
== NULL
) {
1004 ret
= create_ust_session(cmd_ctx
->session
,
1005 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
));
1006 if (ret
!= LTTNG_OK
) {
1011 /* Start the UST consumer daemons */
1013 pthread_mutex_lock(&ustconsumer64_data
.pid_mutex
);
1014 if (config
.consumerd64_bin_path
.value
&&
1015 ustconsumer64_data
.pid
== 0 &&
1016 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1017 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1018 ret
= start_consumerd(&ustconsumer64_data
);
1020 ret
= LTTNG_ERR_UST_CONSUMER64_FAIL
;
1021 uatomic_set(&ust_consumerd64_fd
, -EINVAL
);
1025 uatomic_set(&ust_consumerd64_fd
, ustconsumer64_data
.cmd_sock
);
1026 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1028 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1032 * Setup socket for consumer 64 bit. No need for atomic access
1033 * since it was set above and can ONLY be set in this thread.
1035 ret
= consumer_create_socket(&ustconsumer64_data
,
1036 cmd_ctx
->session
->ust_session
->consumer
);
1042 pthread_mutex_lock(&ustconsumer32_data
.pid_mutex
);
1043 if (config
.consumerd32_bin_path
.value
&&
1044 ustconsumer32_data
.pid
== 0 &&
1045 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1046 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1047 ret
= start_consumerd(&ustconsumer32_data
);
1049 ret
= LTTNG_ERR_UST_CONSUMER32_FAIL
;
1050 uatomic_set(&ust_consumerd32_fd
, -EINVAL
);
1054 uatomic_set(&ust_consumerd32_fd
, ustconsumer32_data
.cmd_sock
);
1055 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1057 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1061 * Setup socket for consumer 32 bit. No need for atomic access
1062 * since it was set above and can ONLY be set in this thread.
1064 ret
= consumer_create_socket(&ustconsumer32_data
,
1065 cmd_ctx
->session
->ust_session
->consumer
);
1077 /* Validate consumer daemon state when start/stop trace command */
1078 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_START_TRACE
||
1079 cmd_ctx
->lsm
.cmd_type
== LTTNG_STOP_TRACE
) {
1080 switch (cmd_ctx
->lsm
.domain
.type
) {
1081 case LTTNG_DOMAIN_NONE
:
1083 case LTTNG_DOMAIN_JUL
:
1084 case LTTNG_DOMAIN_LOG4J
:
1085 case LTTNG_DOMAIN_PYTHON
:
1086 case LTTNG_DOMAIN_UST
:
1087 if (uatomic_read(&ust_consumerd_state
) != CONSUMER_STARTED
) {
1088 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1092 case LTTNG_DOMAIN_KERNEL
:
1093 if (uatomic_read(&kernel_consumerd_state
) != CONSUMER_STARTED
) {
1094 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
1099 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1105 * Check that the UID or GID match that of the tracing session.
1106 * The root user can interact with all sessions.
1108 if (need_tracing_session
) {
1109 if (!session_access_ok(cmd_ctx
->session
,
1110 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1111 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
)) ||
1112 cmd_ctx
->session
->destroyed
) {
1113 ret
= LTTNG_ERR_EPERM
;
1119 * Send relayd information to consumer as soon as we have a domain and a
1122 if (cmd_ctx
->session
&& need_domain
) {
1124 * Setup relayd if not done yet. If the relayd information was already
1125 * sent to the consumer, this call will gracefully return.
1127 ret
= cmd_setup_relayd(cmd_ctx
->session
);
1128 if (ret
!= LTTNG_OK
) {
1133 /* Process by command type */
1134 switch (cmd_ctx
->lsm
.cmd_type
) {
1135 case LTTNG_ADD_CONTEXT
:
1138 * An LTTNG_ADD_CONTEXT command might have a supplementary
1139 * payload if the context being added is an application context.
1141 if (cmd_ctx
->lsm
.u
.context
.ctx
.ctx
==
1142 LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1143 char *provider_name
= NULL
, *context_name
= NULL
;
1144 size_t provider_name_len
=
1145 cmd_ctx
->lsm
.u
.context
.provider_name_len
;
1146 size_t context_name_len
=
1147 cmd_ctx
->lsm
.u
.context
.context_name_len
;
1149 if (provider_name_len
== 0 || context_name_len
== 0) {
1151 * Application provider and context names MUST
1154 ret
= -LTTNG_ERR_INVALID
;
1158 provider_name
= zmalloc(provider_name_len
+ 1);
1159 if (!provider_name
) {
1160 ret
= -LTTNG_ERR_NOMEM
;
1163 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
=
1166 context_name
= zmalloc(context_name_len
+ 1);
1167 if (!context_name
) {
1168 ret
= -LTTNG_ERR_NOMEM
;
1169 goto error_add_context
;
1171 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
=
1174 ret
= lttcomm_recv_unix_sock(*sock
, provider_name
,
1177 goto error_add_context
;
1180 ret
= lttcomm_recv_unix_sock(*sock
, context_name
,
1183 goto error_add_context
;
1188 * cmd_add_context assumes ownership of the provider and context
1191 ret
= cmd_add_context(cmd_ctx
->session
,
1192 cmd_ctx
->lsm
.domain
.type
,
1193 cmd_ctx
->lsm
.u
.context
.channel_name
,
1194 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.context
.ctx
),
1195 kernel_poll_pipe
[1]);
1197 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
1198 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
1200 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
);
1201 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
);
1207 case LTTNG_DISABLE_CHANNEL
:
1209 ret
= cmd_disable_channel(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1210 cmd_ctx
->lsm
.u
.disable
.channel_name
);
1213 case LTTNG_DISABLE_EVENT
:
1217 * FIXME: handle filter; for now we just receive the filter's
1218 * bytecode along with the filter expression which are sent by
1219 * liblttng-ctl and discard them.
1221 * This fixes an issue where the client may block while sending
1222 * the filter payload and encounter an error because the session
1223 * daemon closes the socket without ever handling this data.
1225 size_t count
= cmd_ctx
->lsm
.u
.disable
.expression_len
+
1226 cmd_ctx
->lsm
.u
.disable
.bytecode_len
;
1229 char data
[LTTNG_FILTER_MAX_LEN
];
1231 DBG("Discarding disable event command payload of size %zu", count
);
1233 ret
= lttcomm_recv_unix_sock(*sock
, data
,
1234 count
> sizeof(data
) ? sizeof(data
) : count
);
1239 count
-= (size_t) ret
;
1242 ret
= cmd_disable_event(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1243 cmd_ctx
->lsm
.u
.disable
.channel_name
,
1244 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.disable
.event
));
1247 case LTTNG_ENABLE_CHANNEL
:
1249 cmd_ctx
->lsm
.u
.channel
.chan
.attr
.extended
.ptr
=
1250 (struct lttng_channel_extended
*) &cmd_ctx
->lsm
.u
.channel
.extended
;
1251 ret
= cmd_enable_channel(cmd_ctx
->session
,
1252 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1253 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.channel
.chan
),
1254 kernel_poll_pipe
[1]);
1257 case LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
:
1258 case LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE
:
1260 struct lttng_dynamic_buffer payload
;
1261 struct lttng_buffer_view payload_view
;
1262 const bool add_value
=
1263 cmd_ctx
->lsm
.cmd_type
==
1264 LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
;
1265 const size_t name_len
=
1266 cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1268 const enum lttng_domain_type domain_type
=
1269 (enum lttng_domain_type
)
1270 cmd_ctx
->lsm
.domain
.type
;
1271 const enum lttng_process_attr process_attr
=
1272 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1273 .process_attr_tracker_add_remove_include_value
1275 const enum lttng_process_attr_value_type value_type
=
1276 (enum lttng_process_attr_value_type
) cmd_ctx
1278 .process_attr_tracker_add_remove_include_value
1280 struct process_attr_value
*value
;
1281 enum lttng_error_code ret_code
;
1283 /* Receive remaining variable length payload if applicable. */
1284 if (name_len
> LOGIN_NAME_MAX
) {
1286 * POSIX mandates user and group names that are at least
1287 * 8 characters long. Note that although shadow-utils
1288 * (useradd, groupaadd, etc.) use 32 chars as their
1289 * limit (from bits/utmp.h, UT_NAMESIZE),
1290 * LOGIN_NAME_MAX is defined to 256.
1292 ERR("Rejecting process attribute tracker value %s as the provided exceeds the maximal allowed length: argument length = %zu, maximal length = %d",
1293 add_value
? "addition" : "removal",
1294 name_len
, LOGIN_NAME_MAX
);
1295 ret
= LTTNG_ERR_INVALID
;
1299 lttng_dynamic_buffer_init(&payload
);
1300 if (name_len
!= 0) {
1302 * Receive variable payload for user/group name
1305 ret
= lttng_dynamic_buffer_set_size(&payload
, name_len
);
1307 ERR("Failed to allocate buffer to receive payload of %s process attribute tracker value argument",
1308 add_value
? "add" : "remove");
1309 ret
= LTTNG_ERR_NOMEM
;
1310 goto error_add_remove_tracker_value
;
1313 ret
= lttcomm_recv_unix_sock(
1314 *sock
, payload
.data
, name_len
);
1316 ERR("Failed to receive payload of %s process attribute tracker value argument",
1317 add_value
? "add" : "remove");
1319 ret
= LTTNG_ERR_INVALID_PROTOCOL
;
1320 goto error_add_remove_tracker_value
;
1324 payload_view
= lttng_buffer_view_from_dynamic_buffer(
1325 &payload
, 0, name_len
);
1327 * Validate the value type and domains are legal for the process
1328 * attribute tracker that is specified and convert the value to
1329 * add/remove to the internal sessiond representation.
1331 ret_code
= process_attr_value_from_comm(domain_type
,
1332 process_attr
, value_type
,
1333 &cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1335 &payload_view
, &value
);
1336 if (ret_code
!= LTTNG_OK
) {
1338 goto error_add_remove_tracker_value
;
1342 ret
= cmd_process_attr_tracker_inclusion_set_add_value(
1343 cmd_ctx
->session
, domain_type
,
1344 process_attr
, value
);
1346 ret
= cmd_process_attr_tracker_inclusion_set_remove_value(
1347 cmd_ctx
->session
, domain_type
,
1348 process_attr
, value
);
1350 process_attr_value_destroy(value
);
1351 error_add_remove_tracker_value
:
1352 lttng_dynamic_buffer_reset(&payload
);
1355 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
1357 enum lttng_tracking_policy tracking_policy
;
1358 const enum lttng_domain_type domain_type
=
1359 (enum lttng_domain_type
)
1360 cmd_ctx
->lsm
.domain
.type
;
1361 const enum lttng_process_attr process_attr
=
1362 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1363 .process_attr_tracker_get_tracking_policy
1366 ret
= cmd_process_attr_tracker_get_tracking_policy(
1367 cmd_ctx
->session
, domain_type
, process_attr
,
1369 if (ret
!= LTTNG_OK
) {
1373 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1374 &(uint32_t){tracking_policy
}, sizeof(uint32_t));
1376 ret
= LTTNG_ERR_NOMEM
;
1382 case LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY
:
1384 const enum lttng_tracking_policy tracking_policy
=
1385 (enum lttng_tracking_policy
) cmd_ctx
->lsm
.u
1386 .process_attr_tracker_set_tracking_policy
1388 const enum lttng_domain_type domain_type
=
1389 (enum lttng_domain_type
)
1390 cmd_ctx
->lsm
.domain
.type
;
1391 const enum lttng_process_attr process_attr
=
1392 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1393 .process_attr_tracker_set_tracking_policy
1396 ret
= cmd_process_attr_tracker_set_tracking_policy(
1397 cmd_ctx
->session
, domain_type
, process_attr
,
1399 if (ret
!= LTTNG_OK
) {
1404 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
1406 struct lttng_process_attr_values
*values
;
1407 struct lttng_dynamic_buffer reply
;
1408 const enum lttng_domain_type domain_type
=
1409 (enum lttng_domain_type
)
1410 cmd_ctx
->lsm
.domain
.type
;
1411 const enum lttng_process_attr process_attr
=
1412 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1413 .process_attr_tracker_get_inclusion_set
1416 ret
= cmd_process_attr_tracker_get_inclusion_set(
1417 cmd_ctx
->session
, domain_type
, process_attr
,
1419 if (ret
!= LTTNG_OK
) {
1423 lttng_dynamic_buffer_init(&reply
);
1424 ret
= lttng_process_attr_values_serialize(values
, &reply
);
1426 goto error_tracker_get_inclusion_set
;
1429 ret
= setup_lttng_msg_no_cmd_header(
1430 cmd_ctx
, reply
.data
, reply
.size
);
1432 ret
= LTTNG_ERR_NOMEM
;
1433 goto error_tracker_get_inclusion_set
;
1437 error_tracker_get_inclusion_set
:
1438 lttng_process_attr_values_destroy(values
);
1439 lttng_dynamic_buffer_reset(&reply
);
1442 case LTTNG_ENABLE_EVENT
:
1444 struct lttng_event
*ev
= NULL
;
1445 struct lttng_event_exclusion
*exclusion
= NULL
;
1446 struct lttng_filter_bytecode
*bytecode
= NULL
;
1447 char *filter_expression
= NULL
;
1449 /* Handle exclusion events and receive it from the client. */
1450 if (cmd_ctx
->lsm
.u
.enable
.exclusion_count
> 0) {
1451 size_t count
= cmd_ctx
->lsm
.u
.enable
.exclusion_count
;
1453 exclusion
= zmalloc(sizeof(struct lttng_event_exclusion
) +
1454 (count
* LTTNG_SYMBOL_NAME_LEN
));
1456 ret
= LTTNG_ERR_EXCLUSION_NOMEM
;
1460 DBG("Receiving var len exclusion event list from client ...");
1461 exclusion
->count
= count
;
1462 ret
= lttcomm_recv_unix_sock(*sock
, exclusion
->names
,
1463 count
* LTTNG_SYMBOL_NAME_LEN
);
1465 DBG("Nothing recv() from client var len data... continuing");
1468 ret
= LTTNG_ERR_EXCLUSION_INVAL
;
1473 /* Get filter expression from client. */
1474 if (cmd_ctx
->lsm
.u
.enable
.expression_len
> 0) {
1475 size_t expression_len
=
1476 cmd_ctx
->lsm
.u
.enable
.expression_len
;
1478 if (expression_len
> LTTNG_FILTER_MAX_LEN
) {
1479 ret
= LTTNG_ERR_FILTER_INVAL
;
1484 filter_expression
= zmalloc(expression_len
);
1485 if (!filter_expression
) {
1487 ret
= LTTNG_ERR_FILTER_NOMEM
;
1491 /* Receive var. len. data */
1492 DBG("Receiving var len filter's expression from client ...");
1493 ret
= lttcomm_recv_unix_sock(*sock
, filter_expression
,
1496 DBG("Nothing recv() from client var len data... continuing");
1498 free(filter_expression
);
1500 ret
= LTTNG_ERR_FILTER_INVAL
;
1505 /* Handle filter and get bytecode from client. */
1506 if (cmd_ctx
->lsm
.u
.enable
.bytecode_len
> 0) {
1507 size_t bytecode_len
= cmd_ctx
->lsm
.u
.enable
.bytecode_len
;
1509 if (bytecode_len
> LTTNG_FILTER_MAX_LEN
) {
1510 ret
= LTTNG_ERR_FILTER_INVAL
;
1511 free(filter_expression
);
1516 bytecode
= zmalloc(bytecode_len
);
1518 free(filter_expression
);
1520 ret
= LTTNG_ERR_FILTER_NOMEM
;
1524 /* Receive var. len. data */
1525 DBG("Receiving var len filter's bytecode from client ...");
1526 ret
= lttcomm_recv_unix_sock(*sock
, bytecode
, bytecode_len
);
1528 DBG("Nothing recv() from client var len data... continuing");
1530 free(filter_expression
);
1533 ret
= LTTNG_ERR_FILTER_INVAL
;
1537 if ((bytecode
->len
+ sizeof(*bytecode
)) != bytecode_len
) {
1538 free(filter_expression
);
1541 ret
= LTTNG_ERR_FILTER_INVAL
;
1546 ev
= lttng_event_copy(ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.enable
.event
));
1548 DBG("Failed to copy event: %s",
1549 cmd_ctx
->lsm
.u
.enable
.event
.name
);
1550 free(filter_expression
);
1553 ret
= LTTNG_ERR_NOMEM
;
1558 if (cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
> 0) {
1559 /* Expect a userspace probe description. */
1560 ret
= receive_userspace_probe(cmd_ctx
, *sock
, sock_error
, ev
);
1562 free(filter_expression
);
1565 lttng_event_destroy(ev
);
1570 ret
= cmd_enable_event(cmd_ctx
->session
,
1571 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1572 cmd_ctx
->lsm
.u
.enable
.channel_name
,
1574 filter_expression
, bytecode
, exclusion
,
1575 kernel_poll_pipe
[1]);
1576 lttng_event_destroy(ev
);
1579 case LTTNG_LIST_TRACEPOINTS
:
1581 struct lttng_event
*events
;
1584 session_lock_list();
1585 nb_events
= cmd_list_tracepoints(cmd_ctx
->lsm
.domain
.type
, &events
);
1586 session_unlock_list();
1587 if (nb_events
< 0) {
1588 /* Return value is a negative lttng_error_code. */
1594 * Setup lttng message with payload size set to the event list size in
1595 * bytes and then copy list into the llm payload.
1597 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1598 sizeof(struct lttng_event
) * nb_events
);
1608 case LTTNG_LIST_TRACEPOINT_FIELDS
:
1610 struct lttng_event_field
*fields
;
1613 session_lock_list();
1614 nb_fields
= cmd_list_tracepoint_fields(cmd_ctx
->lsm
.domain
.type
,
1616 session_unlock_list();
1617 if (nb_fields
< 0) {
1618 /* Return value is a negative lttng_error_code. */
1624 * Setup lttng message with payload size set to the event list size in
1625 * bytes and then copy list into the llm payload.
1627 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, fields
,
1628 sizeof(struct lttng_event_field
) * nb_fields
);
1638 case LTTNG_LIST_SYSCALLS
:
1640 struct lttng_event
*events
;
1643 nb_events
= cmd_list_syscalls(&events
);
1644 if (nb_events
< 0) {
1645 /* Return value is a negative lttng_error_code. */
1651 * Setup lttng message with payload size set to the event list size in
1652 * bytes and then copy list into the llm payload.
1654 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1655 sizeof(struct lttng_event
) * nb_events
);
1665 case LTTNG_SET_CONSUMER_URI
:
1668 struct lttng_uri
*uris
;
1670 nb_uri
= cmd_ctx
->lsm
.u
.uri
.size
;
1671 len
= nb_uri
* sizeof(struct lttng_uri
);
1674 ret
= LTTNG_ERR_INVALID
;
1678 uris
= zmalloc(len
);
1680 ret
= LTTNG_ERR_FATAL
;
1684 /* Receive variable len data */
1685 DBG("Receiving %zu URI(s) from client ...", nb_uri
);
1686 ret
= lttcomm_recv_unix_sock(*sock
, uris
, len
);
1688 DBG("No URIs received from client... continuing");
1690 ret
= LTTNG_ERR_SESSION_FAIL
;
1695 ret
= cmd_set_consumer_uri(cmd_ctx
->session
, nb_uri
, uris
);
1697 if (ret
!= LTTNG_OK
) {
1704 case LTTNG_START_TRACE
:
1707 * On the first start, if we have a kernel session and we have
1708 * enabled time or size-based rotations, we have to make sure
1709 * the kernel tracer supports it.
1711 if (!cmd_ctx
->session
->has_been_started
&& \
1712 cmd_ctx
->session
->kernel_session
&& \
1713 (cmd_ctx
->session
->rotate_timer_period
|| \
1714 cmd_ctx
->session
->rotate_size
) && \
1715 !check_rotate_compatible()) {
1716 DBG("Kernel tracer version is not compatible with the rotation feature");
1717 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
1720 ret
= cmd_start_trace(cmd_ctx
->session
);
1723 case LTTNG_STOP_TRACE
:
1725 ret
= cmd_stop_trace(cmd_ctx
->session
);
1728 case LTTNG_DESTROY_SESSION
:
1730 ret
= cmd_destroy_session(cmd_ctx
->session
,
1731 notification_thread_handle
,
1735 case LTTNG_LIST_DOMAINS
:
1738 struct lttng_domain
*domains
= NULL
;
1740 nb_dom
= cmd_list_domains(cmd_ctx
->session
, &domains
);
1742 /* Return value is a negative lttng_error_code. */
1747 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, domains
,
1748 nb_dom
* sizeof(struct lttng_domain
));
1758 case LTTNG_LIST_CHANNELS
:
1760 ssize_t payload_size
;
1761 struct lttng_channel
*channels
= NULL
;
1763 payload_size
= cmd_list_channels(cmd_ctx
->lsm
.domain
.type
,
1764 cmd_ctx
->session
, &channels
);
1765 if (payload_size
< 0) {
1766 /* Return value is a negative lttng_error_code. */
1767 ret
= -payload_size
;
1771 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, channels
,
1782 case LTTNG_LIST_EVENTS
:
1785 struct lttcomm_event_command_header cmd_header
= {};
1786 size_t original_payload_size
;
1787 size_t payload_size
;
1789 ret
= setup_empty_lttng_msg(cmd_ctx
);
1791 ret
= LTTNG_ERR_NOMEM
;
1795 original_payload_size
= cmd_ctx
->reply_payload
.buffer
.size
;
1797 /* Extended infos are included at the end of the payload. */
1798 list_ret
= cmd_list_events(cmd_ctx
->lsm
.domain
.type
,
1800 cmd_ctx
->lsm
.u
.list
.channel_name
,
1801 &cmd_ctx
->reply_payload
);
1803 /* Return value is a negative lttng_error_code. */
1808 payload_size
= cmd_ctx
->reply_payload
.buffer
.size
-
1809 sizeof(cmd_header
) - original_payload_size
;
1810 update_lttng_msg(cmd_ctx
, sizeof(cmd_header
), payload_size
);
1815 case LTTNG_LIST_SESSIONS
:
1817 unsigned int nr_sessions
;
1818 void *sessions_payload
;
1821 session_lock_list();
1822 nr_sessions
= lttng_sessions_count(
1823 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1824 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1826 payload_len
= (sizeof(struct lttng_session
) * nr_sessions
) +
1827 (sizeof(struct lttng_session_extended
) * nr_sessions
);
1828 sessions_payload
= zmalloc(payload_len
);
1830 if (!sessions_payload
) {
1831 session_unlock_list();
1836 cmd_list_lttng_sessions(sessions_payload
, nr_sessions
,
1837 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1838 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1839 session_unlock_list();
1841 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, sessions_payload
,
1843 free(sessions_payload
);
1852 case LTTNG_REGISTER_CONSUMER
:
1854 struct consumer_data
*cdata
;
1856 switch (cmd_ctx
->lsm
.domain
.type
) {
1857 case LTTNG_DOMAIN_KERNEL
:
1858 cdata
= &kconsumer_data
;
1861 ret
= LTTNG_ERR_UND
;
1865 ret
= cmd_register_consumer(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1866 cmd_ctx
->lsm
.u
.reg
.path
, cdata
);
1869 case LTTNG_DATA_PENDING
:
1872 uint8_t pending_ret_byte
;
1874 pending_ret
= cmd_data_pending(cmd_ctx
->session
);
1879 * This function may returns 0 or 1 to indicate whether or not
1880 * there is data pending. In case of error, it should return an
1881 * LTTNG_ERR code. However, some code paths may still return
1882 * a nondescript error code, which we handle by returning an
1885 if (pending_ret
== 0 || pending_ret
== 1) {
1887 * ret will be set to LTTNG_OK at the end of
1890 } else if (pending_ret
< 0) {
1891 ret
= LTTNG_ERR_UNK
;
1898 pending_ret_byte
= (uint8_t) pending_ret
;
1900 /* 1 byte to return whether or not data is pending */
1901 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1902 &pending_ret_byte
, 1);
1911 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
1913 uint32_t snapshot_id
;
1914 struct lttcomm_lttng_output_id reply
;
1916 ret
= cmd_snapshot_add_output(cmd_ctx
->session
,
1917 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
),
1919 if (ret
!= LTTNG_OK
) {
1922 reply
.id
= snapshot_id
;
1924 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &reply
,
1930 /* Copy output list into message payload */
1934 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
1936 ret
= cmd_snapshot_del_output(cmd_ctx
->session
,
1937 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
));
1940 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
1943 struct lttng_snapshot_output
*outputs
= NULL
;
1945 nb_output
= cmd_snapshot_list_outputs(cmd_ctx
->session
, &outputs
);
1946 if (nb_output
< 0) {
1951 assert((nb_output
> 0 && outputs
) || nb_output
== 0);
1952 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, outputs
,
1953 nb_output
* sizeof(struct lttng_snapshot_output
));
1963 case LTTNG_SNAPSHOT_RECORD
:
1965 ret
= cmd_snapshot_record(cmd_ctx
->session
,
1966 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_record
.output
),
1967 cmd_ctx
->lsm
.u
.snapshot_record
.wait
);
1970 case LTTNG_CREATE_SESSION_EXT
:
1972 struct lttng_dynamic_buffer payload
;
1973 struct lttng_session_descriptor
*return_descriptor
= NULL
;
1975 lttng_dynamic_buffer_init(&payload
);
1976 ret
= cmd_create_session(cmd_ctx
, *sock
, &return_descriptor
);
1977 if (ret
!= LTTNG_OK
) {
1981 ret
= lttng_session_descriptor_serialize(return_descriptor
,
1984 ERR("Failed to serialize session descriptor in reply to \"create session\" command");
1985 lttng_session_descriptor_destroy(return_descriptor
);
1986 ret
= LTTNG_ERR_NOMEM
;
1989 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, payload
.data
,
1992 lttng_session_descriptor_destroy(return_descriptor
);
1993 ret
= LTTNG_ERR_NOMEM
;
1996 lttng_dynamic_buffer_reset(&payload
);
1997 lttng_session_descriptor_destroy(return_descriptor
);
2001 case LTTNG_SAVE_SESSION
:
2003 ret
= cmd_save_sessions(&cmd_ctx
->lsm
.u
.save_session
.attr
,
2007 case LTTNG_SET_SESSION_SHM_PATH
:
2009 ret
= cmd_set_session_shm_path(cmd_ctx
->session
,
2010 cmd_ctx
->lsm
.u
.set_shm_path
.shm_path
);
2013 case LTTNG_REGENERATE_METADATA
:
2015 ret
= cmd_regenerate_metadata(cmd_ctx
->session
);
2018 case LTTNG_REGENERATE_STATEDUMP
:
2020 ret
= cmd_regenerate_statedump(cmd_ctx
->session
);
2023 case LTTNG_REGISTER_TRIGGER
:
2025 ret
= cmd_register_trigger(cmd_ctx
, *sock
,
2026 notification_thread_handle
);
2029 case LTTNG_UNREGISTER_TRIGGER
:
2031 ret
= cmd_unregister_trigger(cmd_ctx
, *sock
,
2032 notification_thread_handle
);
2035 case LTTNG_ROTATE_SESSION
:
2037 struct lttng_rotate_session_return rotate_return
;
2039 DBG("Client rotate session \"%s\"", cmd_ctx
->session
->name
);
2041 memset(&rotate_return
, 0, sizeof(rotate_return
));
2042 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2043 DBG("Kernel tracer version is not compatible with the rotation feature");
2044 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2048 ret
= cmd_rotate_session(cmd_ctx
->session
, &rotate_return
,
2050 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED
);
2056 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &rotate_return
,
2057 sizeof(rotate_return
));
2066 case LTTNG_ROTATION_GET_INFO
:
2068 struct lttng_rotation_get_info_return get_info_return
;
2070 memset(&get_info_return
, 0, sizeof(get_info_return
));
2071 ret
= cmd_rotate_get_info(cmd_ctx
->session
, &get_info_return
,
2072 cmd_ctx
->lsm
.u
.get_rotation_info
.rotation_id
);
2078 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &get_info_return
,
2079 sizeof(get_info_return
));
2088 case LTTNG_ROTATION_SET_SCHEDULE
:
2091 enum lttng_rotation_schedule_type schedule_type
;
2094 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2095 DBG("Kernel tracer version does not support session rotations");
2096 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2100 set_schedule
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.set
== 1;
2101 schedule_type
= (enum lttng_rotation_schedule_type
) cmd_ctx
->lsm
.u
.rotation_set_schedule
.type
;
2102 value
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.value
;
2104 ret
= cmd_rotation_set_schedule(cmd_ctx
->session
,
2108 notification_thread_handle
);
2109 if (ret
!= LTTNG_OK
) {
2115 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
2117 struct lttng_session_list_schedules_return schedules
= {
2118 .periodic
.set
= !!cmd_ctx
->session
->rotate_timer_period
,
2119 .periodic
.value
= cmd_ctx
->session
->rotate_timer_period
,
2120 .size
.set
= !!cmd_ctx
->session
->rotate_size
,
2121 .size
.value
= cmd_ctx
->session
->rotate_size
,
2124 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &schedules
,
2134 case LTTNG_CLEAR_SESSION
:
2136 ret
= cmd_clear_session(cmd_ctx
->session
, sock
);
2140 ret
= LTTNG_ERR_UND
;
2145 if (cmd_ctx
->reply_payload
.buffer
.size
== 0) {
2146 DBG("Missing llm header, creating one.");
2147 if (setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0) < 0) {
2151 /* Set return code */
2152 ((struct lttcomm_lttng_msg
*) (cmd_ctx
->reply_payload
.buffer
.data
))->ret_code
= ret
;
2154 if (cmd_ctx
->session
) {
2155 session_unlock(cmd_ctx
->session
);
2156 session_put(cmd_ctx
->session
);
2157 cmd_ctx
->session
= NULL
;
2159 if (need_tracing_session
) {
2160 session_unlock_list();
2163 assert(!rcu_read_ongoing());
2167 static int create_client_sock(void)
2169 int ret
, client_sock
;
2170 const mode_t old_umask
= umask(0);
2172 /* Create client tool unix socket */
2173 client_sock
= lttcomm_create_unix_sock(config
.client_unix_sock_path
.value
);
2174 if (client_sock
< 0) {
2175 ERR("Create unix sock failed: %s", config
.client_unix_sock_path
.value
);
2180 /* Set the cloexec flag */
2181 ret
= utils_set_fd_cloexec(client_sock
);
2183 ERR("Unable to set CLOEXEC flag to the client Unix socket (fd: %d). "
2184 "Continuing but note that the consumer daemon will have a "
2185 "reference to this socket on exec()", client_sock
);
2188 /* File permission MUST be 660 */
2189 ret
= chmod(config
.client_unix_sock_path
.value
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
2191 ERR("Set file permissions failed: %s",
2192 config
.client_unix_sock_path
.value
);
2194 (void) lttcomm_close_unix_sock(client_sock
);
2198 DBG("Created client socket (fd = %i)", client_sock
);
2205 static void cleanup_client_thread(void *data
)
2207 struct lttng_pipe
*quit_pipe
= data
;
2209 lttng_pipe_destroy(quit_pipe
);
2212 static void thread_init_cleanup(void *data
)
2214 set_thread_status(false);
2218 * This thread manage all clients request using the unix client socket for
2221 static void *thread_manage_clients(void *data
)
2223 int sock
= -1, ret
, i
, pollfd
, err
= -1;
2225 uint32_t revents
, nb_fd
;
2226 struct lttng_poll_event events
;
2227 const int client_sock
= thread_state
.client_sock
;
2228 struct lttng_pipe
*quit_pipe
= data
;
2229 const int thread_quit_pipe_fd
= lttng_pipe_get_readfd(quit_pipe
);
2230 struct command_ctx cmd_ctx
= {};
2232 DBG("[thread] Manage client started");
2234 lttng_payload_init(&cmd_ctx
.reply_payload
);
2236 is_root
= (getuid() == 0);
2238 pthread_cleanup_push(thread_init_cleanup
, NULL
);
2240 rcu_register_thread();
2242 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_CMD
);
2244 health_code_update();
2246 ret
= lttcomm_listen_unix_sock(client_sock
);
2252 * Pass 2 as size here for the thread quit pipe and client_sock. Nothing
2253 * more will be added to this poll set.
2255 ret
= lttng_poll_create(&events
, 2, LTTNG_CLOEXEC
);
2257 goto error_create_poll
;
2260 /* Add the application registration socket */
2261 ret
= lttng_poll_add(&events
, client_sock
, LPOLLIN
| LPOLLPRI
);
2266 /* Add thread quit pipe */
2267 ret
= lttng_poll_add(&events
, thread_quit_pipe_fd
, LPOLLIN
| LPOLLERR
);
2272 /* Set state as running. */
2273 set_thread_status(true);
2274 pthread_cleanup_pop(0);
2276 /* This testpoint is after we signal readiness to the parent. */
2277 if (testpoint(sessiond_thread_manage_clients
)) {
2281 if (testpoint(sessiond_thread_manage_clients_before_loop
)) {
2285 health_code_update();
2288 const struct cmd_completion_handler
*cmd_completion_handler
;
2290 cmd_ctx
.creds
= (lttng_sock_cred
) {
2294 cmd_ctx
.session
= NULL
;
2295 lttng_payload_clear(&cmd_ctx
.reply_payload
);
2296 cmd_ctx
.lttng_msg_size
= 0;
2298 DBG("Accepting client command ...");
2300 /* Inifinite blocking call, waiting for transmission */
2302 health_poll_entry();
2303 ret
= lttng_poll_wait(&events
, -1);
2307 * Restart interrupted system call.
2309 if (errno
== EINTR
) {
2317 for (i
= 0; i
< nb_fd
; i
++) {
2318 revents
= LTTNG_POLL_GETEV(&events
, i
);
2319 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2321 health_code_update();
2323 if (pollfd
== thread_quit_pipe_fd
) {
2327 /* Event on the registration socket */
2328 if (revents
& LPOLLIN
) {
2330 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2331 ERR("Client socket poll error");
2334 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2340 DBG("Wait for client response");
2342 health_code_update();
2344 sock
= lttcomm_accept_unix_sock(client_sock
);
2350 * Set the CLOEXEC flag. Return code is useless because either way, the
2353 (void) utils_set_fd_cloexec(sock
);
2355 /* Set socket option for credentials retrieval */
2356 ret
= lttcomm_setsockopt_creds_unix_sock(sock
);
2361 health_code_update();
2364 * Data is received from the lttng client. The struct
2365 * lttcomm_session_msg (lsm) contains the command and data request of
2368 DBG("Receiving data from client ...");
2369 ret
= lttcomm_recv_creds_unix_sock(sock
, &cmd_ctx
.lsm
,
2370 sizeof(struct lttcomm_session_msg
), &cmd_ctx
.creds
);
2371 if (ret
!= sizeof(struct lttcomm_session_msg
)) {
2372 DBG("Incomplete recv() from client... continuing");
2381 health_code_update();
2383 // TODO: Validate cmd_ctx including sanity check for
2384 // security purpose.
2386 rcu_thread_online();
2388 * This function dispatch the work to the kernel or userspace tracer
2389 * libs and fill the lttcomm_lttng_msg data structure of all the needed
2390 * informations for the client. The command context struct contains
2391 * everything this function may needs.
2393 ret
= process_client_msg(&cmd_ctx
, &sock
, &sock_error
);
2394 rcu_thread_offline();
2404 * TODO: Inform client somehow of the fatal error. At
2405 * this point, ret < 0 means that a zmalloc failed
2406 * (ENOMEM). Error detected but still accept
2407 * command, unless a socket error has been
2413 cmd_completion_handler
= cmd_pop_completion_handler();
2414 if (cmd_completion_handler
) {
2415 enum lttng_error_code completion_code
;
2417 completion_code
= cmd_completion_handler
->run(
2418 cmd_completion_handler
->data
);
2419 if (completion_code
!= LTTNG_OK
) {
2424 health_code_update();
2427 struct lttng_payload_view view
=
2428 lttng_payload_view_from_payload(
2429 &cmd_ctx
.reply_payload
,
2431 struct lttcomm_lttng_msg
*llm
= (typeof(
2432 llm
)) cmd_ctx
.reply_payload
.buffer
.data
;
2434 assert(cmd_ctx
.reply_payload
.buffer
.size
>=
2436 assert(cmd_ctx
.lttng_msg_size
== cmd_ctx
.reply_payload
.buffer
.size
);
2438 llm
->fd_count
= lttng_payload_view_get_fd_handle_count(&view
);
2440 DBG("Sending response (size: %d, retcode: %s (%d))",
2441 cmd_ctx
.lttng_msg_size
,
2442 lttng_strerror(-llm
->ret_code
),
2444 ret
= send_unix_sock(sock
, &view
);
2446 ERR("Failed to send data back to client");
2449 /* End of transmission */
2457 health_code_update();
2469 lttng_poll_clean(&events
);
2473 unlink(config
.client_unix_sock_path
.value
);
2474 ret
= close(client_sock
);
2481 ERR("Health error occurred in %s", __func__
);
2484 health_unregister(health_sessiond
);
2486 DBG("Client thread dying");
2487 lttng_payload_reset(&cmd_ctx
.reply_payload
);
2488 rcu_unregister_thread();
2493 bool shutdown_client_thread(void *thread_data
)
2495 struct lttng_pipe
*client_quit_pipe
= thread_data
;
2496 const int write_fd
= lttng_pipe_get_writefd(client_quit_pipe
);
2498 return notify_thread_pipe(write_fd
) == 1;
2501 struct lttng_thread
*launch_client_thread(void)
2503 bool thread_running
;
2504 struct lttng_pipe
*client_quit_pipe
;
2505 struct lttng_thread
*thread
= NULL
;
2506 int client_sock_fd
= -1;
2508 sem_init(&thread_state
.ready
, 0, 0);
2509 client_quit_pipe
= lttng_pipe_open(FD_CLOEXEC
);
2510 if (!client_quit_pipe
) {
2514 client_sock_fd
= create_client_sock();
2515 if (client_sock_fd
< 0) {
2519 thread_state
.client_sock
= client_sock_fd
;
2520 thread
= lttng_thread_create("Client management",
2521 thread_manage_clients
,
2522 shutdown_client_thread
,
2523 cleanup_client_thread
,
2528 /* The client thread now owns the client sock fd and the quit pipe. */
2529 client_sock_fd
= -1;
2530 client_quit_pipe
= NULL
;
2533 * This thread is part of the threads that need to be fully
2534 * initialized before the session daemon is marked as "ready".
2536 thread_running
= wait_thread_status();
2537 if (!thread_running
) {
2542 if (client_sock_fd
>= 0) {
2543 if (close(client_sock_fd
)) {
2544 PERROR("Failed to close client socket");
2547 lttng_thread_put(thread
);
2548 cleanup_client_thread(client_quit_pipe
);