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", uid
);
583 cds_list_for_each_entry(session
, &session_list
->head
, list
) {
584 if (!session_get(session
)) {
587 session_lock(session
);
588 /* Only count the sessions the user can control. */
589 if (session_access_ok(session
, uid
) &&
590 !session
->destroyed
) {
593 session_unlock(session
);
594 session_put(session
);
599 static int receive_userspace_probe(struct command_ctx
*cmd_ctx
, int sock
,
600 int *sock_error
, struct lttng_event
*event
)
603 struct lttng_userspace_probe_location
*probe_location
;
604 struct lttng_payload probe_location_payload
;
605 struct fd_handle
*handle
= NULL
;
608 * Create a payload to store the serialized version of the probe
611 lttng_payload_init(&probe_location_payload
);
613 ret
= lttng_dynamic_buffer_set_size(&probe_location_payload
.buffer
,
614 cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
);
616 ret
= LTTNG_ERR_NOMEM
;
621 * Receive the probe location.
623 ret
= lttcomm_recv_unix_sock(sock
, probe_location_payload
.buffer
.data
,
624 probe_location_payload
.buffer
.size
);
626 DBG("Nothing recv() from client var len data... continuing");
628 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
633 * Receive the file descriptor to the target binary from the client.
635 DBG("Receiving userspace probe target FD from client ...");
636 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
638 DBG("Nothing recv() from client userspace probe fd... continuing");
640 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
644 handle
= fd_handle_create(fd
);
646 ret
= LTTNG_ERR_NOMEM
;
650 /* Transferred to the handle. */
653 ret
= lttng_payload_push_fd_handle(&probe_location_payload
, handle
);
655 ERR("Failed to add userspace probe file descriptor to payload");
656 ret
= LTTNG_ERR_NOMEM
;
660 fd_handle_put(handle
);
664 struct lttng_payload_view view
= lttng_payload_view_from_payload(
665 &probe_location_payload
, 0, -1);
667 /* Extract the probe location from the serialized version. */
668 ret
= lttng_userspace_probe_location_create_from_payload(
669 &view
, &probe_location
);
672 WARN("Failed to create a userspace probe location from the received buffer");
673 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
677 /* Attach the probe location to the event. */
678 ret
= lttng_event_set_userspace_probe_location(event
, probe_location
);
680 ret
= LTTNG_ERR_PROBE_LOCATION_INVAL
;
687 PERROR("Failed to close userspace probe location binary fd");
691 fd_handle_put(handle
);
692 lttng_payload_reset(&probe_location_payload
);
697 * Version of setup_lttng_msg() without command header.
699 static int setup_lttng_msg_no_cmd_header(struct command_ctx
*cmd_ctx
,
700 void *payload_buf
, size_t payload_len
)
702 return setup_lttng_msg(cmd_ctx
, payload_buf
, payload_len
, NULL
, 0);
706 * Check if the current kernel tracer supports the session rotation feature.
707 * Return 1 if it does, 0 otherwise.
709 static int check_rotate_compatible(void)
713 if (kernel_tracer_version
.major
!= 2 || kernel_tracer_version
.minor
< 11) {
714 DBG("Kernel tracer version is not compatible with the rotation feature");
722 * Send data on a unix socket using the liblttsessiondcomm API.
724 * Return lttcomm error code.
726 static int send_unix_sock(int sock
, struct lttng_payload_view
*view
)
729 const int fd_count
= lttng_payload_view_get_fd_handle_count(view
);
731 /* Check valid length */
732 if (view
->buffer
.size
== 0) {
737 ret
= lttcomm_send_unix_sock(
738 sock
, view
->buffer
.data
, view
->buffer
.size
);
744 ret
= lttcomm_send_payload_view_fds_unix_sock(sock
, view
);
755 * Process the command requested by the lttng client within the command
756 * context structure. This function make sure that the return structure (llm)
757 * is set and ready for transmission before returning.
759 * Return any error encountered or 0 for success.
761 * "sock" is only used for special-case var. len data.
762 * A command may assume the ownership of the socket, in which case its value
763 * should be set to -1.
765 * Should *NOT* be called with RCU read-side lock held.
767 static int process_client_msg(struct command_ctx
*cmd_ctx
, int *sock
,
771 int need_tracing_session
= 1;
774 DBG("Processing client command %d", cmd_ctx
->lsm
.cmd_type
);
776 assert(!rcu_read_ongoing());
780 switch (cmd_ctx
->lsm
.cmd_type
) {
781 case LTTNG_CREATE_SESSION_EXT
:
782 case LTTNG_DESTROY_SESSION
:
783 case LTTNG_LIST_SESSIONS
:
784 case LTTNG_LIST_DOMAINS
:
785 case LTTNG_START_TRACE
:
786 case LTTNG_STOP_TRACE
:
787 case LTTNG_DATA_PENDING
:
788 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
789 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
790 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
791 case LTTNG_SNAPSHOT_RECORD
:
792 case LTTNG_SAVE_SESSION
:
793 case LTTNG_SET_SESSION_SHM_PATH
:
794 case LTTNG_REGENERATE_METADATA
:
795 case LTTNG_REGENERATE_STATEDUMP
:
796 case LTTNG_REGISTER_TRIGGER
:
797 case LTTNG_UNREGISTER_TRIGGER
:
798 case LTTNG_ROTATE_SESSION
:
799 case LTTNG_ROTATION_GET_INFO
:
800 case LTTNG_ROTATION_SET_SCHEDULE
:
801 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
802 case LTTNG_CLEAR_SESSION
:
809 if (config
.no_kernel
&& need_domain
810 && cmd_ctx
->lsm
.domain
.type
== LTTNG_DOMAIN_KERNEL
) {
812 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
814 ret
= LTTNG_ERR_KERN_NA
;
819 /* Deny register consumer if we already have a spawned consumer. */
820 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_REGISTER_CONSUMER
) {
821 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
822 if (kconsumer_data
.pid
> 0) {
823 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
824 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
827 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
831 * Check for command that don't needs to allocate a returned payload. We do
832 * this here so we don't have to make the call for no payload at each
835 switch(cmd_ctx
->lsm
.cmd_type
) {
836 case LTTNG_LIST_SESSIONS
:
837 case LTTNG_LIST_TRACEPOINTS
:
838 case LTTNG_LIST_TRACEPOINT_FIELDS
:
839 case LTTNG_LIST_DOMAINS
:
840 case LTTNG_LIST_CHANNELS
:
841 case LTTNG_LIST_EVENTS
:
842 case LTTNG_LIST_SYSCALLS
:
843 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
844 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
845 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
846 case LTTNG_DATA_PENDING
:
847 case LTTNG_ROTATE_SESSION
:
848 case LTTNG_ROTATION_GET_INFO
:
851 /* Setup lttng message with no payload */
852 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0);
854 /* This label does not try to unlock the session */
855 goto init_setup_error
;
859 /* Commands that DO NOT need a session. */
860 switch (cmd_ctx
->lsm
.cmd_type
) {
861 case LTTNG_CREATE_SESSION_EXT
:
862 case LTTNG_LIST_SESSIONS
:
863 case LTTNG_LIST_TRACEPOINTS
:
864 case LTTNG_LIST_SYSCALLS
:
865 case LTTNG_LIST_TRACEPOINT_FIELDS
:
866 case LTTNG_SAVE_SESSION
:
867 case LTTNG_REGISTER_TRIGGER
:
868 case LTTNG_UNREGISTER_TRIGGER
:
869 need_tracing_session
= 0;
872 DBG("Getting session %s by name", cmd_ctx
->lsm
.session
.name
);
874 * We keep the session list lock across _all_ commands
875 * for now, because the per-session lock does not
876 * handle teardown properly.
879 cmd_ctx
->session
= session_find_by_name(cmd_ctx
->lsm
.session
.name
);
880 if (cmd_ctx
->session
== NULL
) {
881 ret
= LTTNG_ERR_SESS_NOT_FOUND
;
884 /* Acquire lock for the session */
885 session_lock(cmd_ctx
->session
);
891 * Commands that need a valid session but should NOT create one if none
892 * exists. Instead of creating one and destroying it when the command is
893 * handled, process that right before so we save some round trip in useless
896 switch (cmd_ctx
->lsm
.cmd_type
) {
897 case LTTNG_DISABLE_CHANNEL
:
898 case LTTNG_DISABLE_EVENT
:
899 switch (cmd_ctx
->lsm
.domain
.type
) {
900 case LTTNG_DOMAIN_KERNEL
:
901 if (!cmd_ctx
->session
->kernel_session
) {
902 ret
= LTTNG_ERR_NO_CHANNEL
;
906 case LTTNG_DOMAIN_JUL
:
907 case LTTNG_DOMAIN_LOG4J
:
908 case LTTNG_DOMAIN_PYTHON
:
909 case LTTNG_DOMAIN_UST
:
910 if (!cmd_ctx
->session
->ust_session
) {
911 ret
= LTTNG_ERR_NO_CHANNEL
;
916 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
928 * Check domain type for specific "pre-action".
930 switch (cmd_ctx
->lsm
.domain
.type
) {
931 case LTTNG_DOMAIN_KERNEL
:
933 ret
= LTTNG_ERR_NEED_ROOT_SESSIOND
;
937 /* Kernel tracer check */
938 if (!kernel_tracer_is_initialized()) {
939 /* Basically, load kernel tracer modules */
940 ret
= init_kernel_tracer();
946 /* Consumer is in an ERROR state. Report back to client */
947 if (uatomic_read(&kernel_consumerd_state
) == CONSUMER_ERROR
) {
948 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
952 /* Need a session for kernel command */
953 if (need_tracing_session
) {
954 if (cmd_ctx
->session
->kernel_session
== NULL
) {
955 ret
= create_kernel_session(cmd_ctx
->session
);
956 if (ret
!= LTTNG_OK
) {
957 ret
= LTTNG_ERR_KERN_SESS_FAIL
;
962 /* Start the kernel consumer daemon */
963 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
964 if (kconsumer_data
.pid
== 0 &&
965 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
966 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
967 ret
= start_consumerd(&kconsumer_data
);
969 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
972 uatomic_set(&kernel_consumerd_state
, CONSUMER_STARTED
);
974 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
978 * The consumer was just spawned so we need to add the socket to
979 * the consumer output of the session if exist.
981 ret
= consumer_create_socket(&kconsumer_data
,
982 cmd_ctx
->session
->kernel_session
->consumer
);
989 case LTTNG_DOMAIN_JUL
:
990 case LTTNG_DOMAIN_LOG4J
:
991 case LTTNG_DOMAIN_PYTHON
:
992 case LTTNG_DOMAIN_UST
:
994 if (!ust_app_supported()) {
995 ret
= LTTNG_ERR_NO_UST
;
998 /* Consumer is in an ERROR state. Report back to client */
999 if (uatomic_read(&ust_consumerd_state
) == CONSUMER_ERROR
) {
1000 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1004 if (need_tracing_session
) {
1005 /* Create UST session if none exist. */
1006 if (cmd_ctx
->session
->ust_session
== NULL
) {
1007 ret
= create_ust_session(cmd_ctx
->session
,
1008 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
));
1009 if (ret
!= LTTNG_OK
) {
1014 /* Start the UST consumer daemons */
1016 pthread_mutex_lock(&ustconsumer64_data
.pid_mutex
);
1017 if (config
.consumerd64_bin_path
.value
&&
1018 ustconsumer64_data
.pid
== 0 &&
1019 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1020 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1021 ret
= start_consumerd(&ustconsumer64_data
);
1023 ret
= LTTNG_ERR_UST_CONSUMER64_FAIL
;
1024 uatomic_set(&ust_consumerd64_fd
, -EINVAL
);
1028 uatomic_set(&ust_consumerd64_fd
, ustconsumer64_data
.cmd_sock
);
1029 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1031 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
1035 * Setup socket for consumer 64 bit. No need for atomic access
1036 * since it was set above and can ONLY be set in this thread.
1038 ret
= consumer_create_socket(&ustconsumer64_data
,
1039 cmd_ctx
->session
->ust_session
->consumer
);
1045 pthread_mutex_lock(&ustconsumer32_data
.pid_mutex
);
1046 if (config
.consumerd32_bin_path
.value
&&
1047 ustconsumer32_data
.pid
== 0 &&
1048 cmd_ctx
->lsm
.cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
1049 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1050 ret
= start_consumerd(&ustconsumer32_data
);
1052 ret
= LTTNG_ERR_UST_CONSUMER32_FAIL
;
1053 uatomic_set(&ust_consumerd32_fd
, -EINVAL
);
1057 uatomic_set(&ust_consumerd32_fd
, ustconsumer32_data
.cmd_sock
);
1058 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
1060 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
1064 * Setup socket for consumer 32 bit. No need for atomic access
1065 * since it was set above and can ONLY be set in this thread.
1067 ret
= consumer_create_socket(&ustconsumer32_data
,
1068 cmd_ctx
->session
->ust_session
->consumer
);
1080 /* Validate consumer daemon state when start/stop trace command */
1081 if (cmd_ctx
->lsm
.cmd_type
== LTTNG_START_TRACE
||
1082 cmd_ctx
->lsm
.cmd_type
== LTTNG_STOP_TRACE
) {
1083 switch (cmd_ctx
->lsm
.domain
.type
) {
1084 case LTTNG_DOMAIN_NONE
:
1086 case LTTNG_DOMAIN_JUL
:
1087 case LTTNG_DOMAIN_LOG4J
:
1088 case LTTNG_DOMAIN_PYTHON
:
1089 case LTTNG_DOMAIN_UST
:
1090 if (uatomic_read(&ust_consumerd_state
) != CONSUMER_STARTED
) {
1091 ret
= LTTNG_ERR_NO_USTCONSUMERD
;
1095 case LTTNG_DOMAIN_KERNEL
:
1096 if (uatomic_read(&kernel_consumerd_state
) != CONSUMER_STARTED
) {
1097 ret
= LTTNG_ERR_NO_KERNCONSUMERD
;
1102 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1108 * Check that the UID matches that of the tracing session.
1109 * The root user can interact with all sessions.
1111 if (need_tracing_session
) {
1112 if (!session_access_ok(cmd_ctx
->session
,
1113 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
)) ||
1114 cmd_ctx
->session
->destroyed
) {
1115 ret
= LTTNG_ERR_EPERM
;
1121 * Send relayd information to consumer as soon as we have a domain and a
1124 if (cmd_ctx
->session
&& need_domain
) {
1126 * Setup relayd if not done yet. If the relayd information was already
1127 * sent to the consumer, this call will gracefully return.
1129 ret
= cmd_setup_relayd(cmd_ctx
->session
);
1130 if (ret
!= LTTNG_OK
) {
1135 /* Process by command type */
1136 switch (cmd_ctx
->lsm
.cmd_type
) {
1137 case LTTNG_ADD_CONTEXT
:
1140 * An LTTNG_ADD_CONTEXT command might have a supplementary
1141 * payload if the context being added is an application context.
1143 if (cmd_ctx
->lsm
.u
.context
.ctx
.ctx
==
1144 LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1145 char *provider_name
= NULL
, *context_name
= NULL
;
1146 size_t provider_name_len
=
1147 cmd_ctx
->lsm
.u
.context
.provider_name_len
;
1148 size_t context_name_len
=
1149 cmd_ctx
->lsm
.u
.context
.context_name_len
;
1151 if (provider_name_len
== 0 || context_name_len
== 0) {
1153 * Application provider and context names MUST
1156 ret
= -LTTNG_ERR_INVALID
;
1160 provider_name
= zmalloc(provider_name_len
+ 1);
1161 if (!provider_name
) {
1162 ret
= -LTTNG_ERR_NOMEM
;
1165 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
=
1168 context_name
= zmalloc(context_name_len
+ 1);
1169 if (!context_name
) {
1170 ret
= -LTTNG_ERR_NOMEM
;
1171 goto error_add_context
;
1173 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
=
1176 ret
= lttcomm_recv_unix_sock(*sock
, provider_name
,
1179 goto error_add_context
;
1182 ret
= lttcomm_recv_unix_sock(*sock
, context_name
,
1185 goto error_add_context
;
1190 * cmd_add_context assumes ownership of the provider and context
1193 ret
= cmd_add_context(cmd_ctx
->session
,
1194 cmd_ctx
->lsm
.domain
.type
,
1195 cmd_ctx
->lsm
.u
.context
.channel_name
,
1196 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.context
.ctx
),
1197 kernel_poll_pipe
[1]);
1199 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
1200 cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
1202 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
);
1203 free(cmd_ctx
->lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
);
1209 case LTTNG_DISABLE_CHANNEL
:
1211 ret
= cmd_disable_channel(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1212 cmd_ctx
->lsm
.u
.disable
.channel_name
);
1215 case LTTNG_DISABLE_EVENT
:
1219 * FIXME: handle filter; for now we just receive the filter's
1220 * bytecode along with the filter expression which are sent by
1221 * liblttng-ctl and discard them.
1223 * This fixes an issue where the client may block while sending
1224 * the filter payload and encounter an error because the session
1225 * daemon closes the socket without ever handling this data.
1227 size_t count
= cmd_ctx
->lsm
.u
.disable
.expression_len
+
1228 cmd_ctx
->lsm
.u
.disable
.bytecode_len
;
1231 char data
[LTTNG_FILTER_MAX_LEN
];
1233 DBG("Discarding disable event command payload of size %zu", count
);
1235 ret
= lttcomm_recv_unix_sock(*sock
, data
,
1236 count
> sizeof(data
) ? sizeof(data
) : count
);
1241 count
-= (size_t) ret
;
1244 ret
= cmd_disable_event(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1245 cmd_ctx
->lsm
.u
.disable
.channel_name
,
1246 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.disable
.event
));
1249 case LTTNG_ENABLE_CHANNEL
:
1251 cmd_ctx
->lsm
.u
.channel
.chan
.attr
.extended
.ptr
=
1252 (struct lttng_channel_extended
*) &cmd_ctx
->lsm
.u
.channel
.extended
;
1253 ret
= cmd_enable_channel(cmd_ctx
->session
,
1254 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1255 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.channel
.chan
),
1256 kernel_poll_pipe
[1]);
1259 case LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
:
1260 case LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE
:
1262 struct lttng_dynamic_buffer payload
;
1263 struct lttng_buffer_view payload_view
;
1264 const bool add_value
=
1265 cmd_ctx
->lsm
.cmd_type
==
1266 LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE
;
1267 const size_t name_len
=
1268 cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1270 const enum lttng_domain_type domain_type
=
1271 (enum lttng_domain_type
)
1272 cmd_ctx
->lsm
.domain
.type
;
1273 const enum lttng_process_attr process_attr
=
1274 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1275 .process_attr_tracker_add_remove_include_value
1277 const enum lttng_process_attr_value_type value_type
=
1278 (enum lttng_process_attr_value_type
) cmd_ctx
1280 .process_attr_tracker_add_remove_include_value
1282 struct process_attr_value
*value
;
1283 enum lttng_error_code ret_code
;
1285 /* Receive remaining variable length payload if applicable. */
1286 if (name_len
> LOGIN_NAME_MAX
) {
1288 * POSIX mandates user and group names that are at least
1289 * 8 characters long. Note that although shadow-utils
1290 * (useradd, groupaadd, etc.) use 32 chars as their
1291 * limit (from bits/utmp.h, UT_NAMESIZE),
1292 * LOGIN_NAME_MAX is defined to 256.
1294 ERR("Rejecting process attribute tracker value %s as the provided exceeds the maximal allowed length: argument length = %zu, maximal length = %d",
1295 add_value
? "addition" : "removal",
1296 name_len
, LOGIN_NAME_MAX
);
1297 ret
= LTTNG_ERR_INVALID
;
1301 lttng_dynamic_buffer_init(&payload
);
1302 if (name_len
!= 0) {
1304 * Receive variable payload for user/group name
1307 ret
= lttng_dynamic_buffer_set_size(&payload
, name_len
);
1309 ERR("Failed to allocate buffer to receive payload of %s process attribute tracker value argument",
1310 add_value
? "add" : "remove");
1311 ret
= LTTNG_ERR_NOMEM
;
1312 goto error_add_remove_tracker_value
;
1315 ret
= lttcomm_recv_unix_sock(
1316 *sock
, payload
.data
, name_len
);
1318 ERR("Failed to receive payload of %s process attribute tracker value argument",
1319 add_value
? "add" : "remove");
1321 ret
= LTTNG_ERR_INVALID_PROTOCOL
;
1322 goto error_add_remove_tracker_value
;
1326 payload_view
= lttng_buffer_view_from_dynamic_buffer(
1327 &payload
, 0, name_len
);
1329 * Validate the value type and domains are legal for the process
1330 * attribute tracker that is specified and convert the value to
1331 * add/remove to the internal sessiond representation.
1333 ret_code
= process_attr_value_from_comm(domain_type
,
1334 process_attr
, value_type
,
1335 &cmd_ctx
->lsm
.u
.process_attr_tracker_add_remove_include_value
1337 &payload_view
, &value
);
1338 if (ret_code
!= LTTNG_OK
) {
1340 goto error_add_remove_tracker_value
;
1344 ret
= cmd_process_attr_tracker_inclusion_set_add_value(
1345 cmd_ctx
->session
, domain_type
,
1346 process_attr
, value
);
1348 ret
= cmd_process_attr_tracker_inclusion_set_remove_value(
1349 cmd_ctx
->session
, domain_type
,
1350 process_attr
, value
);
1352 process_attr_value_destroy(value
);
1353 error_add_remove_tracker_value
:
1354 lttng_dynamic_buffer_reset(&payload
);
1357 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY
:
1359 enum lttng_tracking_policy tracking_policy
;
1360 const enum lttng_domain_type domain_type
=
1361 (enum lttng_domain_type
)
1362 cmd_ctx
->lsm
.domain
.type
;
1363 const enum lttng_process_attr process_attr
=
1364 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1365 .process_attr_tracker_get_tracking_policy
1368 ret
= cmd_process_attr_tracker_get_tracking_policy(
1369 cmd_ctx
->session
, domain_type
, process_attr
,
1371 if (ret
!= LTTNG_OK
) {
1375 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1376 &(uint32_t){tracking_policy
}, sizeof(uint32_t));
1378 ret
= LTTNG_ERR_NOMEM
;
1384 case LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY
:
1386 const enum lttng_tracking_policy tracking_policy
=
1387 (enum lttng_tracking_policy
) cmd_ctx
->lsm
.u
1388 .process_attr_tracker_set_tracking_policy
1390 const enum lttng_domain_type domain_type
=
1391 (enum lttng_domain_type
)
1392 cmd_ctx
->lsm
.domain
.type
;
1393 const enum lttng_process_attr process_attr
=
1394 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1395 .process_attr_tracker_set_tracking_policy
1398 ret
= cmd_process_attr_tracker_set_tracking_policy(
1399 cmd_ctx
->session
, domain_type
, process_attr
,
1401 if (ret
!= LTTNG_OK
) {
1406 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET
:
1408 struct lttng_process_attr_values
*values
;
1409 struct lttng_dynamic_buffer reply
;
1410 const enum lttng_domain_type domain_type
=
1411 (enum lttng_domain_type
)
1412 cmd_ctx
->lsm
.domain
.type
;
1413 const enum lttng_process_attr process_attr
=
1414 (enum lttng_process_attr
) cmd_ctx
->lsm
.u
1415 .process_attr_tracker_get_inclusion_set
1418 ret
= cmd_process_attr_tracker_get_inclusion_set(
1419 cmd_ctx
->session
, domain_type
, process_attr
,
1421 if (ret
!= LTTNG_OK
) {
1425 lttng_dynamic_buffer_init(&reply
);
1426 ret
= lttng_process_attr_values_serialize(values
, &reply
);
1428 goto error_tracker_get_inclusion_set
;
1431 ret
= setup_lttng_msg_no_cmd_header(
1432 cmd_ctx
, reply
.data
, reply
.size
);
1434 ret
= LTTNG_ERR_NOMEM
;
1435 goto error_tracker_get_inclusion_set
;
1439 error_tracker_get_inclusion_set
:
1440 lttng_process_attr_values_destroy(values
);
1441 lttng_dynamic_buffer_reset(&reply
);
1444 case LTTNG_ENABLE_EVENT
:
1446 struct lttng_event
*ev
= NULL
;
1447 struct lttng_event_exclusion
*exclusion
= NULL
;
1448 struct lttng_filter_bytecode
*bytecode
= NULL
;
1449 char *filter_expression
= NULL
;
1451 /* Handle exclusion events and receive it from the client. */
1452 if (cmd_ctx
->lsm
.u
.enable
.exclusion_count
> 0) {
1453 size_t count
= cmd_ctx
->lsm
.u
.enable
.exclusion_count
;
1455 exclusion
= zmalloc(sizeof(struct lttng_event_exclusion
) +
1456 (count
* LTTNG_SYMBOL_NAME_LEN
));
1458 ret
= LTTNG_ERR_EXCLUSION_NOMEM
;
1462 DBG("Receiving var len exclusion event list from client ...");
1463 exclusion
->count
= count
;
1464 ret
= lttcomm_recv_unix_sock(*sock
, exclusion
->names
,
1465 count
* LTTNG_SYMBOL_NAME_LEN
);
1467 DBG("Nothing recv() from client var len data... continuing");
1470 ret
= LTTNG_ERR_EXCLUSION_INVAL
;
1475 /* Get filter expression from client. */
1476 if (cmd_ctx
->lsm
.u
.enable
.expression_len
> 0) {
1477 size_t expression_len
=
1478 cmd_ctx
->lsm
.u
.enable
.expression_len
;
1480 if (expression_len
> LTTNG_FILTER_MAX_LEN
) {
1481 ret
= LTTNG_ERR_FILTER_INVAL
;
1486 filter_expression
= zmalloc(expression_len
);
1487 if (!filter_expression
) {
1489 ret
= LTTNG_ERR_FILTER_NOMEM
;
1493 /* Receive var. len. data */
1494 DBG("Receiving var len filter's expression from client ...");
1495 ret
= lttcomm_recv_unix_sock(*sock
, filter_expression
,
1498 DBG("Nothing recv() from client var len data... continuing");
1500 free(filter_expression
);
1502 ret
= LTTNG_ERR_FILTER_INVAL
;
1507 /* Handle filter and get bytecode from client. */
1508 if (cmd_ctx
->lsm
.u
.enable
.bytecode_len
> 0) {
1509 size_t bytecode_len
= cmd_ctx
->lsm
.u
.enable
.bytecode_len
;
1511 if (bytecode_len
> LTTNG_FILTER_MAX_LEN
) {
1512 ret
= LTTNG_ERR_FILTER_INVAL
;
1513 free(filter_expression
);
1518 bytecode
= zmalloc(bytecode_len
);
1520 free(filter_expression
);
1522 ret
= LTTNG_ERR_FILTER_NOMEM
;
1526 /* Receive var. len. data */
1527 DBG("Receiving var len filter's bytecode from client ...");
1528 ret
= lttcomm_recv_unix_sock(*sock
, bytecode
, bytecode_len
);
1530 DBG("Nothing recv() from client var len data... continuing");
1532 free(filter_expression
);
1535 ret
= LTTNG_ERR_FILTER_INVAL
;
1539 if ((bytecode
->len
+ sizeof(*bytecode
)) != bytecode_len
) {
1540 free(filter_expression
);
1543 ret
= LTTNG_ERR_FILTER_INVAL
;
1548 ev
= lttng_event_copy(ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.enable
.event
));
1550 DBG("Failed to copy event: %s",
1551 cmd_ctx
->lsm
.u
.enable
.event
.name
);
1552 free(filter_expression
);
1555 ret
= LTTNG_ERR_NOMEM
;
1560 if (cmd_ctx
->lsm
.u
.enable
.userspace_probe_location_len
> 0) {
1561 /* Expect a userspace probe description. */
1562 ret
= receive_userspace_probe(cmd_ctx
, *sock
, sock_error
, ev
);
1564 free(filter_expression
);
1567 lttng_event_destroy(ev
);
1572 ret
= cmd_enable_event(cmd_ctx
->session
,
1573 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.domain
),
1574 cmd_ctx
->lsm
.u
.enable
.channel_name
,
1576 filter_expression
, bytecode
, exclusion
,
1577 kernel_poll_pipe
[1]);
1578 lttng_event_destroy(ev
);
1581 case LTTNG_LIST_TRACEPOINTS
:
1583 struct lttng_event
*events
;
1586 session_lock_list();
1587 nb_events
= cmd_list_tracepoints(cmd_ctx
->lsm
.domain
.type
, &events
);
1588 session_unlock_list();
1589 if (nb_events
< 0) {
1590 /* Return value is a negative lttng_error_code. */
1596 * Setup lttng message with payload size set to the event list size in
1597 * bytes and then copy list into the llm payload.
1599 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1600 sizeof(struct lttng_event
) * nb_events
);
1610 case LTTNG_LIST_TRACEPOINT_FIELDS
:
1612 struct lttng_event_field
*fields
;
1615 session_lock_list();
1616 nb_fields
= cmd_list_tracepoint_fields(cmd_ctx
->lsm
.domain
.type
,
1618 session_unlock_list();
1619 if (nb_fields
< 0) {
1620 /* Return value is a negative lttng_error_code. */
1626 * Setup lttng message with payload size set to the event list size in
1627 * bytes and then copy list into the llm payload.
1629 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, fields
,
1630 sizeof(struct lttng_event_field
) * nb_fields
);
1640 case LTTNG_LIST_SYSCALLS
:
1642 struct lttng_event
*events
;
1645 nb_events
= cmd_list_syscalls(&events
);
1646 if (nb_events
< 0) {
1647 /* Return value is a negative lttng_error_code. */
1653 * Setup lttng message with payload size set to the event list size in
1654 * bytes and then copy list into the llm payload.
1656 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, events
,
1657 sizeof(struct lttng_event
) * nb_events
);
1667 case LTTNG_SET_CONSUMER_URI
:
1670 struct lttng_uri
*uris
;
1672 nb_uri
= cmd_ctx
->lsm
.u
.uri
.size
;
1673 len
= nb_uri
* sizeof(struct lttng_uri
);
1676 ret
= LTTNG_ERR_INVALID
;
1680 uris
= zmalloc(len
);
1682 ret
= LTTNG_ERR_FATAL
;
1686 /* Receive variable len data */
1687 DBG("Receiving %zu URI(s) from client ...", nb_uri
);
1688 ret
= lttcomm_recv_unix_sock(*sock
, uris
, len
);
1690 DBG("No URIs received from client... continuing");
1692 ret
= LTTNG_ERR_SESSION_FAIL
;
1697 ret
= cmd_set_consumer_uri(cmd_ctx
->session
, nb_uri
, uris
);
1699 if (ret
!= LTTNG_OK
) {
1706 case LTTNG_START_TRACE
:
1709 * On the first start, if we have a kernel session and we have
1710 * enabled time or size-based rotations, we have to make sure
1711 * the kernel tracer supports it.
1713 if (!cmd_ctx
->session
->has_been_started
&& \
1714 cmd_ctx
->session
->kernel_session
&& \
1715 (cmd_ctx
->session
->rotate_timer_period
|| \
1716 cmd_ctx
->session
->rotate_size
) && \
1717 !check_rotate_compatible()) {
1718 DBG("Kernel tracer version is not compatible with the rotation feature");
1719 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
1722 ret
= cmd_start_trace(cmd_ctx
->session
);
1725 case LTTNG_STOP_TRACE
:
1727 ret
= cmd_stop_trace(cmd_ctx
->session
);
1730 case LTTNG_DESTROY_SESSION
:
1732 ret
= cmd_destroy_session(cmd_ctx
->session
,
1733 notification_thread_handle
,
1737 case LTTNG_LIST_DOMAINS
:
1740 struct lttng_domain
*domains
= NULL
;
1742 nb_dom
= cmd_list_domains(cmd_ctx
->session
, &domains
);
1744 /* Return value is a negative lttng_error_code. */
1749 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, domains
,
1750 nb_dom
* sizeof(struct lttng_domain
));
1760 case LTTNG_LIST_CHANNELS
:
1762 ssize_t payload_size
;
1763 struct lttng_channel
*channels
= NULL
;
1765 payload_size
= cmd_list_channels(cmd_ctx
->lsm
.domain
.type
,
1766 cmd_ctx
->session
, &channels
);
1767 if (payload_size
< 0) {
1768 /* Return value is a negative lttng_error_code. */
1769 ret
= -payload_size
;
1773 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, channels
,
1784 case LTTNG_LIST_EVENTS
:
1787 struct lttcomm_event_command_header cmd_header
= {};
1788 size_t original_payload_size
;
1789 size_t payload_size
;
1791 ret
= setup_empty_lttng_msg(cmd_ctx
);
1793 ret
= LTTNG_ERR_NOMEM
;
1797 original_payload_size
= cmd_ctx
->reply_payload
.buffer
.size
;
1799 /* Extended infos are included at the end of the payload. */
1800 list_ret
= cmd_list_events(cmd_ctx
->lsm
.domain
.type
,
1802 cmd_ctx
->lsm
.u
.list
.channel_name
,
1803 &cmd_ctx
->reply_payload
);
1805 /* Return value is a negative lttng_error_code. */
1810 payload_size
= cmd_ctx
->reply_payload
.buffer
.size
-
1811 sizeof(cmd_header
) - original_payload_size
;
1812 update_lttng_msg(cmd_ctx
, sizeof(cmd_header
), payload_size
);
1817 case LTTNG_LIST_SESSIONS
:
1819 unsigned int nr_sessions
;
1820 void *sessions_payload
;
1823 session_lock_list();
1824 nr_sessions
= lttng_sessions_count(
1825 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1826 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1828 payload_len
= (sizeof(struct lttng_session
) * nr_sessions
) +
1829 (sizeof(struct lttng_session_extended
) * nr_sessions
);
1830 sessions_payload
= zmalloc(payload_len
);
1832 if (!sessions_payload
) {
1833 session_unlock_list();
1838 cmd_list_lttng_sessions(sessions_payload
, nr_sessions
,
1839 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
1840 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
1841 session_unlock_list();
1843 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, sessions_payload
,
1845 free(sessions_payload
);
1854 case LTTNG_REGISTER_CONSUMER
:
1856 struct consumer_data
*cdata
;
1858 switch (cmd_ctx
->lsm
.domain
.type
) {
1859 case LTTNG_DOMAIN_KERNEL
:
1860 cdata
= &kconsumer_data
;
1863 ret
= LTTNG_ERR_UND
;
1867 ret
= cmd_register_consumer(cmd_ctx
->session
, cmd_ctx
->lsm
.domain
.type
,
1868 cmd_ctx
->lsm
.u
.reg
.path
, cdata
);
1871 case LTTNG_DATA_PENDING
:
1874 uint8_t pending_ret_byte
;
1876 pending_ret
= cmd_data_pending(cmd_ctx
->session
);
1881 * This function may returns 0 or 1 to indicate whether or not
1882 * there is data pending. In case of error, it should return an
1883 * LTTNG_ERR code. However, some code paths may still return
1884 * a nondescript error code, which we handle by returning an
1887 if (pending_ret
== 0 || pending_ret
== 1) {
1889 * ret will be set to LTTNG_OK at the end of
1892 } else if (pending_ret
< 0) {
1893 ret
= LTTNG_ERR_UNK
;
1900 pending_ret_byte
= (uint8_t) pending_ret
;
1902 /* 1 byte to return whether or not data is pending */
1903 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
,
1904 &pending_ret_byte
, 1);
1913 case LTTNG_SNAPSHOT_ADD_OUTPUT
:
1915 uint32_t snapshot_id
;
1916 struct lttcomm_lttng_output_id reply
;
1918 ret
= cmd_snapshot_add_output(cmd_ctx
->session
,
1919 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
),
1921 if (ret
!= LTTNG_OK
) {
1924 reply
.id
= snapshot_id
;
1926 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &reply
,
1932 /* Copy output list into message payload */
1936 case LTTNG_SNAPSHOT_DEL_OUTPUT
:
1938 ret
= cmd_snapshot_del_output(cmd_ctx
->session
,
1939 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_output
.output
));
1942 case LTTNG_SNAPSHOT_LIST_OUTPUT
:
1945 struct lttng_snapshot_output
*outputs
= NULL
;
1947 nb_output
= cmd_snapshot_list_outputs(cmd_ctx
->session
, &outputs
);
1948 if (nb_output
< 0) {
1953 assert((nb_output
> 0 && outputs
) || nb_output
== 0);
1954 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, outputs
,
1955 nb_output
* sizeof(struct lttng_snapshot_output
));
1965 case LTTNG_SNAPSHOT_RECORD
:
1967 ret
= cmd_snapshot_record(cmd_ctx
->session
,
1968 ALIGNED_CONST_PTR(cmd_ctx
->lsm
.u
.snapshot_record
.output
),
1969 cmd_ctx
->lsm
.u
.snapshot_record
.wait
);
1972 case LTTNG_CREATE_SESSION_EXT
:
1974 struct lttng_dynamic_buffer payload
;
1975 struct lttng_session_descriptor
*return_descriptor
= NULL
;
1977 lttng_dynamic_buffer_init(&payload
);
1978 ret
= cmd_create_session(cmd_ctx
, *sock
, &return_descriptor
);
1979 if (ret
!= LTTNG_OK
) {
1983 ret
= lttng_session_descriptor_serialize(return_descriptor
,
1986 ERR("Failed to serialize session descriptor in reply to \"create session\" command");
1987 lttng_session_descriptor_destroy(return_descriptor
);
1988 ret
= LTTNG_ERR_NOMEM
;
1991 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, payload
.data
,
1994 lttng_session_descriptor_destroy(return_descriptor
);
1995 ret
= LTTNG_ERR_NOMEM
;
1998 lttng_dynamic_buffer_reset(&payload
);
1999 lttng_session_descriptor_destroy(return_descriptor
);
2003 case LTTNG_SAVE_SESSION
:
2005 ret
= cmd_save_sessions(&cmd_ctx
->lsm
.u
.save_session
.attr
,
2009 case LTTNG_SET_SESSION_SHM_PATH
:
2011 ret
= cmd_set_session_shm_path(cmd_ctx
->session
,
2012 cmd_ctx
->lsm
.u
.set_shm_path
.shm_path
);
2015 case LTTNG_REGENERATE_METADATA
:
2017 ret
= cmd_regenerate_metadata(cmd_ctx
->session
);
2020 case LTTNG_REGENERATE_STATEDUMP
:
2022 ret
= cmd_regenerate_statedump(cmd_ctx
->session
);
2025 case LTTNG_REGISTER_TRIGGER
:
2027 ret
= cmd_register_trigger(cmd_ctx
, *sock
,
2028 notification_thread_handle
);
2031 case LTTNG_UNREGISTER_TRIGGER
:
2033 ret
= cmd_unregister_trigger(cmd_ctx
, *sock
,
2034 notification_thread_handle
);
2037 case LTTNG_ROTATE_SESSION
:
2039 struct lttng_rotate_session_return rotate_return
;
2041 DBG("Client rotate session \"%s\"", cmd_ctx
->session
->name
);
2043 memset(&rotate_return
, 0, sizeof(rotate_return
));
2044 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2045 DBG("Kernel tracer version is not compatible with the rotation feature");
2046 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2050 ret
= cmd_rotate_session(cmd_ctx
->session
, &rotate_return
,
2052 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED
);
2058 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &rotate_return
,
2059 sizeof(rotate_return
));
2068 case LTTNG_ROTATION_GET_INFO
:
2070 struct lttng_rotation_get_info_return get_info_return
;
2072 memset(&get_info_return
, 0, sizeof(get_info_return
));
2073 ret
= cmd_rotate_get_info(cmd_ctx
->session
, &get_info_return
,
2074 cmd_ctx
->lsm
.u
.get_rotation_info
.rotation_id
);
2080 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &get_info_return
,
2081 sizeof(get_info_return
));
2090 case LTTNG_ROTATION_SET_SCHEDULE
:
2093 enum lttng_rotation_schedule_type schedule_type
;
2096 if (cmd_ctx
->session
->kernel_session
&& !check_rotate_compatible()) {
2097 DBG("Kernel tracer version does not support session rotations");
2098 ret
= LTTNG_ERR_ROTATION_WRONG_VERSION
;
2102 set_schedule
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.set
== 1;
2103 schedule_type
= (enum lttng_rotation_schedule_type
) cmd_ctx
->lsm
.u
.rotation_set_schedule
.type
;
2104 value
= cmd_ctx
->lsm
.u
.rotation_set_schedule
.value
;
2106 ret
= cmd_rotation_set_schedule(cmd_ctx
->session
,
2110 notification_thread_handle
);
2111 if (ret
!= LTTNG_OK
) {
2117 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES
:
2119 struct lttng_session_list_schedules_return schedules
= {
2120 .periodic
.set
= !!cmd_ctx
->session
->rotate_timer_period
,
2121 .periodic
.value
= cmd_ctx
->session
->rotate_timer_period
,
2122 .size
.set
= !!cmd_ctx
->session
->rotate_size
,
2123 .size
.value
= cmd_ctx
->session
->rotate_size
,
2126 ret
= setup_lttng_msg_no_cmd_header(cmd_ctx
, &schedules
,
2136 case LTTNG_CLEAR_SESSION
:
2138 ret
= cmd_clear_session(cmd_ctx
->session
, sock
);
2142 ret
= LTTNG_ERR_UND
;
2147 if (cmd_ctx
->reply_payload
.buffer
.size
== 0) {
2148 DBG("Missing llm header, creating one.");
2149 if (setup_lttng_msg_no_cmd_header(cmd_ctx
, NULL
, 0) < 0) {
2153 /* Set return code */
2154 ((struct lttcomm_lttng_msg
*) (cmd_ctx
->reply_payload
.buffer
.data
))->ret_code
= ret
;
2156 if (cmd_ctx
->session
) {
2157 session_unlock(cmd_ctx
->session
);
2158 session_put(cmd_ctx
->session
);
2159 cmd_ctx
->session
= NULL
;
2161 if (need_tracing_session
) {
2162 session_unlock_list();
2165 assert(!rcu_read_ongoing());
2169 static int create_client_sock(void)
2171 int ret
, client_sock
;
2172 const mode_t old_umask
= umask(0);
2174 /* Create client tool unix socket */
2175 client_sock
= lttcomm_create_unix_sock(config
.client_unix_sock_path
.value
);
2176 if (client_sock
< 0) {
2177 ERR("Create unix sock failed: %s", config
.client_unix_sock_path
.value
);
2182 /* Set the cloexec flag */
2183 ret
= utils_set_fd_cloexec(client_sock
);
2185 ERR("Unable to set CLOEXEC flag to the client Unix socket (fd: %d). "
2186 "Continuing but note that the consumer daemon will have a "
2187 "reference to this socket on exec()", client_sock
);
2190 /* File permission MUST be 660 */
2191 ret
= chmod(config
.client_unix_sock_path
.value
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
2193 ERR("Set file permissions failed: %s",
2194 config
.client_unix_sock_path
.value
);
2196 (void) lttcomm_close_unix_sock(client_sock
);
2200 DBG("Created client socket (fd = %i)", client_sock
);
2207 static void cleanup_client_thread(void *data
)
2209 struct lttng_pipe
*quit_pipe
= data
;
2211 lttng_pipe_destroy(quit_pipe
);
2214 static void thread_init_cleanup(void *data
)
2216 set_thread_status(false);
2220 * This thread manage all clients request using the unix client socket for
2223 static void *thread_manage_clients(void *data
)
2225 int sock
= -1, ret
, i
, pollfd
, err
= -1;
2227 uint32_t revents
, nb_fd
;
2228 struct lttng_poll_event events
;
2229 const int client_sock
= thread_state
.client_sock
;
2230 struct lttng_pipe
*quit_pipe
= data
;
2231 const int thread_quit_pipe_fd
= lttng_pipe_get_readfd(quit_pipe
);
2232 struct command_ctx cmd_ctx
= {};
2234 DBG("[thread] Manage client started");
2236 lttng_payload_init(&cmd_ctx
.reply_payload
);
2238 is_root
= (getuid() == 0);
2240 pthread_cleanup_push(thread_init_cleanup
, NULL
);
2242 rcu_register_thread();
2244 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_CMD
);
2246 health_code_update();
2248 ret
= lttcomm_listen_unix_sock(client_sock
);
2254 * Pass 2 as size here for the thread quit pipe and client_sock. Nothing
2255 * more will be added to this poll set.
2257 ret
= lttng_poll_create(&events
, 2, LTTNG_CLOEXEC
);
2259 goto error_create_poll
;
2262 /* Add the application registration socket */
2263 ret
= lttng_poll_add(&events
, client_sock
, LPOLLIN
| LPOLLPRI
);
2268 /* Add thread quit pipe */
2269 ret
= lttng_poll_add(&events
, thread_quit_pipe_fd
, LPOLLIN
| LPOLLERR
);
2274 /* Set state as running. */
2275 set_thread_status(true);
2276 pthread_cleanup_pop(0);
2278 /* This testpoint is after we signal readiness to the parent. */
2279 if (testpoint(sessiond_thread_manage_clients
)) {
2283 if (testpoint(sessiond_thread_manage_clients_before_loop
)) {
2287 health_code_update();
2290 const struct cmd_completion_handler
*cmd_completion_handler
;
2292 cmd_ctx
.creds
= (lttng_sock_cred
) {
2296 cmd_ctx
.session
= NULL
;
2297 lttng_payload_clear(&cmd_ctx
.reply_payload
);
2298 cmd_ctx
.lttng_msg_size
= 0;
2300 DBG("Accepting client command ...");
2302 /* Inifinite blocking call, waiting for transmission */
2304 health_poll_entry();
2305 ret
= lttng_poll_wait(&events
, -1);
2309 * Restart interrupted system call.
2311 if (errno
== EINTR
) {
2319 for (i
= 0; i
< nb_fd
; i
++) {
2320 revents
= LTTNG_POLL_GETEV(&events
, i
);
2321 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2323 health_code_update();
2325 if (pollfd
== thread_quit_pipe_fd
) {
2329 /* Event on the registration socket */
2330 if (revents
& LPOLLIN
) {
2332 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2333 ERR("Client socket poll error");
2336 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2342 DBG("Wait for client response");
2344 health_code_update();
2346 sock
= lttcomm_accept_unix_sock(client_sock
);
2352 * Set the CLOEXEC flag. Return code is useless because either way, the
2355 (void) utils_set_fd_cloexec(sock
);
2357 /* Set socket option for credentials retrieval */
2358 ret
= lttcomm_setsockopt_creds_unix_sock(sock
);
2363 health_code_update();
2366 * Data is received from the lttng client. The struct
2367 * lttcomm_session_msg (lsm) contains the command and data request of
2370 DBG("Receiving data from client ...");
2371 ret
= lttcomm_recv_creds_unix_sock(sock
, &cmd_ctx
.lsm
,
2372 sizeof(struct lttcomm_session_msg
), &cmd_ctx
.creds
);
2373 if (ret
!= sizeof(struct lttcomm_session_msg
)) {
2374 DBG("Incomplete recv() from client... continuing");
2383 health_code_update();
2385 // TODO: Validate cmd_ctx including sanity check for
2386 // security purpose.
2388 rcu_thread_online();
2390 * This function dispatch the work to the kernel or userspace tracer
2391 * libs and fill the lttcomm_lttng_msg data structure of all the needed
2392 * informations for the client. The command context struct contains
2393 * everything this function may needs.
2395 ret
= process_client_msg(&cmd_ctx
, &sock
, &sock_error
);
2396 rcu_thread_offline();
2406 * TODO: Inform client somehow of the fatal error. At
2407 * this point, ret < 0 means that a zmalloc failed
2408 * (ENOMEM). Error detected but still accept
2409 * command, unless a socket error has been
2415 cmd_completion_handler
= cmd_pop_completion_handler();
2416 if (cmd_completion_handler
) {
2417 enum lttng_error_code completion_code
;
2419 completion_code
= cmd_completion_handler
->run(
2420 cmd_completion_handler
->data
);
2421 if (completion_code
!= LTTNG_OK
) {
2426 health_code_update();
2429 struct lttng_payload_view view
=
2430 lttng_payload_view_from_payload(
2431 &cmd_ctx
.reply_payload
,
2433 struct lttcomm_lttng_msg
*llm
= (typeof(
2434 llm
)) cmd_ctx
.reply_payload
.buffer
.data
;
2436 assert(cmd_ctx
.reply_payload
.buffer
.size
>=
2438 assert(cmd_ctx
.lttng_msg_size
== cmd_ctx
.reply_payload
.buffer
.size
);
2440 llm
->fd_count
= lttng_payload_view_get_fd_handle_count(&view
);
2442 DBG("Sending response (size: %d, retcode: %s (%d))",
2443 cmd_ctx
.lttng_msg_size
,
2444 lttng_strerror(-llm
->ret_code
),
2446 ret
= send_unix_sock(sock
, &view
);
2448 ERR("Failed to send data back to client");
2451 /* End of transmission */
2459 health_code_update();
2471 lttng_poll_clean(&events
);
2475 unlink(config
.client_unix_sock_path
.value
);
2476 ret
= close(client_sock
);
2483 ERR("Health error occurred in %s", __func__
);
2486 health_unregister(health_sessiond
);
2488 DBG("Client thread dying");
2489 lttng_payload_reset(&cmd_ctx
.reply_payload
);
2490 rcu_unregister_thread();
2495 bool shutdown_client_thread(void *thread_data
)
2497 struct lttng_pipe
*client_quit_pipe
= thread_data
;
2498 const int write_fd
= lttng_pipe_get_writefd(client_quit_pipe
);
2500 return notify_thread_pipe(write_fd
) == 1;
2503 struct lttng_thread
*launch_client_thread(void)
2505 bool thread_running
;
2506 struct lttng_pipe
*client_quit_pipe
;
2507 struct lttng_thread
*thread
= NULL
;
2508 int client_sock_fd
= -1;
2510 sem_init(&thread_state
.ready
, 0, 0);
2511 client_quit_pipe
= lttng_pipe_open(FD_CLOEXEC
);
2512 if (!client_quit_pipe
) {
2516 client_sock_fd
= create_client_sock();
2517 if (client_sock_fd
< 0) {
2521 thread_state
.client_sock
= client_sock_fd
;
2522 thread
= lttng_thread_create("Client management",
2523 thread_manage_clients
,
2524 shutdown_client_thread
,
2525 cleanup_client_thread
,
2530 /* The client thread now owns the client sock fd and the quit pipe. */
2531 client_sock_fd
= -1;
2532 client_quit_pipe
= NULL
;
2535 * This thread is part of the threads that need to be fully
2536 * initialized before the session daemon is marked as "ready".
2538 thread_running
= wait_thread_status();
2539 if (!thread_running
) {
2544 if (client_sock_fd
>= 0) {
2545 if (close(client_sock_fd
)) {
2546 PERROR("Failed to close client socket");
2549 lttng_thread_put(thread
);
2550 cleanup_client_thread(client_quit_pipe
);