2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <semaphore.h>
30 #include <sys/mount.h>
31 #include <sys/resource.h>
32 #include <sys/socket.h>
34 #include <sys/types.h>
36 #include <urcu/uatomic.h>
40 #include <common/common.h>
41 #include <common/compat/poll.h>
42 #include <common/compat/socket.h>
43 #include <common/defaults.h>
44 #include <common/kernel-consumer/kernel-consumer.h>
45 #include <common/futex.h>
46 #include <common/relayd/relayd.h>
48 #include "lttng-sessiond.h"
54 #include "kernel-consumer.h"
58 #include "ust-consumer.h"
63 #define CONSUMERD_FILE "lttng-consumerd"
66 const char default_home_dir
[] = DEFAULT_HOME_DIR
;
67 const char default_tracing_group
[] = DEFAULT_TRACING_GROUP
;
68 const char default_ust_sock_dir
[] = DEFAULT_UST_SOCK_DIR
;
69 const char default_global_apps_pipe
[] = DEFAULT_GLOBAL_APPS_PIPE
;
72 const char *opt_tracing_group
;
73 static int opt_sig_parent
;
74 static int opt_verbose_consumer
;
75 static int opt_daemon
;
76 static int opt_no_kernel
;
77 static int is_root
; /* Set to 1 if the daemon is running as root */
78 static pid_t ppid
; /* Parent PID for --sig-parent option */
81 /* Consumer daemon specific control data */
82 static struct consumer_data kconsumer_data
= {
83 .type
= LTTNG_CONSUMER_KERNEL
,
84 .err_unix_sock_path
= DEFAULT_KCONSUMERD_ERR_SOCK_PATH
,
85 .cmd_unix_sock_path
= DEFAULT_KCONSUMERD_CMD_SOCK_PATH
,
89 static struct consumer_data ustconsumer64_data
= {
90 .type
= LTTNG_CONSUMER64_UST
,
91 .err_unix_sock_path
= DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH
,
92 .cmd_unix_sock_path
= DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH
,
96 static struct consumer_data ustconsumer32_data
= {
97 .type
= LTTNG_CONSUMER32_UST
,
98 .err_unix_sock_path
= DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH
,
99 .cmd_unix_sock_path
= DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH
,
104 static int dispatch_thread_exit
;
106 /* Global application Unix socket path */
107 static char apps_unix_sock_path
[PATH_MAX
];
108 /* Global client Unix socket path */
109 static char client_unix_sock_path
[PATH_MAX
];
110 /* global wait shm path for UST */
111 static char wait_shm_path
[PATH_MAX
];
113 /* Sockets and FDs */
114 static int client_sock
= -1;
115 static int apps_sock
= -1;
116 static int kernel_tracer_fd
= -1;
117 static int kernel_poll_pipe
[2] = { -1, -1 };
120 * Quit pipe for all threads. This permits a single cancellation point
121 * for all threads when receiving an event on the pipe.
123 static int thread_quit_pipe
[2] = { -1, -1 };
126 * This pipe is used to inform the thread managing application communication
127 * that a command is queued and ready to be processed.
129 static int apps_cmd_pipe
[2] = { -1, -1 };
131 /* Pthread, Mutexes and Semaphores */
132 static pthread_t apps_thread
;
133 static pthread_t reg_apps_thread
;
134 static pthread_t client_thread
;
135 static pthread_t kernel_thread
;
136 static pthread_t dispatch_thread
;
139 * UST registration command queue. This queue is tied with a futex and uses a N
140 * wakers / 1 waiter implemented and detailed in futex.c/.h
142 * The thread_manage_apps and thread_dispatch_ust_registration interact with
143 * this queue and the wait/wake scheme.
145 static struct ust_cmd_queue ust_cmd_queue
;
148 * Pointer initialized before thread creation.
150 * This points to the tracing session list containing the session count and a
151 * mutex lock. The lock MUST be taken if you iterate over the list. The lock
152 * MUST NOT be taken if you call a public function in session.c.
154 * The lock is nested inside the structure: session_list_ptr->lock. Please use
155 * session_lock_list and session_unlock_list for lock acquisition.
157 static struct ltt_session_list
*session_list_ptr
;
159 int ust_consumerd64_fd
= -1;
160 int ust_consumerd32_fd
= -1;
162 static const char *consumerd32_bin
= CONFIG_CONSUMERD32_BIN
;
163 static const char *consumerd64_bin
= CONFIG_CONSUMERD64_BIN
;
164 static const char *consumerd32_libdir
= CONFIG_CONSUMERD32_LIBDIR
;
165 static const char *consumerd64_libdir
= CONFIG_CONSUMERD64_LIBDIR
;
168 * Consumer daemon state which is changed when spawning it, killing it or in
169 * case of a fatal error.
171 enum consumerd_state
{
172 CONSUMER_STARTED
= 1,
173 CONSUMER_STOPPED
= 2,
178 * This consumer daemon state is used to validate if a client command will be
179 * able to reach the consumer. If not, the client is informed. For instance,
180 * doing a "lttng start" when the consumer state is set to ERROR will return an
181 * error to the client.
183 * The following example shows a possible race condition of this scheme:
185 * consumer thread error happens
187 * client cmd checks state -> still OK
188 * consumer thread exit, sets error
189 * client cmd try to talk to consumer
192 * However, since the consumer is a different daemon, we have no way of making
193 * sure the command will reach it safely even with this state flag. This is why
194 * we consider that up to the state validation during command processing, the
195 * command is safe. After that, we can not guarantee the correctness of the
196 * client request vis-a-vis the consumer.
198 static enum consumerd_state ust_consumerd_state
;
199 static enum consumerd_state kernel_consumerd_state
;
202 * Used to keep a unique index for each relayd socket created where this value
203 * is associated with streams on the consumer so it can match the right relayd
206 * This value should be incremented atomically for safety purposes and future
207 * possible concurrent access.
209 static unsigned int relayd_net_seq_idx
;
212 void setup_consumerd_path(void)
214 const char *bin
, *libdir
;
217 * Allow INSTALL_BIN_PATH to be used as a target path for the
218 * native architecture size consumer if CONFIG_CONSUMER*_PATH
219 * has not been defined.
221 #if (CAA_BITS_PER_LONG == 32)
222 if (!consumerd32_bin
[0]) {
223 consumerd32_bin
= INSTALL_BIN_PATH
"/" CONSUMERD_FILE
;
225 if (!consumerd32_libdir
[0]) {
226 consumerd32_libdir
= INSTALL_LIB_PATH
;
228 #elif (CAA_BITS_PER_LONG == 64)
229 if (!consumerd64_bin
[0]) {
230 consumerd64_bin
= INSTALL_BIN_PATH
"/" CONSUMERD_FILE
;
232 if (!consumerd64_libdir
[0]) {
233 consumerd64_libdir
= INSTALL_LIB_PATH
;
236 #error "Unknown bitness"
240 * runtime env. var. overrides the build default.
242 bin
= getenv("LTTNG_CONSUMERD32_BIN");
244 consumerd32_bin
= bin
;
246 bin
= getenv("LTTNG_CONSUMERD64_BIN");
248 consumerd64_bin
= bin
;
250 libdir
= getenv("LTTNG_CONSUMERD32_LIBDIR");
252 consumerd32_libdir
= libdir
;
254 libdir
= getenv("LTTNG_CONSUMERD64_LIBDIR");
256 consumerd64_libdir
= libdir
;
261 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
263 static int create_thread_poll_set(struct lttng_poll_event
*events
,
268 if (events
== NULL
|| size
== 0) {
273 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
279 ret
= lttng_poll_add(events
, thread_quit_pipe
[0], LPOLLIN
);
291 * Check if the thread quit pipe was triggered.
293 * Return 1 if it was triggered else 0;
295 static int check_thread_quit_pipe(int fd
, uint32_t events
)
297 if (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
)) {
305 * Return group ID of the tracing group or -1 if not found.
307 static gid_t
allowed_group(void)
311 if (opt_tracing_group
) {
312 grp
= getgrnam(opt_tracing_group
);
314 grp
= getgrnam(default_tracing_group
);
324 * Init thread quit pipe.
326 * Return -1 on error or 0 if all pipes are created.
328 static int init_thread_quit_pipe(void)
332 ret
= pipe(thread_quit_pipe
);
334 PERROR("thread quit pipe");
338 for (i
= 0; i
< 2; i
++) {
339 ret
= fcntl(thread_quit_pipe
[i
], F_SETFD
, FD_CLOEXEC
);
351 * Complete teardown of a kernel session. This free all data structure related
352 * to a kernel session and update counter.
354 static void teardown_kernel_session(struct ltt_session
*session
)
356 if (!session
->kernel_session
) {
357 DBG3("No kernel session when tearing down session");
361 DBG("Tearing down kernel session");
364 * If a custom kernel consumer was registered, close the socket before
365 * tearing down the complete kernel session structure
367 if (kconsumer_data
.cmd_sock
>= 0 &&
368 session
->kernel_session
->consumer_fd
!= kconsumer_data
.cmd_sock
) {
369 lttcomm_close_unix_sock(session
->kernel_session
->consumer_fd
);
372 trace_kernel_destroy_session(session
->kernel_session
);
376 * Complete teardown of all UST sessions. This will free everything on his path
377 * and destroy the core essence of all ust sessions :)
379 static void teardown_ust_session(struct ltt_session
*session
)
383 if (!session
->ust_session
) {
384 DBG3("No UST session when tearing down session");
388 DBG("Tearing down UST session(s)");
390 ret
= ust_app_destroy_trace_all(session
->ust_session
);
392 ERR("Error in ust_app_destroy_trace_all");
395 trace_ust_destroy_session(session
->ust_session
);
399 * Stop all threads by closing the thread quit pipe.
401 static void stop_threads(void)
405 /* Stopping all threads */
406 DBG("Terminating all threads");
407 ret
= notify_thread_pipe(thread_quit_pipe
[1]);
409 ERR("write error on thread quit pipe");
412 /* Dispatch thread */
413 dispatch_thread_exit
= 1;
414 futex_nto1_wake(&ust_cmd_queue
.futex
);
420 static void cleanup(void)
424 struct ltt_session
*sess
, *stmp
;
428 DBG("Removing %s directory", rundir
);
429 ret
= asprintf(&cmd
, "rm -rf %s", rundir
);
431 ERR("asprintf failed. Something is really wrong!");
434 /* Remove lttng run directory */
437 ERR("Unable to clean %s", rundir
);
441 DBG("Cleaning up all sessions");
443 /* Destroy session list mutex */
444 if (session_list_ptr
!= NULL
) {
445 pthread_mutex_destroy(&session_list_ptr
->lock
);
447 /* Cleanup ALL session */
448 cds_list_for_each_entry_safe(sess
, stmp
,
449 &session_list_ptr
->head
, list
) {
450 teardown_kernel_session(sess
);
451 teardown_ust_session(sess
);
456 DBG("Closing all UST sockets");
457 ust_app_clean_list();
459 pthread_mutex_destroy(&kconsumer_data
.pid_mutex
);
461 if (is_root
&& !opt_no_kernel
) {
462 DBG2("Closing kernel fd");
463 if (kernel_tracer_fd
>= 0) {
464 ret
= close(kernel_tracer_fd
);
469 DBG("Unloading kernel modules");
470 modprobe_remove_lttng_all();
472 utils_close_pipe(kernel_poll_pipe
);
473 utils_close_pipe(thread_quit_pipe
);
474 utils_close_pipe(apps_cmd_pipe
);
477 DBG("%c[%d;%dm*** assert failed :-) *** ==> %c[%dm%c[%d;%dm"
478 "Matthew, BEET driven development works!%c[%dm",
479 27, 1, 31, 27, 0, 27, 1, 33, 27, 0);
484 * Send data on a unix socket using the liblttsessiondcomm API.
486 * Return lttcomm error code.
488 static int send_unix_sock(int sock
, void *buf
, size_t len
)
490 /* Check valid length */
495 return lttcomm_send_unix_sock(sock
, buf
, len
);
499 * Free memory of a command context structure.
501 static void clean_command_ctx(struct command_ctx
**cmd_ctx
)
503 DBG("Clean command context structure");
505 if ((*cmd_ctx
)->llm
) {
506 free((*cmd_ctx
)->llm
);
508 if ((*cmd_ctx
)->lsm
) {
509 free((*cmd_ctx
)->lsm
);
517 * Notify UST applications using the shm mmap futex.
519 static int notify_ust_apps(int active
)
523 DBG("Notifying applications of session daemon state: %d", active
);
525 /* See shm.c for this call implying mmap, shm and futex calls */
526 wait_shm_mmap
= shm_ust_get_mmap(wait_shm_path
, is_root
);
527 if (wait_shm_mmap
== NULL
) {
531 /* Wake waiting process */
532 futex_wait_update((int32_t *) wait_shm_mmap
, active
);
534 /* Apps notified successfully */
542 * Setup the outgoing data buffer for the response (llm) by allocating the
543 * right amount of memory and copying the original information from the lsm
546 * Return total size of the buffer pointed by buf.
548 static int setup_lttng_msg(struct command_ctx
*cmd_ctx
, size_t size
)
554 cmd_ctx
->llm
= zmalloc(sizeof(struct lttcomm_lttng_msg
) + buf_size
);
555 if (cmd_ctx
->llm
== NULL
) {
561 /* Copy common data */
562 cmd_ctx
->llm
->cmd_type
= cmd_ctx
->lsm
->cmd_type
;
563 cmd_ctx
->llm
->pid
= cmd_ctx
->lsm
->domain
.attr
.pid
;
565 cmd_ctx
->llm
->data_size
= size
;
566 cmd_ctx
->lttng_msg_size
= sizeof(struct lttcomm_lttng_msg
) + buf_size
;
575 * Update the kernel poll set of all channel fd available over all tracing
576 * session. Add the wakeup pipe at the end of the set.
578 static int update_kernel_poll(struct lttng_poll_event
*events
)
581 struct ltt_session
*session
;
582 struct ltt_kernel_channel
*channel
;
584 DBG("Updating kernel poll set");
587 cds_list_for_each_entry(session
, &session_list_ptr
->head
, list
) {
588 session_lock(session
);
589 if (session
->kernel_session
== NULL
) {
590 session_unlock(session
);
594 cds_list_for_each_entry(channel
,
595 &session
->kernel_session
->channel_list
.head
, list
) {
596 /* Add channel fd to the kernel poll set */
597 ret
= lttng_poll_add(events
, channel
->fd
, LPOLLIN
| LPOLLRDNORM
);
599 session_unlock(session
);
602 DBG("Channel fd %d added to kernel set", channel
->fd
);
604 session_unlock(session
);
606 session_unlock_list();
611 session_unlock_list();
616 * Find the channel fd from 'fd' over all tracing session. When found, check
617 * for new channel stream and send those stream fds to the kernel consumer.
619 * Useful for CPU hotplug feature.
621 static int update_kernel_stream(struct consumer_data
*consumer_data
, int fd
)
624 struct ltt_session
*session
;
625 struct ltt_kernel_channel
*channel
;
627 DBG("Updating kernel streams for channel fd %d", fd
);
630 cds_list_for_each_entry(session
, &session_list_ptr
->head
, list
) {
631 session_lock(session
);
632 if (session
->kernel_session
== NULL
) {
633 session_unlock(session
);
637 /* This is not suppose to be -1 but this is an extra security check */
638 if (session
->kernel_session
->consumer_fd
< 0) {
639 session
->kernel_session
->consumer_fd
= consumer_data
->cmd_sock
;
642 cds_list_for_each_entry(channel
,
643 &session
->kernel_session
->channel_list
.head
, list
) {
644 if (channel
->fd
== fd
) {
645 DBG("Channel found, updating kernel streams");
646 ret
= kernel_open_channel_stream(channel
);
652 * Have we already sent fds to the consumer? If yes, it means
653 * that tracing is started so it is safe to send our updated
656 if (session
->kernel_session
->consumer_fds_sent
== 1 &&
657 session
->kernel_session
->consumer
!= NULL
) {
658 ret
= kernel_consumer_send_channel_stream(
659 session
->kernel_session
->consumer_fd
, channel
,
660 session
->kernel_session
);
668 session_unlock(session
);
670 session_unlock_list();
674 session_unlock(session
);
675 session_unlock_list();
680 * For each tracing session, update newly registered apps.
682 static void update_ust_app(int app_sock
)
684 struct ltt_session
*sess
, *stmp
;
688 /* For all tracing session(s) */
689 cds_list_for_each_entry_safe(sess
, stmp
, &session_list_ptr
->head
, list
) {
691 if (sess
->ust_session
) {
692 ust_app_global_update(sess
->ust_session
, app_sock
);
694 session_unlock(sess
);
697 session_unlock_list();
701 * This thread manage event coming from the kernel.
703 * Features supported in this thread:
706 static void *thread_manage_kernel(void *data
)
708 int ret
, i
, pollfd
, update_poll_flag
= 1;
709 uint32_t revents
, nb_fd
;
711 struct lttng_poll_event events
;
713 DBG("Thread manage kernel started");
715 ret
= create_thread_poll_set(&events
, 2);
717 goto error_poll_create
;
720 ret
= lttng_poll_add(&events
, kernel_poll_pipe
[0], LPOLLIN
);
726 if (update_poll_flag
== 1) {
728 * Reset number of fd in the poll set. Always 2 since there is the thread
729 * quit pipe and the kernel pipe.
733 ret
= update_kernel_poll(&events
);
737 update_poll_flag
= 0;
740 nb_fd
= LTTNG_POLL_GETNB(&events
);
742 DBG("Thread kernel polling on %d fds", nb_fd
);
744 /* Zeroed the poll events */
745 lttng_poll_reset(&events
);
747 /* Poll infinite value of time */
749 ret
= lttng_poll_wait(&events
, -1);
752 * Restart interrupted system call.
754 if (errno
== EINTR
) {
758 } else if (ret
== 0) {
759 /* Should not happen since timeout is infinite */
760 ERR("Return value of poll is 0 with an infinite timeout.\n"
761 "This should not have happened! Continuing...");
765 for (i
= 0; i
< nb_fd
; i
++) {
766 /* Fetch once the poll data */
767 revents
= LTTNG_POLL_GETEV(&events
, i
);
768 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
770 /* Thread quit pipe has been closed. Killing thread. */
771 ret
= check_thread_quit_pipe(pollfd
, revents
);
776 /* Check for data on kernel pipe */
777 if (pollfd
== kernel_poll_pipe
[0] && (revents
& LPOLLIN
)) {
778 ret
= read(kernel_poll_pipe
[0], &tmp
, 1);
779 update_poll_flag
= 1;
783 * New CPU detected by the kernel. Adding kernel stream to
784 * kernel session and updating the kernel consumer
786 if (revents
& LPOLLIN
) {
787 ret
= update_kernel_stream(&kconsumer_data
, pollfd
);
793 * TODO: We might want to handle the LPOLLERR | LPOLLHUP
794 * and unregister kernel stream at this point.
802 lttng_poll_clean(&events
);
804 DBG("Kernel thread dying");
809 * This thread manage the consumer error sent back to the session daemon.
811 static void *thread_manage_consumer(void *data
)
813 int sock
= -1, i
, ret
, pollfd
;
814 uint32_t revents
, nb_fd
;
815 enum lttcomm_return_code code
;
816 struct lttng_poll_event events
;
817 struct consumer_data
*consumer_data
= data
;
819 DBG("[thread] Manage consumer started");
821 ret
= lttcomm_listen_unix_sock(consumer_data
->err_sock
);
827 * Pass 2 as size here for the thread quit pipe and kconsumerd_err_sock.
828 * Nothing more will be added to this poll set.
830 ret
= create_thread_poll_set(&events
, 2);
835 ret
= lttng_poll_add(&events
, consumer_data
->err_sock
, LPOLLIN
| LPOLLRDHUP
);
840 nb_fd
= LTTNG_POLL_GETNB(&events
);
842 /* Inifinite blocking call, waiting for transmission */
844 ret
= lttng_poll_wait(&events
, -1);
847 * Restart interrupted system call.
849 if (errno
== EINTR
) {
855 for (i
= 0; i
< nb_fd
; i
++) {
856 /* Fetch once the poll data */
857 revents
= LTTNG_POLL_GETEV(&events
, i
);
858 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
860 /* Thread quit pipe has been closed. Killing thread. */
861 ret
= check_thread_quit_pipe(pollfd
, revents
);
866 /* Event on the registration socket */
867 if (pollfd
== consumer_data
->err_sock
) {
868 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
869 ERR("consumer err socket poll error");
875 sock
= lttcomm_accept_unix_sock(consumer_data
->err_sock
);
880 DBG2("Receiving code from consumer err_sock");
882 /* Getting status code from kconsumerd */
883 ret
= lttcomm_recv_unix_sock(sock
, &code
,
884 sizeof(enum lttcomm_return_code
));
889 if (code
== CONSUMERD_COMMAND_SOCK_READY
) {
890 consumer_data
->cmd_sock
=
891 lttcomm_connect_unix_sock(consumer_data
->cmd_unix_sock_path
);
892 if (consumer_data
->cmd_sock
< 0) {
893 sem_post(&consumer_data
->sem
);
894 PERROR("consumer connect");
897 /* Signal condition to tell that the kconsumerd is ready */
898 sem_post(&consumer_data
->sem
);
899 DBG("consumer command socket ready");
901 ERR("consumer error when waiting for SOCK_READY : %s",
902 lttcomm_get_readable_code(-code
));
906 /* Remove the kconsumerd error sock since we've established a connexion */
907 ret
= lttng_poll_del(&events
, consumer_data
->err_sock
);
912 ret
= lttng_poll_add(&events
, sock
, LPOLLIN
| LPOLLRDHUP
);
917 /* Update number of fd */
918 nb_fd
= LTTNG_POLL_GETNB(&events
);
920 /* Inifinite blocking call, waiting for transmission */
922 ret
= lttng_poll_wait(&events
, -1);
925 * Restart interrupted system call.
927 if (errno
== EINTR
) {
933 for (i
= 0; i
< nb_fd
; i
++) {
934 /* Fetch once the poll data */
935 revents
= LTTNG_POLL_GETEV(&events
, i
);
936 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
938 /* Thread quit pipe has been closed. Killing thread. */
939 ret
= check_thread_quit_pipe(pollfd
, revents
);
944 /* Event on the kconsumerd socket */
945 if (pollfd
== sock
) {
946 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
947 ERR("consumer err socket second poll error");
953 /* Wait for any kconsumerd error */
954 ret
= lttcomm_recv_unix_sock(sock
, &code
,
955 sizeof(enum lttcomm_return_code
));
957 ERR("consumer closed the command socket");
961 ERR("consumer return code : %s", lttcomm_get_readable_code(-code
));
964 /* Immediately set the consumerd state to stopped */
965 if (consumer_data
->type
== LTTNG_CONSUMER_KERNEL
) {
966 uatomic_set(&kernel_consumerd_state
, CONSUMER_ERROR
);
967 } else if (consumer_data
->type
== LTTNG_CONSUMER64_UST
||
968 consumer_data
->type
== LTTNG_CONSUMER32_UST
) {
969 uatomic_set(&ust_consumerd_state
, CONSUMER_ERROR
);
971 /* Code flow error... */
975 if (consumer_data
->err_sock
>= 0) {
976 ret
= close(consumer_data
->err_sock
);
981 if (consumer_data
->cmd_sock
>= 0) {
982 ret
= close(consumer_data
->cmd_sock
);
994 unlink(consumer_data
->err_unix_sock_path
);
995 unlink(consumer_data
->cmd_unix_sock_path
);
996 consumer_data
->pid
= 0;
998 lttng_poll_clean(&events
);
1001 DBG("consumer thread cleanup completed");
1007 * This thread manage application communication.
1009 static void *thread_manage_apps(void *data
)
1012 uint32_t revents
, nb_fd
;
1013 struct ust_command ust_cmd
;
1014 struct lttng_poll_event events
;
1016 DBG("[thread] Manage application started");
1018 rcu_register_thread();
1019 rcu_thread_online();
1021 ret
= create_thread_poll_set(&events
, 2);
1023 goto error_poll_create
;
1026 ret
= lttng_poll_add(&events
, apps_cmd_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
1032 /* Zeroed the events structure */
1033 lttng_poll_reset(&events
);
1035 nb_fd
= LTTNG_POLL_GETNB(&events
);
1037 DBG("Apps thread polling on %d fds", nb_fd
);
1039 /* Inifinite blocking call, waiting for transmission */
1041 ret
= lttng_poll_wait(&events
, -1);
1044 * Restart interrupted system call.
1046 if (errno
== EINTR
) {
1052 for (i
= 0; i
< nb_fd
; i
++) {
1053 /* Fetch once the poll data */
1054 revents
= LTTNG_POLL_GETEV(&events
, i
);
1055 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1057 /* Thread quit pipe has been closed. Killing thread. */
1058 ret
= check_thread_quit_pipe(pollfd
, revents
);
1063 /* Inspect the apps cmd pipe */
1064 if (pollfd
== apps_cmd_pipe
[0]) {
1065 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1066 ERR("Apps command pipe error");
1068 } else if (revents
& LPOLLIN
) {
1070 ret
= read(apps_cmd_pipe
[0], &ust_cmd
, sizeof(ust_cmd
));
1071 if (ret
< 0 || ret
< sizeof(ust_cmd
)) {
1072 PERROR("read apps cmd pipe");
1076 /* Register applicaton to the session daemon */
1077 ret
= ust_app_register(&ust_cmd
.reg_msg
,
1079 if (ret
== -ENOMEM
) {
1081 } else if (ret
< 0) {
1086 * Validate UST version compatibility.
1088 ret
= ust_app_validate_version(ust_cmd
.sock
);
1091 * Add channel(s) and event(s) to newly registered apps
1092 * from lttng global UST domain.
1094 update_ust_app(ust_cmd
.sock
);
1097 ret
= ust_app_register_done(ust_cmd
.sock
);
1100 * If the registration is not possible, we simply
1101 * unregister the apps and continue
1103 ust_app_unregister(ust_cmd
.sock
);
1106 * We just need here to monitor the close of the UST
1107 * socket and poll set monitor those by default.
1108 * Listen on POLLIN (even if we never expect any
1109 * data) to ensure that hangup wakes us.
1111 ret
= lttng_poll_add(&events
, ust_cmd
.sock
, LPOLLIN
);
1116 DBG("Apps with sock %d added to poll set",
1124 * At this point, we know that a registered application made
1125 * the event at poll_wait.
1127 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1128 /* Removing from the poll set */
1129 ret
= lttng_poll_del(&events
, pollfd
);
1134 /* Socket closed on remote end. */
1135 ust_app_unregister(pollfd
);
1143 lttng_poll_clean(&events
);
1145 DBG("Application communication apps thread cleanup complete");
1146 rcu_thread_offline();
1147 rcu_unregister_thread();
1152 * Dispatch request from the registration threads to the application
1153 * communication thread.
1155 static void *thread_dispatch_ust_registration(void *data
)
1158 struct cds_wfq_node
*node
;
1159 struct ust_command
*ust_cmd
= NULL
;
1161 DBG("[thread] Dispatch UST command started");
1163 while (!dispatch_thread_exit
) {
1164 /* Atomically prepare the queue futex */
1165 futex_nto1_prepare(&ust_cmd_queue
.futex
);
1168 /* Dequeue command for registration */
1169 node
= cds_wfq_dequeue_blocking(&ust_cmd_queue
.queue
);
1171 DBG("Woken up but nothing in the UST command queue");
1172 /* Continue thread execution */
1176 ust_cmd
= caa_container_of(node
, struct ust_command
, node
);
1178 DBG("Dispatching UST registration pid:%d ppid:%d uid:%d"
1179 " gid:%d sock:%d name:%s (version %d.%d)",
1180 ust_cmd
->reg_msg
.pid
, ust_cmd
->reg_msg
.ppid
,
1181 ust_cmd
->reg_msg
.uid
, ust_cmd
->reg_msg
.gid
,
1182 ust_cmd
->sock
, ust_cmd
->reg_msg
.name
,
1183 ust_cmd
->reg_msg
.major
, ust_cmd
->reg_msg
.minor
);
1185 * Inform apps thread of the new application registration. This
1186 * call is blocking so we can be assured that the data will be read
1187 * at some point in time or wait to the end of the world :)
1189 ret
= write(apps_cmd_pipe
[1], ust_cmd
,
1190 sizeof(struct ust_command
));
1192 PERROR("write apps cmd pipe");
1193 if (errno
== EBADF
) {
1195 * We can't inform the application thread to process
1196 * registration. We will exit or else application
1197 * registration will not occur and tracing will never
1204 } while (node
!= NULL
);
1206 /* Futex wait on queue. Blocking call on futex() */
1207 futex_nto1_wait(&ust_cmd_queue
.futex
);
1211 DBG("Dispatch thread dying");
1216 * This thread manage application registration.
1218 static void *thread_registration_apps(void *data
)
1220 int sock
= -1, i
, ret
, pollfd
;
1221 uint32_t revents
, nb_fd
;
1222 struct lttng_poll_event events
;
1224 * Get allocated in this thread, enqueued to a global queue, dequeued and
1225 * freed in the manage apps thread.
1227 struct ust_command
*ust_cmd
= NULL
;
1229 DBG("[thread] Manage application registration started");
1231 ret
= lttcomm_listen_unix_sock(apps_sock
);
1237 * Pass 2 as size here for the thread quit pipe and apps socket. Nothing
1238 * more will be added to this poll set.
1240 ret
= create_thread_poll_set(&events
, 2);
1242 goto error_create_poll
;
1245 /* Add the application registration socket */
1246 ret
= lttng_poll_add(&events
, apps_sock
, LPOLLIN
| LPOLLRDHUP
);
1248 goto error_poll_add
;
1251 /* Notify all applications to register */
1252 ret
= notify_ust_apps(1);
1254 ERR("Failed to notify applications or create the wait shared memory.\n"
1255 "Execution continues but there might be problem for already\n"
1256 "running applications that wishes to register.");
1260 DBG("Accepting application registration");
1262 nb_fd
= LTTNG_POLL_GETNB(&events
);
1264 /* Inifinite blocking call, waiting for transmission */
1266 ret
= lttng_poll_wait(&events
, -1);
1269 * Restart interrupted system call.
1271 if (errno
== EINTR
) {
1277 for (i
= 0; i
< nb_fd
; i
++) {
1278 /* Fetch once the poll data */
1279 revents
= LTTNG_POLL_GETEV(&events
, i
);
1280 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1282 /* Thread quit pipe has been closed. Killing thread. */
1283 ret
= check_thread_quit_pipe(pollfd
, revents
);
1288 /* Event on the registration socket */
1289 if (pollfd
== apps_sock
) {
1290 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1291 ERR("Register apps socket poll error");
1293 } else if (revents
& LPOLLIN
) {
1294 sock
= lttcomm_accept_unix_sock(apps_sock
);
1299 /* Create UST registration command for enqueuing */
1300 ust_cmd
= zmalloc(sizeof(struct ust_command
));
1301 if (ust_cmd
== NULL
) {
1302 PERROR("ust command zmalloc");
1307 * Using message-based transmissions to ensure we don't
1308 * have to deal with partially received messages.
1310 ret
= lttng_fd_get(LTTNG_FD_APPS
, 1);
1312 ERR("Exhausted file descriptors allowed for applications.");
1321 ret
= lttcomm_recv_unix_sock(sock
, &ust_cmd
->reg_msg
,
1322 sizeof(struct ust_register_msg
));
1323 if (ret
< 0 || ret
< sizeof(struct ust_register_msg
)) {
1325 PERROR("lttcomm_recv_unix_sock register apps");
1327 ERR("Wrong size received on apps register");
1334 lttng_fd_put(LTTNG_FD_APPS
, 1);
1339 ust_cmd
->sock
= sock
;
1342 DBG("UST registration received with pid:%d ppid:%d uid:%d"
1343 " gid:%d sock:%d name:%s (version %d.%d)",
1344 ust_cmd
->reg_msg
.pid
, ust_cmd
->reg_msg
.ppid
,
1345 ust_cmd
->reg_msg
.uid
, ust_cmd
->reg_msg
.gid
,
1346 ust_cmd
->sock
, ust_cmd
->reg_msg
.name
,
1347 ust_cmd
->reg_msg
.major
, ust_cmd
->reg_msg
.minor
);
1350 * Lock free enqueue the registration request. The red pill
1351 * has been taken! This apps will be part of the *system*.
1353 cds_wfq_enqueue(&ust_cmd_queue
.queue
, &ust_cmd
->node
);
1356 * Wake the registration queue futex. Implicit memory
1357 * barrier with the exchange in cds_wfq_enqueue.
1359 futex_nto1_wake(&ust_cmd_queue
.futex
);
1366 /* Notify that the registration thread is gone */
1369 if (apps_sock
>= 0) {
1370 ret
= close(apps_sock
);
1380 lttng_fd_put(LTTNG_FD_APPS
, 1);
1382 unlink(apps_unix_sock_path
);
1385 lttng_poll_clean(&events
);
1388 DBG("UST Registration thread cleanup complete");
1394 * Start the thread_manage_consumer. This must be done after a lttng-consumerd
1395 * exec or it will fails.
1397 static int spawn_consumer_thread(struct consumer_data
*consumer_data
)
1400 struct timespec timeout
;
1402 timeout
.tv_sec
= DEFAULT_SEM_WAIT_TIMEOUT
;
1403 timeout
.tv_nsec
= 0;
1405 /* Setup semaphore */
1406 ret
= sem_init(&consumer_data
->sem
, 0, 0);
1408 PERROR("sem_init consumer semaphore");
1412 ret
= pthread_create(&consumer_data
->thread
, NULL
,
1413 thread_manage_consumer
, consumer_data
);
1415 PERROR("pthread_create consumer");
1420 /* Get time for sem_timedwait absolute timeout */
1421 ret
= clock_gettime(CLOCK_REALTIME
, &timeout
);
1423 PERROR("clock_gettime spawn consumer");
1424 /* Infinite wait for the kconsumerd thread to be ready */
1425 ret
= sem_wait(&consumer_data
->sem
);
1427 /* Normal timeout if the gettime was successful */
1428 timeout
.tv_sec
+= DEFAULT_SEM_WAIT_TIMEOUT
;
1429 ret
= sem_timedwait(&consumer_data
->sem
, &timeout
);
1433 if (errno
== ETIMEDOUT
) {
1435 * Call has timed out so we kill the kconsumerd_thread and return
1438 ERR("The consumer thread was never ready. Killing it");
1439 ret
= pthread_cancel(consumer_data
->thread
);
1441 PERROR("pthread_cancel consumer thread");
1444 PERROR("semaphore wait failed consumer thread");
1449 pthread_mutex_lock(&consumer_data
->pid_mutex
);
1450 if (consumer_data
->pid
== 0) {
1451 ERR("Kconsumerd did not start");
1452 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
1455 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
1464 * Join consumer thread
1466 static int join_consumer_thread(struct consumer_data
*consumer_data
)
1471 if (consumer_data
->pid
!= 0) {
1472 ret
= kill(consumer_data
->pid
, SIGTERM
);
1474 ERR("Error killing consumer daemon");
1477 return pthread_join(consumer_data
->thread
, &status
);
1484 * Fork and exec a consumer daemon (consumerd).
1486 * Return pid if successful else -1.
1488 static pid_t
spawn_consumerd(struct consumer_data
*consumer_data
)
1492 const char *consumer_to_use
;
1493 const char *verbosity
;
1496 DBG("Spawning consumerd");
1503 if (opt_verbose_consumer
) {
1504 verbosity
= "--verbose";
1506 verbosity
= "--quiet";
1508 switch (consumer_data
->type
) {
1509 case LTTNG_CONSUMER_KERNEL
:
1511 * Find out which consumerd to execute. We will first try the
1512 * 64-bit path, then the sessiond's installation directory, and
1513 * fallback on the 32-bit one,
1515 DBG3("Looking for a kernel consumer at these locations:");
1516 DBG3(" 1) %s", consumerd64_bin
);
1517 DBG3(" 2) %s/%s", INSTALL_BIN_PATH
, CONSUMERD_FILE
);
1518 DBG3(" 3) %s", consumerd32_bin
);
1519 if (stat(consumerd64_bin
, &st
) == 0) {
1520 DBG3("Found location #1");
1521 consumer_to_use
= consumerd64_bin
;
1522 } else if (stat(INSTALL_BIN_PATH
"/" CONSUMERD_FILE
, &st
) == 0) {
1523 DBG3("Found location #2");
1524 consumer_to_use
= INSTALL_BIN_PATH
"/" CONSUMERD_FILE
;
1525 } else if (stat(consumerd32_bin
, &st
) == 0) {
1526 DBG3("Found location #3");
1527 consumer_to_use
= consumerd32_bin
;
1529 DBG("Could not find any valid consumerd executable");
1532 DBG("Using kernel consumer at: %s", consumer_to_use
);
1533 execl(consumer_to_use
,
1534 "lttng-consumerd", verbosity
, "-k",
1535 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
1536 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
1539 case LTTNG_CONSUMER64_UST
:
1541 char *tmpnew
= NULL
;
1543 if (consumerd64_libdir
[0] != '\0') {
1547 tmp
= getenv("LD_LIBRARY_PATH");
1551 tmplen
= strlen("LD_LIBRARY_PATH=")
1552 + strlen(consumerd64_libdir
) + 1 /* : */ + strlen(tmp
);
1553 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
1558 strcpy(tmpnew
, "LD_LIBRARY_PATH=");
1559 strcat(tmpnew
, consumerd64_libdir
);
1560 if (tmp
[0] != '\0') {
1561 strcat(tmpnew
, ":");
1562 strcat(tmpnew
, tmp
);
1564 ret
= putenv(tmpnew
);
1570 DBG("Using 64-bit UST consumer at: %s", consumerd64_bin
);
1571 ret
= execl(consumerd64_bin
, "lttng-consumerd", verbosity
, "-u",
1572 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
1573 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
1575 if (consumerd64_libdir
[0] != '\0') {
1583 case LTTNG_CONSUMER32_UST
:
1585 char *tmpnew
= NULL
;
1587 if (consumerd32_libdir
[0] != '\0') {
1591 tmp
= getenv("LD_LIBRARY_PATH");
1595 tmplen
= strlen("LD_LIBRARY_PATH=")
1596 + strlen(consumerd32_libdir
) + 1 /* : */ + strlen(tmp
);
1597 tmpnew
= zmalloc(tmplen
+ 1 /* \0 */);
1602 strcpy(tmpnew
, "LD_LIBRARY_PATH=");
1603 strcat(tmpnew
, consumerd32_libdir
);
1604 if (tmp
[0] != '\0') {
1605 strcat(tmpnew
, ":");
1606 strcat(tmpnew
, tmp
);
1608 ret
= putenv(tmpnew
);
1614 DBG("Using 32-bit UST consumer at: %s", consumerd32_bin
);
1615 ret
= execl(consumerd32_bin
, "lttng-consumerd", verbosity
, "-u",
1616 "--consumerd-cmd-sock", consumer_data
->cmd_unix_sock_path
,
1617 "--consumerd-err-sock", consumer_data
->err_unix_sock_path
,
1619 if (consumerd32_libdir
[0] != '\0') {
1628 PERROR("unknown consumer type");
1632 PERROR("kernel start consumer exec");
1635 } else if (pid
> 0) {
1638 PERROR("start consumer fork");
1646 * Spawn the consumerd daemon and session daemon thread.
1648 static int start_consumerd(struct consumer_data
*consumer_data
)
1652 pthread_mutex_lock(&consumer_data
->pid_mutex
);
1653 if (consumer_data
->pid
!= 0) {
1654 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
1658 ret
= spawn_consumerd(consumer_data
);
1660 ERR("Spawning consumerd failed");
1661 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
1665 /* Setting up the consumer_data pid */
1666 consumer_data
->pid
= ret
;
1667 DBG2("Consumer pid %d", consumer_data
->pid
);
1668 pthread_mutex_unlock(&consumer_data
->pid_mutex
);
1670 DBG2("Spawning consumer control thread");
1671 ret
= spawn_consumer_thread(consumer_data
);
1673 ERR("Fatal error spawning consumer control thread");
1685 * Check version of the lttng-modules.
1687 static int validate_lttng_modules_version(void)
1689 return kernel_validate_version(kernel_tracer_fd
);
1693 * Setup necessary data for kernel tracer action.
1695 static int init_kernel_tracer(void)
1699 /* Modprobe lttng kernel modules */
1700 ret
= modprobe_lttng_control();
1705 /* Open debugfs lttng */
1706 kernel_tracer_fd
= open(module_proc_lttng
, O_RDWR
);
1707 if (kernel_tracer_fd
< 0) {
1708 DBG("Failed to open %s", module_proc_lttng
);
1713 /* Validate kernel version */
1714 ret
= validate_lttng_modules_version();
1719 ret
= modprobe_lttng_data();
1724 DBG("Kernel tracer fd %d", kernel_tracer_fd
);
1728 modprobe_remove_lttng_control();
1729 ret
= close(kernel_tracer_fd
);
1733 kernel_tracer_fd
= -1;
1734 return LTTCOMM_KERN_VERSION
;
1737 ret
= close(kernel_tracer_fd
);
1743 modprobe_remove_lttng_control();
1746 WARN("No kernel tracer available");
1747 kernel_tracer_fd
= -1;
1749 return LTTCOMM_NEED_ROOT_SESSIOND
;
1751 return LTTCOMM_KERN_NA
;
1756 * Init tracing by creating trace directory and sending fds kernel consumer.
1758 static int init_kernel_tracing(struct ltt_kernel_session
*session
)
1762 if (session
->consumer_fds_sent
== 0 && session
->consumer
!= NULL
) {
1764 * Assign default kernel consumer socket if no consumer assigned to the
1765 * kernel session. At this point, it's NOT supposed to be -1 but this is
1766 * an extra security check.
1768 if (session
->consumer_fd
< 0) {
1769 session
->consumer_fd
= kconsumer_data
.cmd_sock
;
1772 ret
= kernel_consumer_send_session(session
->consumer_fd
, session
);
1774 ret
= LTTCOMM_KERN_CONSUMER_FAIL
;
1784 * Create a socket to the relayd using the URI.
1786 * On success, the relayd_sock pointer is set to the created socket.
1787 * Else, it is untouched and an lttcomm error code is returned.
1789 static int create_connect_relayd(struct consumer_output
*output
,
1790 const char *session_name
, struct lttng_uri
*uri
,
1791 struct lttcomm_sock
**relayd_sock
)
1794 struct lttcomm_sock
*sock
;
1796 /* Create socket object from URI */
1797 sock
= lttcomm_alloc_sock_from_uri(uri
);
1799 ret
= LTTCOMM_FATAL
;
1803 ret
= lttcomm_create_sock(sock
);
1805 ret
= LTTCOMM_FATAL
;
1809 /* Connect to relayd so we can proceed with a session creation. */
1810 ret
= relayd_connect(sock
);
1812 ERR("Unable to reach lttng-relayd");
1813 ret
= LTTCOMM_RELAYD_SESSION_FAIL
;
1817 /* Create socket for control stream. */
1818 if (uri
->stype
== LTTNG_STREAM_CONTROL
) {
1819 DBG3("Creating relayd stream socket from URI");
1821 /* Check relayd version */
1822 ret
= relayd_version_check(sock
, LTTNG_UST_COMM_MAJOR
, 0);
1824 ret
= LTTCOMM_RELAYD_VERSION_FAIL
;
1827 } else if (uri
->stype
== LTTNG_STREAM_DATA
) {
1828 DBG3("Creating relayd data socket from URI");
1830 /* Command is not valid */
1831 ERR("Relayd invalid stream type: %d", uri
->stype
);
1832 ret
= LTTCOMM_INVALID
;
1836 *relayd_sock
= sock
;
1842 (void) relayd_close(sock
);
1846 lttcomm_destroy_sock(sock
);
1853 * Connect to the relayd using URI and send the socket to the right consumer.
1855 static int send_socket_relayd_consumer(int domain
, struct ltt_session
*session
,
1856 struct lttng_uri
*relayd_uri
, struct consumer_output
*consumer
,
1860 struct lttcomm_sock
*sock
= NULL
;
1862 /* Set the network sequence index if not set. */
1863 if (consumer
->net_seq_index
== -1) {
1865 * Increment net_seq_idx because we are about to transfer the
1866 * new relayd socket to the consumer.
1868 uatomic_inc(&relayd_net_seq_idx
);
1869 /* Assign unique key so the consumer can match streams */
1870 consumer
->net_seq_index
= uatomic_read(&relayd_net_seq_idx
);
1873 /* Connect to relayd and make version check if uri is the control. */
1874 ret
= create_connect_relayd(consumer
, session
->name
, relayd_uri
, &sock
);
1875 if (ret
!= LTTCOMM_OK
) {
1879 /* If the control socket is connected, network session is ready */
1880 if (relayd_uri
->stype
== LTTNG_STREAM_CONTROL
) {
1881 session
->net_handle
= 1;
1885 case LTTNG_DOMAIN_KERNEL
:
1886 /* Send relayd socket to consumer. */
1887 ret
= kernel_consumer_send_relayd_socket(consumer_fd
, sock
,
1888 consumer
, relayd_uri
->stype
);
1890 ret
= LTTCOMM_ENABLE_CONSUMER_FAIL
;
1894 case LTTNG_DOMAIN_UST
:
1895 /* Send relayd socket to consumer. */
1896 ret
= ust_consumer_send_relayd_socket(consumer_fd
, sock
,
1897 consumer
, relayd_uri
->stype
);
1899 ret
= LTTCOMM_ENABLE_CONSUMER_FAIL
;
1908 * Close socket which was dup on the consumer side. The session daemon does
1909 * NOT keep track of the relayd socket(s) once transfer to the consumer.
1914 (void) relayd_close(sock
);
1915 lttcomm_destroy_sock(sock
);
1922 * Send both relayd sockets to a specific consumer and domain. This is a
1923 * helper function to facilitate sending the information to the consumer for a
1926 static int send_sockets_relayd_consumer(int domain
,
1927 struct ltt_session
*session
, struct consumer_output
*consumer
, int fd
)
1931 /* Sending control relayd socket. */
1932 ret
= send_socket_relayd_consumer(domain
, session
,
1933 &consumer
->dst
.net
.control
, consumer
, fd
);
1934 if (ret
!= LTTCOMM_OK
) {
1938 /* Sending data relayd socket. */
1939 ret
= send_socket_relayd_consumer(domain
, session
,
1940 &consumer
->dst
.net
.data
, consumer
, fd
);
1941 if (ret
!= LTTCOMM_OK
) {
1950 * Setup relayd connections for a tracing session. First creates the socket to
1951 * the relayd and send them to the right domain consumer. Consumer type MUST be
1954 static int setup_relayd(struct ltt_session
*session
)
1956 int ret
= LTTCOMM_OK
;
1957 struct ltt_ust_session
*usess
;
1958 struct ltt_kernel_session
*ksess
;
1962 usess
= session
->ust_session
;
1963 ksess
= session
->kernel_session
;
1965 DBG2("Setting relayd for session %s", session
->name
);
1967 if (usess
&& usess
->consumer
->sock
== -1 &&
1968 usess
->consumer
->type
== CONSUMER_DST_NET
&&
1969 usess
->consumer
->enabled
) {
1970 /* Setup relayd for 64 bits consumer */
1971 if (ust_consumerd64_fd
>= 0) {
1972 send_sockets_relayd_consumer(LTTNG_DOMAIN_UST
, session
,
1973 usess
->consumer
, ust_consumerd64_fd
);
1974 if (ret
!= LTTCOMM_OK
) {
1979 /* Setup relayd for 32 bits consumer */
1980 if (ust_consumerd32_fd
>= 0) {
1981 send_sockets_relayd_consumer(LTTNG_DOMAIN_UST
, session
,
1982 usess
->consumer
, ust_consumerd32_fd
);
1983 if (ret
!= LTTCOMM_OK
) {
1987 } else if (ksess
&& ksess
->consumer
->sock
== -1 &&
1988 ksess
->consumer
->type
== CONSUMER_DST_NET
&&
1989 ksess
->consumer
->enabled
) {
1990 send_sockets_relayd_consumer(LTTNG_DOMAIN_KERNEL
, session
,
1991 ksess
->consumer
, ksess
->consumer_fd
);
1992 if (ret
!= LTTCOMM_OK
) {
2002 * Copy consumer output from the tracing session to the domain session. The
2003 * function also applies the right modification on a per domain basis for the
2004 * trace files destination directory.
2006 static int copy_session_consumer(int domain
, struct ltt_session
*session
)
2009 const char *dir_name
;
2010 struct consumer_output
*consumer
;
2013 case LTTNG_DOMAIN_KERNEL
:
2014 DBG3("Copying tracing session consumer output in kernel session");
2015 session
->kernel_session
->consumer
=
2016 consumer_copy_output(session
->consumer
);
2017 /* Ease our life a bit for the next part */
2018 consumer
= session
->kernel_session
->consumer
;
2019 dir_name
= DEFAULT_KERNEL_TRACE_DIR
;
2021 case LTTNG_DOMAIN_UST
:
2022 DBG3("Copying tracing session consumer output in UST session");
2023 session
->ust_session
->consumer
=
2024 consumer_copy_output(session
->consumer
);
2025 /* Ease our life a bit for the next part */
2026 consumer
= session
->ust_session
->consumer
;
2027 dir_name
= DEFAULT_UST_TRACE_DIR
;
2030 ret
= LTTCOMM_UNKNOWN_DOMAIN
;
2034 /* Append correct directory to subdir */
2035 strncat(consumer
->subdir
, dir_name
, sizeof(consumer
->subdir
));
2036 DBG3("Copy session consumer subdir %s", consumer
->subdir
);
2038 /* Add default trace directory name */
2039 if (consumer
->type
== CONSUMER_DST_LOCAL
) {
2040 strncat(consumer
->dst
.trace_path
, dir_name
,
2041 sizeof(consumer
->dst
.trace_path
));
2051 * Create an UST session and add it to the session ust list.
2053 static int create_ust_session(struct ltt_session
*session
,
2054 struct lttng_domain
*domain
)
2057 struct ltt_ust_session
*lus
= NULL
;
2060 assert(session
->consumer
);
2062 switch (domain
->type
) {
2063 case LTTNG_DOMAIN_UST
:
2066 ERR("Unknown UST domain on create session %d", domain
->type
);
2067 ret
= LTTCOMM_UNKNOWN_DOMAIN
;
2071 DBG("Creating UST session");
2073 lus
= trace_ust_create_session(session
->path
, session
->id
, domain
);
2075 ret
= LTTCOMM_UST_SESS_FAIL
;
2079 if (session
->consumer
->type
== CONSUMER_DST_LOCAL
) {
2080 ret
= run_as_mkdir_recursive(lus
->pathname
, S_IRWXU
| S_IRWXG
,
2081 session
->uid
, session
->gid
);
2083 if (ret
!= -EEXIST
) {
2084 ERR("Trace directory creation error");
2085 ret
= LTTCOMM_UST_SESS_FAIL
;
2091 lus
->uid
= session
->uid
;
2092 lus
->gid
= session
->gid
;
2093 session
->ust_session
= lus
;
2095 /* Copy session output to the newly created UST session */
2096 ret
= copy_session_consumer(domain
->type
, session
);
2097 if (ret
!= LTTCOMM_OK
) {
2105 session
->ust_session
= NULL
;
2110 * Create a kernel tracer session then create the default channel.
2112 static int create_kernel_session(struct ltt_session
*session
)
2116 DBG("Creating kernel session");
2118 ret
= kernel_create_session(session
, kernel_tracer_fd
);
2120 ret
= LTTCOMM_KERN_SESS_FAIL
;
2124 /* Set kernel consumer socket fd */
2125 if (kconsumer_data
.cmd_sock
>= 0) {
2126 session
->kernel_session
->consumer_fd
= kconsumer_data
.cmd_sock
;
2129 /* Copy session output to the newly created Kernel session */
2130 ret
= copy_session_consumer(LTTNG_DOMAIN_KERNEL
, session
);
2131 if (ret
!= LTTCOMM_OK
) {
2135 /* Create directory(ies) on local filesystem. */
2136 if (session
->consumer
->type
== CONSUMER_DST_LOCAL
) {
2137 ret
= run_as_mkdir_recursive(
2138 session
->kernel_session
->consumer
->dst
.trace_path
,
2139 S_IRWXU
| S_IRWXG
, session
->uid
, session
->gid
);
2141 if (ret
!= -EEXIST
) {
2142 ERR("Trace directory creation error");
2148 session
->kernel_session
->uid
= session
->uid
;
2149 session
->kernel_session
->gid
= session
->gid
;
2154 trace_kernel_destroy_session(session
->kernel_session
);
2155 session
->kernel_session
= NULL
;
2160 * Check if the UID or GID match the session. Root user has access to all
2163 static int session_access_ok(struct ltt_session
*session
, uid_t uid
, gid_t gid
)
2165 if (uid
!= session
->uid
&& gid
!= session
->gid
&& uid
!= 0) {
2173 * Count number of session permitted by uid/gid.
2175 static unsigned int lttng_sessions_count(uid_t uid
, gid_t gid
)
2178 struct ltt_session
*session
;
2180 DBG("Counting number of available session for UID %d GID %d",
2182 cds_list_for_each_entry(session
, &session_list_ptr
->head
, list
) {
2184 * Only list the sessions the user can control.
2186 if (!session_access_ok(session
, uid
, gid
)) {
2195 * Using the session list, filled a lttng_session array to send back to the
2196 * client for session listing.
2198 * The session list lock MUST be acquired before calling this function. Use
2199 * session_lock_list() and session_unlock_list().
2201 static void list_lttng_sessions(struct lttng_session
*sessions
, uid_t uid
,
2205 struct ltt_session
*session
;
2207 DBG("Getting all available session for UID %d GID %d",
2210 * Iterate over session list and append data after the control struct in
2213 cds_list_for_each_entry(session
, &session_list_ptr
->head
, list
) {
2215 * Only list the sessions the user can control.
2217 if (!session_access_ok(session
, uid
, gid
)) {
2220 strncpy(sessions
[i
].path
, session
->path
, PATH_MAX
);
2221 sessions
[i
].path
[PATH_MAX
- 1] = '\0';
2222 strncpy(sessions
[i
].name
, session
->name
, NAME_MAX
);
2223 sessions
[i
].name
[NAME_MAX
- 1] = '\0';
2224 sessions
[i
].enabled
= session
->enabled
;
2230 * Fill lttng_channel array of all channels.
2232 static void list_lttng_channels(int domain
, struct ltt_session
*session
,
2233 struct lttng_channel
*channels
)
2236 struct ltt_kernel_channel
*kchan
;
2238 DBG("Listing channels for session %s", session
->name
);
2241 case LTTNG_DOMAIN_KERNEL
:
2242 /* Kernel channels */
2243 if (session
->kernel_session
!= NULL
) {
2244 cds_list_for_each_entry(kchan
,
2245 &session
->kernel_session
->channel_list
.head
, list
) {
2246 /* Copy lttng_channel struct to array */
2247 memcpy(&channels
[i
], kchan
->channel
, sizeof(struct lttng_channel
));
2248 channels
[i
].enabled
= kchan
->enabled
;
2253 case LTTNG_DOMAIN_UST
:
2255 struct lttng_ht_iter iter
;
2256 struct ltt_ust_channel
*uchan
;
2258 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
2259 &iter
.iter
, uchan
, node
.node
) {
2260 strncpy(channels
[i
].name
, uchan
->name
, LTTNG_SYMBOL_NAME_LEN
);
2261 channels
[i
].attr
.overwrite
= uchan
->attr
.overwrite
;
2262 channels
[i
].attr
.subbuf_size
= uchan
->attr
.subbuf_size
;
2263 channels
[i
].attr
.num_subbuf
= uchan
->attr
.num_subbuf
;
2264 channels
[i
].attr
.switch_timer_interval
=
2265 uchan
->attr
.switch_timer_interval
;
2266 channels
[i
].attr
.read_timer_interval
=
2267 uchan
->attr
.read_timer_interval
;
2268 channels
[i
].enabled
= uchan
->enabled
;
2269 switch (uchan
->attr
.output
) {
2270 case LTTNG_UST_MMAP
:
2272 channels
[i
].attr
.output
= LTTNG_EVENT_MMAP
;
2285 * Create a list of ust global domain events.
2287 static int list_lttng_ust_global_events(char *channel_name
,
2288 struct ltt_ust_domain_global
*ust_global
, struct lttng_event
**events
)
2291 unsigned int nb_event
= 0;
2292 struct lttng_ht_iter iter
;
2293 struct lttng_ht_node_str
*node
;
2294 struct ltt_ust_channel
*uchan
;
2295 struct ltt_ust_event
*uevent
;
2296 struct lttng_event
*tmp
;
2298 DBG("Listing UST global events for channel %s", channel_name
);
2302 lttng_ht_lookup(ust_global
->channels
, (void *)channel_name
, &iter
);
2303 node
= lttng_ht_iter_get_node_str(&iter
);
2305 ret
= -LTTCOMM_UST_CHAN_NOT_FOUND
;
2309 uchan
= caa_container_of(&node
->node
, struct ltt_ust_channel
, node
.node
);
2311 nb_event
+= lttng_ht_get_count(uchan
->events
);
2313 if (nb_event
== 0) {
2318 DBG3("Listing UST global %d events", nb_event
);
2320 tmp
= zmalloc(nb_event
* sizeof(struct lttng_event
));
2322 ret
= -LTTCOMM_FATAL
;
2326 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
2327 strncpy(tmp
[i
].name
, uevent
->attr
.name
, LTTNG_SYMBOL_NAME_LEN
);
2328 tmp
[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
2329 tmp
[i
].enabled
= uevent
->enabled
;
2330 switch (uevent
->attr
.instrumentation
) {
2331 case LTTNG_UST_TRACEPOINT
:
2332 tmp
[i
].type
= LTTNG_EVENT_TRACEPOINT
;
2334 case LTTNG_UST_PROBE
:
2335 tmp
[i
].type
= LTTNG_EVENT_PROBE
;
2337 case LTTNG_UST_FUNCTION
:
2338 tmp
[i
].type
= LTTNG_EVENT_FUNCTION
;
2341 tmp
[i
].loglevel
= uevent
->attr
.loglevel
;
2342 switch (uevent
->attr
.loglevel_type
) {
2343 case LTTNG_UST_LOGLEVEL_ALL
:
2344 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
2346 case LTTNG_UST_LOGLEVEL_RANGE
:
2347 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
2349 case LTTNG_UST_LOGLEVEL_SINGLE
:
2350 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
2353 if (uevent
->filter
) {
2368 * Fill lttng_event array of all kernel events in the channel.
2370 static int list_lttng_kernel_events(char *channel_name
,
2371 struct ltt_kernel_session
*kernel_session
, struct lttng_event
**events
)
2374 unsigned int nb_event
;
2375 struct ltt_kernel_event
*event
;
2376 struct ltt_kernel_channel
*kchan
;
2378 kchan
= trace_kernel_get_channel_by_name(channel_name
, kernel_session
);
2379 if (kchan
== NULL
) {
2380 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
2384 nb_event
= kchan
->event_count
;
2386 DBG("Listing events for channel %s", kchan
->channel
->name
);
2388 if (nb_event
== 0) {
2393 *events
= zmalloc(nb_event
* sizeof(struct lttng_event
));
2394 if (*events
== NULL
) {
2395 ret
= LTTCOMM_FATAL
;
2399 /* Kernel channels */
2400 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
2401 strncpy((*events
)[i
].name
, event
->event
->name
, LTTNG_SYMBOL_NAME_LEN
);
2402 (*events
)[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
2403 (*events
)[i
].enabled
= event
->enabled
;
2404 switch (event
->event
->instrumentation
) {
2405 case LTTNG_KERNEL_TRACEPOINT
:
2406 (*events
)[i
].type
= LTTNG_EVENT_TRACEPOINT
;
2408 case LTTNG_KERNEL_KPROBE
:
2409 case LTTNG_KERNEL_KRETPROBE
:
2410 (*events
)[i
].type
= LTTNG_EVENT_PROBE
;
2411 memcpy(&(*events
)[i
].attr
.probe
, &event
->event
->u
.kprobe
,
2412 sizeof(struct lttng_kernel_kprobe
));
2414 case LTTNG_KERNEL_FUNCTION
:
2415 (*events
)[i
].type
= LTTNG_EVENT_FUNCTION
;
2416 memcpy(&((*events
)[i
].attr
.ftrace
), &event
->event
->u
.ftrace
,
2417 sizeof(struct lttng_kernel_function
));
2419 case LTTNG_KERNEL_NOOP
:
2420 (*events
)[i
].type
= LTTNG_EVENT_NOOP
;
2422 case LTTNG_KERNEL_SYSCALL
:
2423 (*events
)[i
].type
= LTTNG_EVENT_SYSCALL
;
2425 case LTTNG_KERNEL_ALL
:
2439 * Command LTTNG_DISABLE_CHANNEL processed by the client thread.
2441 static int cmd_disable_channel(struct ltt_session
*session
,
2442 int domain
, char *channel_name
)
2445 struct ltt_ust_session
*usess
;
2447 usess
= session
->ust_session
;
2450 case LTTNG_DOMAIN_KERNEL
:
2452 ret
= channel_kernel_disable(session
->kernel_session
,
2454 if (ret
!= LTTCOMM_OK
) {
2458 kernel_wait_quiescent(kernel_tracer_fd
);
2461 case LTTNG_DOMAIN_UST
:
2463 struct ltt_ust_channel
*uchan
;
2464 struct lttng_ht
*chan_ht
;
2466 chan_ht
= usess
->domain_global
.channels
;
2468 uchan
= trace_ust_find_channel_by_name(chan_ht
, channel_name
);
2469 if (uchan
== NULL
) {
2470 ret
= LTTCOMM_UST_CHAN_NOT_FOUND
;
2474 ret
= channel_ust_disable(usess
, domain
, uchan
);
2475 if (ret
!= LTTCOMM_OK
) {
2481 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
2482 case LTTNG_DOMAIN_UST_EXEC_NAME
:
2483 case LTTNG_DOMAIN_UST_PID
:
2486 ret
= LTTCOMM_UNKNOWN_DOMAIN
;
2497 * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
2499 static int cmd_enable_channel(struct ltt_session
*session
,
2500 int domain
, struct lttng_channel
*attr
)
2503 struct ltt_ust_session
*usess
= session
->ust_session
;
2504 struct lttng_ht
*chan_ht
;
2506 DBG("Enabling channel %s for session %s", attr
->name
, session
->name
);
2509 case LTTNG_DOMAIN_KERNEL
:
2511 struct ltt_kernel_channel
*kchan
;
2513 kchan
= trace_kernel_get_channel_by_name(attr
->name
,
2514 session
->kernel_session
);
2515 if (kchan
== NULL
) {
2516 ret
= channel_kernel_create(session
->kernel_session
,
2517 attr
, kernel_poll_pipe
[1]);
2519 ret
= channel_kernel_enable(session
->kernel_session
, kchan
);
2522 if (ret
!= LTTCOMM_OK
) {
2526 kernel_wait_quiescent(kernel_tracer_fd
);
2529 case LTTNG_DOMAIN_UST
:
2531 struct ltt_ust_channel
*uchan
;
2533 chan_ht
= usess
->domain_global
.channels
;
2535 uchan
= trace_ust_find_channel_by_name(chan_ht
, attr
->name
);
2536 if (uchan
== NULL
) {
2537 ret
= channel_ust_create(usess
, domain
, attr
);
2539 ret
= channel_ust_enable(usess
, domain
, uchan
);
2544 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
2545 case LTTNG_DOMAIN_UST_EXEC_NAME
:
2546 case LTTNG_DOMAIN_UST_PID
:
2549 ret
= LTTCOMM_UNKNOWN_DOMAIN
;
2558 * Command LTTNG_DISABLE_EVENT processed by the client thread.
2560 static int cmd_disable_event(struct ltt_session
*session
, int domain
,
2561 char *channel_name
, char *event_name
)
2566 case LTTNG_DOMAIN_KERNEL
:
2568 struct ltt_kernel_channel
*kchan
;
2569 struct ltt_kernel_session
*ksess
;
2571 ksess
= session
->kernel_session
;
2573 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksess
);
2574 if (kchan
== NULL
) {
2575 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
2579 ret
= event_kernel_disable_tracepoint(ksess
, kchan
, event_name
);
2580 if (ret
!= LTTCOMM_OK
) {
2584 kernel_wait_quiescent(kernel_tracer_fd
);
2587 case LTTNG_DOMAIN_UST
:
2589 struct ltt_ust_channel
*uchan
;
2590 struct ltt_ust_session
*usess
;
2592 usess
= session
->ust_session
;
2594 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
2596 if (uchan
== NULL
) {
2597 ret
= LTTCOMM_UST_CHAN_NOT_FOUND
;
2601 ret
= event_ust_disable_tracepoint(usess
, domain
, uchan
, event_name
);
2602 if (ret
!= LTTCOMM_OK
) {
2606 DBG3("Disable UST event %s in channel %s completed", event_name
,
2611 case LTTNG_DOMAIN_UST_EXEC_NAME
:
2612 case LTTNG_DOMAIN_UST_PID
:
2613 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
2627 * Command LTTNG_DISABLE_ALL_EVENT processed by the client thread.
2629 static int cmd_disable_event_all(struct ltt_session
*session
, int domain
,
2635 case LTTNG_DOMAIN_KERNEL
:
2637 struct ltt_kernel_session
*ksess
;
2638 struct ltt_kernel_channel
*kchan
;
2640 ksess
= session
->kernel_session
;
2642 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksess
);
2643 if (kchan
== NULL
) {
2644 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
2648 ret
= event_kernel_disable_all(ksess
, kchan
);
2649 if (ret
!= LTTCOMM_OK
) {
2653 kernel_wait_quiescent(kernel_tracer_fd
);
2656 case LTTNG_DOMAIN_UST
:
2658 struct ltt_ust_session
*usess
;
2659 struct ltt_ust_channel
*uchan
;
2661 usess
= session
->ust_session
;
2663 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
2665 if (uchan
== NULL
) {
2666 ret
= LTTCOMM_UST_CHAN_NOT_FOUND
;
2670 ret
= event_ust_disable_all_tracepoints(usess
, domain
, uchan
);
2675 DBG3("Disable all UST events in channel %s completed", channel_name
);
2680 case LTTNG_DOMAIN_UST_EXEC_NAME
:
2681 case LTTNG_DOMAIN_UST_PID
:
2682 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
2696 * Command LTTNG_ADD_CONTEXT processed by the client thread.
2698 static int cmd_add_context(struct ltt_session
*session
, int domain
,
2699 char *channel_name
, char *event_name
, struct lttng_event_context
*ctx
)
2704 case LTTNG_DOMAIN_KERNEL
:
2705 /* Add kernel context to kernel tracer */
2706 ret
= context_kernel_add(session
->kernel_session
, ctx
,
2707 event_name
, channel_name
);
2708 if (ret
!= LTTCOMM_OK
) {
2712 case LTTNG_DOMAIN_UST
:
2714 struct ltt_ust_session
*usess
= session
->ust_session
;
2716 ret
= context_ust_add(usess
, domain
, ctx
, event_name
, channel_name
);
2717 if (ret
!= LTTCOMM_OK
) {
2723 case LTTNG_DOMAIN_UST_EXEC_NAME
:
2724 case LTTNG_DOMAIN_UST_PID
:
2725 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
2739 * Command LTTNG_SET_FILTER processed by the client thread.
2741 static int cmd_set_filter(struct ltt_session
*session
, int domain
,
2742 char *channel_name
, char *event_name
,
2743 struct lttng_filter_bytecode
*bytecode
)
2748 case LTTNG_DOMAIN_KERNEL
:
2749 ret
= LTTCOMM_FATAL
;
2751 case LTTNG_DOMAIN_UST
:
2753 struct ltt_ust_session
*usess
= session
->ust_session
;
2755 ret
= filter_ust_set(usess
, domain
, bytecode
, event_name
, channel_name
);
2756 if (ret
!= LTTCOMM_OK
) {
2762 case LTTNG_DOMAIN_UST_EXEC_NAME
:
2763 case LTTNG_DOMAIN_UST_PID
:
2764 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
2779 * Command LTTNG_ENABLE_EVENT processed by the client thread.
2781 static int cmd_enable_event(struct ltt_session
*session
, int domain
,
2782 char *channel_name
, struct lttng_event
*event
)
2785 struct lttng_channel
*attr
;
2786 struct ltt_ust_session
*usess
= session
->ust_session
;
2789 case LTTNG_DOMAIN_KERNEL
:
2791 struct ltt_kernel_channel
*kchan
;
2793 kchan
= trace_kernel_get_channel_by_name(channel_name
,
2794 session
->kernel_session
);
2795 if (kchan
== NULL
) {
2796 attr
= channel_new_default_attr(domain
);
2798 ret
= LTTCOMM_FATAL
;
2801 snprintf(attr
->name
, NAME_MAX
, "%s", channel_name
);
2803 /* This call will notify the kernel thread */
2804 ret
= channel_kernel_create(session
->kernel_session
,
2805 attr
, kernel_poll_pipe
[1]);
2806 if (ret
!= LTTCOMM_OK
) {
2813 /* Get the newly created kernel channel pointer */
2814 kchan
= trace_kernel_get_channel_by_name(channel_name
,
2815 session
->kernel_session
);
2816 if (kchan
== NULL
) {
2817 /* This sould not happen... */
2818 ret
= LTTCOMM_FATAL
;
2822 ret
= event_kernel_enable_tracepoint(session
->kernel_session
, kchan
,
2824 if (ret
!= LTTCOMM_OK
) {
2828 kernel_wait_quiescent(kernel_tracer_fd
);
2831 case LTTNG_DOMAIN_UST
:
2833 struct lttng_channel
*attr
;
2834 struct ltt_ust_channel
*uchan
;
2836 /* Get channel from global UST domain */
2837 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
2839 if (uchan
== NULL
) {
2840 /* Create default channel */
2841 attr
= channel_new_default_attr(domain
);
2843 ret
= LTTCOMM_FATAL
;
2846 snprintf(attr
->name
, NAME_MAX
, "%s", channel_name
);
2847 attr
->name
[NAME_MAX
- 1] = '\0';
2849 ret
= channel_ust_create(usess
, domain
, attr
);
2850 if (ret
!= LTTCOMM_OK
) {
2856 /* Get the newly created channel reference back */
2857 uchan
= trace_ust_find_channel_by_name(
2858 usess
->domain_global
.channels
, channel_name
);
2859 if (uchan
== NULL
) {
2860 /* Something is really wrong */
2861 ret
= LTTCOMM_FATAL
;
2866 /* At this point, the session and channel exist on the tracer */
2867 ret
= event_ust_enable_tracepoint(usess
, domain
, uchan
, event
);
2868 if (ret
!= LTTCOMM_OK
) {
2874 case LTTNG_DOMAIN_UST_EXEC_NAME
:
2875 case LTTNG_DOMAIN_UST_PID
:
2876 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
2890 * Command LTTNG_ENABLE_ALL_EVENT processed by the client thread.
2892 static int cmd_enable_event_all(struct ltt_session
*session
, int domain
,
2893 char *channel_name
, int event_type
)
2896 struct ltt_kernel_channel
*kchan
;
2899 case LTTNG_DOMAIN_KERNEL
:
2900 kchan
= trace_kernel_get_channel_by_name(channel_name
,
2901 session
->kernel_session
);
2902 if (kchan
== NULL
) {
2903 /* This call will notify the kernel thread */
2904 ret
= channel_kernel_create(session
->kernel_session
, NULL
,
2905 kernel_poll_pipe
[1]);
2906 if (ret
!= LTTCOMM_OK
) {
2910 /* Get the newly created kernel channel pointer */
2911 kchan
= trace_kernel_get_channel_by_name(channel_name
,
2912 session
->kernel_session
);
2913 if (kchan
== NULL
) {
2914 /* This sould not happen... */
2915 ret
= LTTCOMM_FATAL
;
2921 switch (event_type
) {
2922 case LTTNG_EVENT_SYSCALL
:
2923 ret
= event_kernel_enable_all_syscalls(session
->kernel_session
,
2924 kchan
, kernel_tracer_fd
);
2926 case LTTNG_EVENT_TRACEPOINT
:
2928 * This call enables all LTTNG_KERNEL_TRACEPOINTS and
2929 * events already registered to the channel.
2931 ret
= event_kernel_enable_all_tracepoints(session
->kernel_session
,
2932 kchan
, kernel_tracer_fd
);
2934 case LTTNG_EVENT_ALL
:
2935 /* Enable syscalls and tracepoints */
2936 ret
= event_kernel_enable_all(session
->kernel_session
,
2937 kchan
, kernel_tracer_fd
);
2940 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
2944 /* Manage return value */
2945 if (ret
!= LTTCOMM_OK
) {
2949 kernel_wait_quiescent(kernel_tracer_fd
);
2951 case LTTNG_DOMAIN_UST
:
2953 struct lttng_channel
*attr
;
2954 struct ltt_ust_channel
*uchan
;
2955 struct ltt_ust_session
*usess
= session
->ust_session
;
2957 /* Get channel from global UST domain */
2958 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
2960 if (uchan
== NULL
) {
2961 /* Create default channel */
2962 attr
= channel_new_default_attr(domain
);
2964 ret
= LTTCOMM_FATAL
;
2967 snprintf(attr
->name
, NAME_MAX
, "%s", channel_name
);
2968 attr
->name
[NAME_MAX
- 1] = '\0';
2970 /* Use the internal command enable channel */
2971 ret
= channel_ust_create(usess
, domain
, attr
);
2972 if (ret
!= LTTCOMM_OK
) {
2978 /* Get the newly created channel reference back */
2979 uchan
= trace_ust_find_channel_by_name(
2980 usess
->domain_global
.channels
, channel_name
);
2981 if (uchan
== NULL
) {
2982 /* Something is really wrong */
2983 ret
= LTTCOMM_FATAL
;
2988 /* At this point, the session and channel exist on the tracer */
2990 switch (event_type
) {
2991 case LTTNG_EVENT_ALL
:
2992 case LTTNG_EVENT_TRACEPOINT
:
2993 ret
= event_ust_enable_all_tracepoints(usess
, domain
, uchan
);
2994 if (ret
!= LTTCOMM_OK
) {
2999 ret
= LTTCOMM_UST_ENABLE_FAIL
;
3003 /* Manage return value */
3004 if (ret
!= LTTCOMM_OK
) {
3011 case LTTNG_DOMAIN_UST_EXEC_NAME
:
3012 case LTTNG_DOMAIN_UST_PID
:
3013 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
3027 * Command LTTNG_LIST_TRACEPOINTS processed by the client thread.
3029 static ssize_t
cmd_list_tracepoints(int domain
, struct lttng_event
**events
)
3032 ssize_t nb_events
= 0;
3035 case LTTNG_DOMAIN_KERNEL
:
3036 nb_events
= kernel_list_events(kernel_tracer_fd
, events
);
3037 if (nb_events
< 0) {
3038 ret
= LTTCOMM_KERN_LIST_FAIL
;
3042 case LTTNG_DOMAIN_UST
:
3043 nb_events
= ust_app_list_events(events
);
3044 if (nb_events
< 0) {
3045 ret
= LTTCOMM_UST_LIST_FAIL
;
3057 /* Return negative value to differentiate return code */
3062 * Command LTTNG_LIST_TRACEPOINT_FIELDS processed by the client thread.
3064 static ssize_t
cmd_list_tracepoint_fields(int domain
,
3065 struct lttng_event_field
**fields
)
3068 ssize_t nb_fields
= 0;
3071 case LTTNG_DOMAIN_UST
:
3072 nb_fields
= ust_app_list_event_fields(fields
);
3073 if (nb_fields
< 0) {
3074 ret
= LTTCOMM_UST_LIST_FAIL
;
3078 case LTTNG_DOMAIN_KERNEL
:
3079 default: /* fall-through */
3087 /* Return negative value to differentiate return code */
3092 * Command LTTNG_START_TRACE processed by the client thread.
3094 static int cmd_start_trace(struct ltt_session
*session
)
3097 struct ltt_kernel_session
*ksession
;
3098 struct ltt_ust_session
*usess
;
3099 struct ltt_kernel_channel
*kchan
;
3101 /* Ease our life a bit ;) */
3102 ksession
= session
->kernel_session
;
3103 usess
= session
->ust_session
;
3105 if (session
->enabled
) {
3106 /* Already started. */
3107 ret
= LTTCOMM_TRACE_ALREADY_STARTED
;
3111 session
->enabled
= 1;
3113 ret
= setup_relayd(session
);
3114 if (ret
!= LTTCOMM_OK
) {
3115 ERR("Error setting up relayd for session %s", session
->name
);
3119 /* Kernel tracing */
3120 if (ksession
!= NULL
) {
3121 /* Open kernel metadata */
3122 if (ksession
->metadata
== NULL
) {
3123 ret
= kernel_open_metadata(ksession
,
3124 ksession
->consumer
->dst
.trace_path
);
3126 ret
= LTTCOMM_KERN_META_FAIL
;
3131 /* Open kernel metadata stream */
3132 if (ksession
->metadata_stream_fd
< 0) {
3133 ret
= kernel_open_metadata_stream(ksession
);
3135 ERR("Kernel create metadata stream failed");
3136 ret
= LTTCOMM_KERN_STREAM_FAIL
;
3141 /* For each channel */
3142 cds_list_for_each_entry(kchan
, &ksession
->channel_list
.head
, list
) {
3143 if (kchan
->stream_count
== 0) {
3144 ret
= kernel_open_channel_stream(kchan
);
3146 ret
= LTTCOMM_KERN_STREAM_FAIL
;
3149 /* Update the stream global counter */
3150 ksession
->stream_count_global
+= ret
;
3154 /* Setup kernel consumer socket and send fds to it */
3155 ret
= init_kernel_tracing(ksession
);
3157 ret
= LTTCOMM_KERN_START_FAIL
;
3161 /* This start the kernel tracing */
3162 ret
= kernel_start_session(ksession
);
3164 ret
= LTTCOMM_KERN_START_FAIL
;
3168 /* Quiescent wait after starting trace */
3169 kernel_wait_quiescent(kernel_tracer_fd
);
3172 /* Flag session that trace should start automatically */
3174 usess
->start_trace
= 1;
3176 ret
= ust_app_start_trace_all(usess
);
3178 ret
= LTTCOMM_UST_START_FAIL
;
3190 * Command LTTNG_STOP_TRACE processed by the client thread.
3192 static int cmd_stop_trace(struct ltt_session
*session
)
3195 struct ltt_kernel_channel
*kchan
;
3196 struct ltt_kernel_session
*ksession
;
3197 struct ltt_ust_session
*usess
;
3200 ksession
= session
->kernel_session
;
3201 usess
= session
->ust_session
;
3203 if (!session
->enabled
) {
3204 ret
= LTTCOMM_TRACE_ALREADY_STOPPED
;
3208 session
->enabled
= 0;
3211 if (ksession
!= NULL
) {
3212 DBG("Stop kernel tracing");
3214 /* Flush metadata if exist */
3215 if (ksession
->metadata_stream_fd
>= 0) {
3216 ret
= kernel_metadata_flush_buffer(ksession
->metadata_stream_fd
);
3218 ERR("Kernel metadata flush failed");
3222 /* Flush all buffers before stopping */
3223 cds_list_for_each_entry(kchan
, &ksession
->channel_list
.head
, list
) {
3224 ret
= kernel_flush_buffer(kchan
);
3226 ERR("Kernel flush buffer error");
3230 ret
= kernel_stop_session(ksession
);
3232 ret
= LTTCOMM_KERN_STOP_FAIL
;
3236 kernel_wait_quiescent(kernel_tracer_fd
);
3240 usess
->start_trace
= 0;
3242 ret
= ust_app_stop_trace_all(usess
);
3244 ret
= LTTCOMM_UST_STOP_FAIL
;
3256 * Command LTTNG_CREATE_SESSION_URI processed by the client thread.
3258 static int cmd_create_session_uri(char *name
, struct lttng_uri
*ctrl_uri
,
3259 struct lttng_uri
*data_uri
, unsigned int enable_consumer
,
3260 lttng_sock_cred
*creds
)
3264 struct ltt_session
*session
;
3265 struct consumer_output
*consumer
;
3267 /* Verify if the session already exist */
3268 session
= session_find_by_name(name
);
3269 if (session
!= NULL
) {
3270 ret
= LTTCOMM_EXIST_SESS
;
3274 /* TODO: validate URIs */
3276 /* Create default consumer output */
3277 consumer
= consumer_create_output(CONSUMER_DST_LOCAL
);
3278 if (consumer
== NULL
) {
3279 ret
= LTTCOMM_FATAL
;
3282 strncpy(consumer
->subdir
, ctrl_uri
->subdir
, sizeof(consumer
->subdir
));
3283 DBG2("Consumer subdir set to %s", consumer
->subdir
);
3285 switch (ctrl_uri
->dtype
) {
3286 case LTTNG_DST_IPV4
:
3287 case LTTNG_DST_IPV6
:
3288 /* Set control URI into consumer output object */
3289 ret
= consumer_set_network_uri(consumer
, ctrl_uri
);
3291 ret
= LTTCOMM_FATAL
;
3295 /* Set data URI into consumer output object */
3296 ret
= consumer_set_network_uri(consumer
, data_uri
);
3298 ret
= LTTCOMM_FATAL
;
3302 /* Empty path since the session is network */
3305 case LTTNG_DST_PATH
:
3306 /* Very volatile pointer. Only used for the create session. */
3307 path
= ctrl_uri
->dst
.path
;
3308 strncpy(consumer
->dst
.trace_path
, path
,
3309 sizeof(consumer
->dst
.trace_path
));
3313 /* Set if the consumer is enabled or not */
3314 consumer
->enabled
= enable_consumer
;
3316 ret
= session_create(name
, path
, LTTNG_SOCK_GET_UID_CRED(creds
),
3317 LTTNG_SOCK_GET_GID_CRED(creds
));
3318 if (ret
!= LTTCOMM_OK
) {
3319 goto consumer_error
;
3322 /* Get the newly created session pointer back */
3323 session
= session_find_by_name(name
);
3326 /* Assign consumer to session */
3327 session
->consumer
= consumer
;
3332 consumer_destroy_output(consumer
);
3338 * Command LTTNG_CREATE_SESSION processed by the client thread.
3340 static int cmd_create_session(char *name
, char *path
, lttng_sock_cred
*creds
)
3343 struct lttng_uri uri
;
3345 /* Zeroed temporary URI */
3346 memset(&uri
, 0, sizeof(uri
));
3348 uri
.dtype
= LTTNG_DST_PATH
;
3349 uri
.utype
= LTTNG_URI_DST
;
3350 strncpy(uri
.dst
.path
, path
, sizeof(uri
.dst
.path
));
3352 /* TODO: Strip date-time from path and put it in uri's subdir */
3354 ret
= cmd_create_session_uri(name
, &uri
, NULL
, 1, creds
);
3355 if (ret
!= LTTCOMM_OK
) {
3364 * Command LTTNG_DESTROY_SESSION processed by the client thread.
3366 static int cmd_destroy_session(struct ltt_session
*session
, char *name
)
3370 /* Clean kernel session teardown */
3371 teardown_kernel_session(session
);
3372 /* UST session teardown */
3373 teardown_ust_session(session
);
3376 * Must notify the kernel thread here to update it's poll setin order
3377 * to remove the channel(s)' fd just destroyed.
3379 ret
= notify_thread_pipe(kernel_poll_pipe
[1]);
3381 PERROR("write kernel poll pipe");
3384 ret
= session_destroy(session
);
3390 * Command LTTNG_CALIBRATE processed by the client thread.
3392 static int cmd_calibrate(int domain
, struct lttng_calibrate
*calibrate
)
3397 case LTTNG_DOMAIN_KERNEL
:
3399 struct lttng_kernel_calibrate kcalibrate
;
3401 kcalibrate
.type
= calibrate
->type
;
3402 ret
= kernel_calibrate(kernel_tracer_fd
, &kcalibrate
);
3404 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
3409 case LTTNG_DOMAIN_UST
:
3411 struct lttng_ust_calibrate ucalibrate
;
3413 ucalibrate
.type
= calibrate
->type
;
3414 ret
= ust_app_calibrate_glb(&ucalibrate
);
3416 ret
= LTTCOMM_UST_CALIBRATE_FAIL
;
3433 * Command LTTNG_REGISTER_CONSUMER processed by the client thread.
3435 static int cmd_register_consumer(struct ltt_session
*session
, int domain
,
3441 case LTTNG_DOMAIN_KERNEL
:
3442 /* Can't register a consumer if there is already one */
3443 if (session
->kernel_session
->consumer_fds_sent
!= 0) {
3444 ret
= LTTCOMM_KERN_CONSUMER_FAIL
;
3448 sock
= lttcomm_connect_unix_sock(sock_path
);
3450 ret
= LTTCOMM_CONNECT_FAIL
;
3454 session
->kernel_session
->consumer_fd
= sock
;
3457 /* TODO: Userspace tracing */
3469 * Command LTTNG_LIST_DOMAINS processed by the client thread.
3471 static ssize_t
cmd_list_domains(struct ltt_session
*session
,
3472 struct lttng_domain
**domains
)
3477 if (session
->kernel_session
!= NULL
) {
3478 DBG3("Listing domains found kernel domain");
3482 if (session
->ust_session
!= NULL
) {
3483 DBG3("Listing domains found UST global domain");
3487 *domains
= zmalloc(nb_dom
* sizeof(struct lttng_domain
));
3488 if (*domains
== NULL
) {
3489 ret
= -LTTCOMM_FATAL
;
3493 if (session
->kernel_session
!= NULL
) {
3494 (*domains
)[index
].type
= LTTNG_DOMAIN_KERNEL
;
3498 if (session
->ust_session
!= NULL
) {
3499 (*domains
)[index
].type
= LTTNG_DOMAIN_UST
;
3510 * Command LTTNG_LIST_CHANNELS processed by the client thread.
3512 static ssize_t
cmd_list_channels(int domain
, struct ltt_session
*session
,
3513 struct lttng_channel
**channels
)
3516 ssize_t nb_chan
= 0;
3519 case LTTNG_DOMAIN_KERNEL
:
3520 if (session
->kernel_session
!= NULL
) {
3521 nb_chan
= session
->kernel_session
->channel_count
;
3523 DBG3("Number of kernel channels %zd", nb_chan
);
3525 case LTTNG_DOMAIN_UST
:
3526 if (session
->ust_session
!= NULL
) {
3527 nb_chan
= lttng_ht_get_count(
3528 session
->ust_session
->domain_global
.channels
);
3530 DBG3("Number of UST global channels %zd", nb_chan
);
3539 *channels
= zmalloc(nb_chan
* sizeof(struct lttng_channel
));
3540 if (*channels
== NULL
) {
3541 ret
= -LTTCOMM_FATAL
;
3545 list_lttng_channels(domain
, session
, *channels
);
3557 * Command LTTNG_LIST_EVENTS processed by the client thread.
3559 static ssize_t
cmd_list_events(int domain
, struct ltt_session
*session
,
3560 char *channel_name
, struct lttng_event
**events
)
3563 ssize_t nb_event
= 0;
3566 case LTTNG_DOMAIN_KERNEL
:
3567 if (session
->kernel_session
!= NULL
) {
3568 nb_event
= list_lttng_kernel_events(channel_name
,
3569 session
->kernel_session
, events
);
3572 case LTTNG_DOMAIN_UST
:
3574 if (session
->ust_session
!= NULL
) {
3575 nb_event
= list_lttng_ust_global_events(channel_name
,
3576 &session
->ust_session
->domain_global
, events
);
3592 * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
3594 static int cmd_set_consumer_uri(int domain
, struct ltt_session
*session
,
3595 struct lttng_uri
*uri
)
3598 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3599 struct ltt_ust_session
*usess
= session
->ust_session
;
3600 struct consumer_output
*consumer
;
3602 /* Can't enable consumer after session started. */
3603 if (session
->enabled
) {
3604 ret
= LTTCOMM_TRACE_ALREADY_STARTED
;
3609 case LTTNG_DOMAIN_KERNEL
:
3610 /* Code flow error if we don't have a kernel session here. */
3613 /* Create consumer output if none exists */
3614 consumer
= ksess
->tmp_consumer
;
3615 if (consumer
== NULL
) {
3616 consumer
= consumer_copy_output(ksess
->consumer
);
3617 if (consumer
== NULL
) {
3618 ret
= LTTCOMM_FATAL
;
3621 /* Reassign new pointer */
3622 ksess
->tmp_consumer
= consumer
;
3625 switch (uri
->dtype
) {
3626 case LTTNG_DST_IPV4
:
3627 case LTTNG_DST_IPV6
:
3628 DBG2("Setting network URI for kernel session %s", session
->name
);
3630 /* Set URI into consumer output object */
3631 ret
= consumer_set_network_uri(consumer
, uri
);
3633 ret
= LTTCOMM_FATAL
;
3637 /* On a new subdir, reappend the default trace dir. */
3638 if (strlen(uri
->subdir
) != 0) {
3639 strncat(consumer
->subdir
, DEFAULT_KERNEL_TRACE_DIR
,
3640 sizeof(consumer
->subdir
));
3643 ret
= send_socket_relayd_consumer(domain
, session
, uri
, consumer
,
3644 ksess
->consumer_fd
);
3645 if (ret
!= LTTCOMM_OK
) {
3649 case LTTNG_DST_PATH
:
3650 DBG2("Setting trace directory path from URI to %s", uri
->dst
.path
);
3651 memset(consumer
->dst
.trace_path
, 0,
3652 sizeof(consumer
->dst
.trace_path
));
3653 strncpy(consumer
->dst
.trace_path
, uri
->dst
.path
,
3654 sizeof(consumer
->dst
.trace_path
));
3655 /* Append default kernel trace dir */
3656 strncat(consumer
->dst
.trace_path
, DEFAULT_KERNEL_TRACE_DIR
,
3657 sizeof(consumer
->dst
.trace_path
));
3663 case LTTNG_DOMAIN_UST
:
3664 /* Code flow error if we don't have a kernel session here. */
3667 /* Create consumer output if none exists */
3668 consumer
= usess
->tmp_consumer
;
3669 if (consumer
== NULL
) {
3670 consumer
= consumer_copy_output(usess
->consumer
);
3671 if (consumer
== NULL
) {
3672 ret
= LTTCOMM_FATAL
;
3675 /* Reassign new pointer */
3676 usess
->tmp_consumer
= consumer
;
3679 switch (uri
->dtype
) {
3680 case LTTNG_DST_IPV4
:
3681 case LTTNG_DST_IPV6
:
3683 DBG2("Setting network URI for UST session %s", session
->name
);
3685 /* Set URI into consumer object */
3686 ret
= consumer_set_network_uri(consumer
, uri
);
3688 ret
= LTTCOMM_FATAL
;
3692 /* On a new subdir, reappend the default trace dir. */
3693 if (strlen(uri
->subdir
) != 0) {
3694 strncat(consumer
->subdir
, DEFAULT_UST_TRACE_DIR
,
3695 sizeof(consumer
->subdir
));
3698 if (ust_consumerd64_fd
>= 0) {
3699 ret
= send_socket_relayd_consumer(domain
, session
, uri
,
3700 consumer
, ust_consumerd64_fd
);
3701 if (ret
!= LTTCOMM_OK
) {
3706 if (ust_consumerd32_fd
>= 0) {
3707 ret
= send_socket_relayd_consumer(domain
, session
, uri
,
3708 consumer
, ust_consumerd32_fd
);
3709 if (ret
!= LTTCOMM_OK
) {
3716 case LTTNG_DST_PATH
:
3717 DBG2("Setting trace directory path from URI to %s", uri
->dst
.path
);
3718 memset(consumer
->dst
.trace_path
, 0,
3719 sizeof(consumer
->dst
.trace_path
));
3720 strncpy(consumer
->dst
.trace_path
, uri
->dst
.path
,
3721 sizeof(consumer
->dst
.trace_path
));
3722 /* Append default UST trace dir */
3723 strncat(consumer
->dst
.trace_path
, DEFAULT_UST_TRACE_DIR
,
3724 sizeof(consumer
->dst
.trace_path
));
3738 * Command LTTNG_DISABLE_CONSUMER processed by the client thread.
3740 static int cmd_disable_consumer(int domain
, struct ltt_session
*session
)
3743 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3744 struct ltt_ust_session
*usess
= session
->ust_session
;
3745 struct consumer_output
*consumer
;
3747 if (session
->enabled
) {
3748 /* Can't disable consumer on an already started session */
3749 ret
= LTTCOMM_TRACE_ALREADY_STARTED
;
3754 case LTTNG_DOMAIN_KERNEL
:
3755 /* Code flow error if we don't have a kernel session here. */
3758 DBG("Disabling kernel consumer");
3759 consumer
= ksess
->consumer
;
3762 case LTTNG_DOMAIN_UST
:
3763 /* Code flow error if we don't have a UST session here. */
3766 DBG("Disabling UST consumer");
3767 consumer
= usess
->consumer
;
3771 ret
= LTTCOMM_UNKNOWN_DOMAIN
;
3776 consumer
->enabled
= 0;
3778 /* Success at this point */
3786 * Command LTTNG_ENABLE_CONSUMER processed by the client thread.
3788 static int cmd_enable_consumer(int domain
, struct ltt_session
*session
)
3791 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3792 struct ltt_ust_session
*usess
= session
->ust_session
;
3793 struct consumer_output
*tmp_out
;
3795 /* Can't enable consumer after session started. */
3796 if (session
->enabled
) {
3797 ret
= LTTCOMM_TRACE_ALREADY_STARTED
;
3802 case LTTNG_DOMAIN_KERNEL
:
3803 /* Code flow error if we don't have a kernel session here. */
3807 * Check if we have already sent fds to the consumer. In that case,
3808 * the enable-consumer command can't be used because a start trace
3809 * had previously occured.
3811 if (ksess
->consumer_fds_sent
) {
3812 ret
= LTTCOMM_ENABLE_CONSUMER_FAIL
;
3816 tmp_out
= ksess
->tmp_consumer
;
3817 if (tmp_out
== NULL
) {
3818 /* No temp. consumer output exists. Using the current one. */
3819 DBG3("No temporary consumer. Using default");
3824 switch (tmp_out
->type
) {
3825 case CONSUMER_DST_LOCAL
:
3826 DBG2("Consumer output is local. Creating directory(ies)");
3828 /* Create directory(ies) */
3829 ret
= run_as_mkdir_recursive(tmp_out
->dst
.trace_path
,
3830 S_IRWXU
| S_IRWXG
, session
->uid
, session
->gid
);
3832 if (ret
!= -EEXIST
) {
3833 ERR("Trace directory creation error");
3834 ret
= LTTCOMM_FATAL
;
3839 case CONSUMER_DST_NET
:
3840 DBG2("Consumer output is network. Validating URIs");
3841 /* Validate if we have both control and data path set. */
3842 if (!tmp_out
->dst
.net
.control_isset
) {
3843 ret
= LTTCOMM_URI_CTRL_MISS
;
3847 if (!tmp_out
->dst
.net
.data_isset
) {
3848 ret
= LTTCOMM_URI_DATA_MISS
;
3852 /* Check established network session state */
3853 if (session
->net_handle
== 0) {
3854 ret
= LTTCOMM_ENABLE_CONSUMER_FAIL
;
3855 ERR("Session network handle is not set on enable-consumer");
3859 /* Append default kernel trace dir to subdir */
3860 strncat(ksess
->consumer
->subdir
, DEFAULT_KERNEL_TRACE_DIR
,
3861 sizeof(ksess
->consumer
->subdir
));
3868 * This is race free for now since the session lock is acquired before
3869 * ending up in this function. No other threads can access this kernel
3870 * session without this lock hence freeing the consumer output object
3873 consumer_destroy_output(ksess
->consumer
);
3874 ksess
->consumer
= tmp_out
;
3875 ksess
->tmp_consumer
= NULL
;
3878 case LTTNG_DOMAIN_UST
:
3879 /* Code flow error if we don't have a UST session here. */
3883 * Check if we have already sent fds to the consumer. In that case,
3884 * the enable-consumer command can't be used because a start trace
3885 * had previously occured.
3887 if (usess
->start_trace
) {
3888 ret
= LTTCOMM_ENABLE_CONSUMER_FAIL
;
3892 tmp_out
= usess
->tmp_consumer
;
3893 if (tmp_out
== NULL
) {
3894 /* No temp. consumer output exists. Using the current one. */
3895 DBG3("No temporary consumer. Using default");
3900 switch (tmp_out
->type
) {
3901 case CONSUMER_DST_LOCAL
:
3902 DBG2("Consumer output is local. Creating directory(ies)");
3904 /* Create directory(ies) */
3905 ret
= run_as_mkdir_recursive(tmp_out
->dst
.trace_path
,
3906 S_IRWXU
| S_IRWXG
, session
->uid
, session
->gid
);
3908 if (ret
!= -EEXIST
) {
3909 ERR("Trace directory creation error");
3910 ret
= LTTCOMM_FATAL
;
3915 case CONSUMER_DST_NET
:
3916 DBG2("Consumer output is network. Validating URIs");
3917 /* Validate if we have both control and data path set. */
3918 if (!tmp_out
->dst
.net
.control_isset
) {
3919 ret
= LTTCOMM_URI_CTRL_MISS
;
3923 if (!tmp_out
->dst
.net
.data_isset
) {
3924 ret
= LTTCOMM_URI_DATA_MISS
;
3928 /* Check established network session state */
3929 if (session
->net_handle
== 0) {
3930 ret
= LTTCOMM_ENABLE_CONSUMER_FAIL
;
3931 DBG2("Session network handle is not set on enable-consumer");
3935 if (tmp_out
->net_seq_index
== -1) {
3936 ret
= LTTCOMM_ENABLE_CONSUMER_FAIL
;
3937 DBG2("Network index is not set on the consumer");
3941 /* Append default kernel trace dir to subdir */
3942 strncat(usess
->consumer
->subdir
, DEFAULT_UST_TRACE_DIR
,
3943 sizeof(usess
->consumer
->subdir
));
3950 * This is race free for now since the session lock is acquired before
3951 * ending up in this function. No other threads can access this kernel
3952 * session without this lock hence freeing the consumer output object
3955 consumer_destroy_output(usess
->consumer
);
3956 usess
->consumer
= tmp_out
;
3957 usess
->tmp_consumer
= NULL
;
3962 /* Success at this point */
3970 * Process the command requested by the lttng client within the command
3971 * context structure. This function make sure that the return structure (llm)
3972 * is set and ready for transmission before returning.
3974 * Return any error encountered or 0 for success.
3976 * "sock" is only used for special-case var. len data.
3978 static int process_client_msg(struct command_ctx
*cmd_ctx
, int sock
,
3981 int ret
= LTTCOMM_OK
;
3982 int need_tracing_session
= 1;
3985 DBG("Processing client command %d", cmd_ctx
->lsm
->cmd_type
);
3989 switch (cmd_ctx
->lsm
->cmd_type
) {
3990 case LTTNG_CREATE_SESSION
:
3991 case LTTNG_CREATE_SESSION_URI
:
3992 case LTTNG_DESTROY_SESSION
:
3993 case LTTNG_LIST_SESSIONS
:
3994 case LTTNG_LIST_DOMAINS
:
3995 case LTTNG_START_TRACE
:
3996 case LTTNG_STOP_TRACE
:
4003 if (opt_no_kernel
&& need_domain
4004 && cmd_ctx
->lsm
->domain
.type
== LTTNG_DOMAIN_KERNEL
) {
4006 ret
= LTTCOMM_NEED_ROOT_SESSIOND
;
4008 ret
= LTTCOMM_KERN_NA
;
4014 * Check for command that don't needs to allocate a returned payload. We do
4015 * this here so we don't have to make the call for no payload at each
4018 switch(cmd_ctx
->lsm
->cmd_type
) {
4019 case LTTNG_LIST_SESSIONS
:
4020 case LTTNG_LIST_TRACEPOINTS
:
4021 case LTTNG_LIST_TRACEPOINT_FIELDS
:
4022 case LTTNG_LIST_DOMAINS
:
4023 case LTTNG_LIST_CHANNELS
:
4024 case LTTNG_LIST_EVENTS
:
4027 /* Setup lttng message with no payload */
4028 ret
= setup_lttng_msg(cmd_ctx
, 0);
4030 /* This label does not try to unlock the session */
4031 goto init_setup_error
;
4035 /* Commands that DO NOT need a session. */
4036 switch (cmd_ctx
->lsm
->cmd_type
) {
4037 case LTTNG_CREATE_SESSION
:
4038 case LTTNG_CREATE_SESSION_URI
:
4039 case LTTNG_CALIBRATE
:
4040 case LTTNG_LIST_SESSIONS
:
4041 case LTTNG_LIST_TRACEPOINTS
:
4042 case LTTNG_LIST_TRACEPOINT_FIELDS
:
4043 need_tracing_session
= 0;
4046 DBG("Getting session %s by name", cmd_ctx
->lsm
->session
.name
);
4048 * We keep the session list lock across _all_ commands
4049 * for now, because the per-session lock does not
4050 * handle teardown properly.
4052 session_lock_list();
4053 cmd_ctx
->session
= session_find_by_name(cmd_ctx
->lsm
->session
.name
);
4054 if (cmd_ctx
->session
== NULL
) {
4055 if (cmd_ctx
->lsm
->session
.name
!= NULL
) {
4056 ret
= LTTCOMM_SESS_NOT_FOUND
;
4058 /* If no session name specified */
4059 ret
= LTTCOMM_SELECT_SESS
;
4063 /* Acquire lock for the session */
4064 session_lock(cmd_ctx
->session
);
4073 * Check domain type for specific "pre-action".
4075 switch (cmd_ctx
->lsm
->domain
.type
) {
4076 case LTTNG_DOMAIN_KERNEL
:
4078 ret
= LTTCOMM_NEED_ROOT_SESSIOND
;
4082 /* Kernel tracer check */
4083 if (kernel_tracer_fd
== -1) {
4084 /* Basically, load kernel tracer modules */
4085 ret
= init_kernel_tracer();
4091 /* Consumer is in an ERROR state. Report back to client */
4092 if (uatomic_read(&kernel_consumerd_state
) == CONSUMER_ERROR
) {
4093 ret
= LTTCOMM_NO_KERNCONSUMERD
;
4097 /* Need a session for kernel command */
4098 if (need_tracing_session
) {
4099 if (cmd_ctx
->session
->kernel_session
== NULL
) {
4100 ret
= create_kernel_session(cmd_ctx
->session
);
4102 ret
= LTTCOMM_KERN_SESS_FAIL
;
4107 /* Start the kernel consumer daemon */
4108 pthread_mutex_lock(&kconsumer_data
.pid_mutex
);
4109 if (kconsumer_data
.pid
== 0 &&
4110 cmd_ctx
->lsm
->cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
4111 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
4112 ret
= start_consumerd(&kconsumer_data
);
4114 ret
= LTTCOMM_KERN_CONSUMER_FAIL
;
4117 uatomic_set(&kernel_consumerd_state
, CONSUMER_STARTED
);
4119 /* Set consumer fd of the session */
4120 cmd_ctx
->session
->kernel_session
->consumer_fd
=
4121 kconsumer_data
.cmd_sock
;
4123 pthread_mutex_unlock(&kconsumer_data
.pid_mutex
);
4128 case LTTNG_DOMAIN_UST
:
4130 /* Consumer is in an ERROR state. Report back to client */
4131 if (uatomic_read(&ust_consumerd_state
) == CONSUMER_ERROR
) {
4132 ret
= LTTCOMM_NO_USTCONSUMERD
;
4136 if (need_tracing_session
) {
4137 if (cmd_ctx
->session
->ust_session
== NULL
) {
4138 ret
= create_ust_session(cmd_ctx
->session
,
4139 &cmd_ctx
->lsm
->domain
);
4140 if (ret
!= LTTCOMM_OK
) {
4145 /* Start the UST consumer daemons */
4147 pthread_mutex_lock(&ustconsumer64_data
.pid_mutex
);
4148 if (consumerd64_bin
[0] != '\0' &&
4149 ustconsumer64_data
.pid
== 0 &&
4150 cmd_ctx
->lsm
->cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
4151 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
4152 ret
= start_consumerd(&ustconsumer64_data
);
4154 ret
= LTTCOMM_UST_CONSUMER64_FAIL
;
4155 ust_consumerd64_fd
= -EINVAL
;
4159 ust_consumerd64_fd
= ustconsumer64_data
.cmd_sock
;
4160 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
4162 pthread_mutex_unlock(&ustconsumer64_data
.pid_mutex
);
4165 if (consumerd32_bin
[0] != '\0' &&
4166 ustconsumer32_data
.pid
== 0 &&
4167 cmd_ctx
->lsm
->cmd_type
!= LTTNG_REGISTER_CONSUMER
) {
4168 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
4169 ret
= start_consumerd(&ustconsumer32_data
);
4171 ret
= LTTCOMM_UST_CONSUMER32_FAIL
;
4172 ust_consumerd32_fd
= -EINVAL
;
4176 ust_consumerd32_fd
= ustconsumer32_data
.cmd_sock
;
4177 uatomic_set(&ust_consumerd_state
, CONSUMER_STARTED
);
4179 pthread_mutex_unlock(&ustconsumer32_data
.pid_mutex
);
4189 /* Validate consumer daemon state when start/stop trace command */
4190 if (cmd_ctx
->lsm
->cmd_type
== LTTNG_START_TRACE
||
4191 cmd_ctx
->lsm
->cmd_type
== LTTNG_STOP_TRACE
) {
4192 switch (cmd_ctx
->lsm
->domain
.type
) {
4193 case LTTNG_DOMAIN_UST
:
4194 if (uatomic_read(&ust_consumerd_state
) != CONSUMER_STARTED
) {
4195 ret
= LTTCOMM_NO_USTCONSUMERD
;
4199 case LTTNG_DOMAIN_KERNEL
:
4200 if (uatomic_read(&kernel_consumerd_state
) != CONSUMER_STARTED
) {
4201 ret
= LTTCOMM_NO_KERNCONSUMERD
;
4209 * Check that the UID or GID match that of the tracing session.
4210 * The root user can interact with all sessions.
4212 if (need_tracing_session
) {
4213 if (!session_access_ok(cmd_ctx
->session
,
4214 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
4215 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
))) {
4216 ret
= LTTCOMM_EPERM
;
4221 /* Process by command type */
4222 switch (cmd_ctx
->lsm
->cmd_type
) {
4223 case LTTNG_ADD_CONTEXT
:
4225 ret
= cmd_add_context(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4226 cmd_ctx
->lsm
->u
.context
.channel_name
,
4227 cmd_ctx
->lsm
->u
.context
.event_name
,
4228 &cmd_ctx
->lsm
->u
.context
.ctx
);
4231 case LTTNG_DISABLE_CHANNEL
:
4233 ret
= cmd_disable_channel(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4234 cmd_ctx
->lsm
->u
.disable
.channel_name
);
4237 case LTTNG_DISABLE_EVENT
:
4239 ret
= cmd_disable_event(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4240 cmd_ctx
->lsm
->u
.disable
.channel_name
,
4241 cmd_ctx
->lsm
->u
.disable
.name
);
4244 case LTTNG_DISABLE_ALL_EVENT
:
4246 DBG("Disabling all events");
4248 ret
= cmd_disable_event_all(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4249 cmd_ctx
->lsm
->u
.disable
.channel_name
);
4252 case LTTNG_DISABLE_CONSUMER
:
4254 ret
= cmd_disable_consumer(cmd_ctx
->lsm
->domain
.type
, cmd_ctx
->session
);
4257 case LTTNG_ENABLE_CHANNEL
:
4259 ret
= cmd_enable_channel(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4260 &cmd_ctx
->lsm
->u
.channel
.chan
);
4263 case LTTNG_ENABLE_CONSUMER
:
4265 ret
= cmd_enable_consumer(cmd_ctx
->lsm
->domain
.type
, cmd_ctx
->session
);
4268 case LTTNG_ENABLE_EVENT
:
4270 ret
= cmd_enable_event(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4271 cmd_ctx
->lsm
->u
.enable
.channel_name
,
4272 &cmd_ctx
->lsm
->u
.enable
.event
);
4275 case LTTNG_ENABLE_ALL_EVENT
:
4277 DBG("Enabling all events");
4279 ret
= cmd_enable_event_all(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4280 cmd_ctx
->lsm
->u
.enable
.channel_name
,
4281 cmd_ctx
->lsm
->u
.enable
.event
.type
);
4284 case LTTNG_LIST_TRACEPOINTS
:
4286 struct lttng_event
*events
;
4289 nb_events
= cmd_list_tracepoints(cmd_ctx
->lsm
->domain
.type
, &events
);
4290 if (nb_events
< 0) {
4296 * Setup lttng message with payload size set to the event list size in
4297 * bytes and then copy list into the llm payload.
4299 ret
= setup_lttng_msg(cmd_ctx
, sizeof(struct lttng_event
) * nb_events
);
4305 /* Copy event list into message payload */
4306 memcpy(cmd_ctx
->llm
->payload
, events
,
4307 sizeof(struct lttng_event
) * nb_events
);
4314 case LTTNG_LIST_TRACEPOINT_FIELDS
:
4316 struct lttng_event_field
*fields
;
4319 nb_fields
= cmd_list_tracepoint_fields(cmd_ctx
->lsm
->domain
.type
, &fields
);
4320 if (nb_fields
< 0) {
4326 * Setup lttng message with payload size set to the event list size in
4327 * bytes and then copy list into the llm payload.
4329 ret
= setup_lttng_msg(cmd_ctx
, sizeof(struct lttng_event_field
) * nb_fields
);
4335 /* Copy event list into message payload */
4336 memcpy(cmd_ctx
->llm
->payload
, fields
,
4337 sizeof(struct lttng_event_field
) * nb_fields
);
4344 case LTTNG_SET_CONSUMER_URI
:
4346 ret
= cmd_set_consumer_uri(cmd_ctx
->lsm
->domain
.type
, cmd_ctx
->session
,
4347 &cmd_ctx
->lsm
->u
.uri
);
4350 case LTTNG_START_TRACE
:
4352 ret
= cmd_start_trace(cmd_ctx
->session
);
4355 case LTTNG_STOP_TRACE
:
4357 ret
= cmd_stop_trace(cmd_ctx
->session
);
4360 case LTTNG_CREATE_SESSION
:
4362 ret
= cmd_create_session(cmd_ctx
->lsm
->session
.name
,
4363 cmd_ctx
->lsm
->session
.path
, &cmd_ctx
->creds
);
4366 case LTTNG_CREATE_SESSION_URI
:
4368 ret
= cmd_create_session_uri(cmd_ctx
->lsm
->session
.name
,
4369 &cmd_ctx
->lsm
->u
.create_uri
.ctrl_uri
,
4370 &cmd_ctx
->lsm
->u
.create_uri
.data_uri
,
4371 cmd_ctx
->lsm
->u
.create_uri
.enable_consumer
, &cmd_ctx
->creds
);
4374 case LTTNG_DESTROY_SESSION
:
4376 ret
= cmd_destroy_session(cmd_ctx
->session
,
4377 cmd_ctx
->lsm
->session
.name
);
4379 * Set session to NULL so we do not unlock it after
4382 cmd_ctx
->session
= NULL
;
4385 case LTTNG_LIST_DOMAINS
:
4388 struct lttng_domain
*domains
;
4390 nb_dom
= cmd_list_domains(cmd_ctx
->session
, &domains
);
4396 ret
= setup_lttng_msg(cmd_ctx
, nb_dom
* sizeof(struct lttng_domain
));
4401 /* Copy event list into message payload */
4402 memcpy(cmd_ctx
->llm
->payload
, domains
,
4403 nb_dom
* sizeof(struct lttng_domain
));
4410 case LTTNG_LIST_CHANNELS
:
4413 struct lttng_channel
*channels
;
4415 nb_chan
= cmd_list_channels(cmd_ctx
->lsm
->domain
.type
,
4416 cmd_ctx
->session
, &channels
);
4422 ret
= setup_lttng_msg(cmd_ctx
, nb_chan
* sizeof(struct lttng_channel
));
4427 /* Copy event list into message payload */
4428 memcpy(cmd_ctx
->llm
->payload
, channels
,
4429 nb_chan
* sizeof(struct lttng_channel
));
4436 case LTTNG_LIST_EVENTS
:
4439 struct lttng_event
*events
= NULL
;
4441 nb_event
= cmd_list_events(cmd_ctx
->lsm
->domain
.type
, cmd_ctx
->session
,
4442 cmd_ctx
->lsm
->u
.list
.channel_name
, &events
);
4448 ret
= setup_lttng_msg(cmd_ctx
, nb_event
* sizeof(struct lttng_event
));
4453 /* Copy event list into message payload */
4454 memcpy(cmd_ctx
->llm
->payload
, events
,
4455 nb_event
* sizeof(struct lttng_event
));
4462 case LTTNG_LIST_SESSIONS
:
4464 unsigned int nr_sessions
;
4466 session_lock_list();
4467 nr_sessions
= lttng_sessions_count(
4468 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
4469 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
4471 ret
= setup_lttng_msg(cmd_ctx
, sizeof(struct lttng_session
) * nr_sessions
);
4473 session_unlock_list();
4477 /* Filled the session array */
4478 list_lttng_sessions((struct lttng_session
*)(cmd_ctx
->llm
->payload
),
4479 LTTNG_SOCK_GET_UID_CRED(&cmd_ctx
->creds
),
4480 LTTNG_SOCK_GET_GID_CRED(&cmd_ctx
->creds
));
4482 session_unlock_list();
4487 case LTTNG_CALIBRATE
:
4489 ret
= cmd_calibrate(cmd_ctx
->lsm
->domain
.type
,
4490 &cmd_ctx
->lsm
->u
.calibrate
);
4493 case LTTNG_REGISTER_CONSUMER
:
4495 ret
= cmd_register_consumer(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4496 cmd_ctx
->lsm
->u
.reg
.path
);
4499 case LTTNG_SET_FILTER
:
4501 struct lttng_filter_bytecode
*bytecode
;
4503 if (cmd_ctx
->lsm
->u
.filter
.bytecode_len
> 65336) {
4504 ret
= LTTCOMM_FILTER_INVAL
;
4507 bytecode
= zmalloc(cmd_ctx
->lsm
->u
.filter
.bytecode_len
);
4509 ret
= LTTCOMM_FILTER_NOMEM
;
4512 /* Receive var. len. data */
4513 DBG("Receiving var len data from client ...");
4514 ret
= lttcomm_recv_unix_sock(sock
, bytecode
,
4515 cmd_ctx
->lsm
->u
.filter
.bytecode_len
);
4517 DBG("Nothing recv() from client var len data... continuing");
4519 ret
= LTTCOMM_FILTER_INVAL
;
4523 if (bytecode
->len
+ sizeof(*bytecode
)
4524 != cmd_ctx
->lsm
->u
.filter
.bytecode_len
) {
4526 ret
= LTTCOMM_FILTER_INVAL
;
4530 ret
= cmd_set_filter(cmd_ctx
->session
, cmd_ctx
->lsm
->domain
.type
,
4531 cmd_ctx
->lsm
->u
.filter
.channel_name
,
4532 cmd_ctx
->lsm
->u
.filter
.event_name
,
4542 if (cmd_ctx
->llm
== NULL
) {
4543 DBG("Missing llm structure. Allocating one.");
4544 if (setup_lttng_msg(cmd_ctx
, 0) < 0) {
4548 /* Set return code */
4549 cmd_ctx
->llm
->ret_code
= ret
;
4551 if (cmd_ctx
->session
) {
4552 session_unlock(cmd_ctx
->session
);
4554 if (need_tracing_session
) {
4555 session_unlock_list();
4562 * This thread manage all clients request using the unix client socket for
4565 static void *thread_manage_clients(void *data
)
4567 int sock
= -1, ret
, i
, pollfd
;
4569 uint32_t revents
, nb_fd
;
4570 struct command_ctx
*cmd_ctx
= NULL
;
4571 struct lttng_poll_event events
;
4573 DBG("[thread] Manage client started");
4575 rcu_register_thread();
4577 ret
= lttcomm_listen_unix_sock(client_sock
);
4583 * Pass 2 as size here for the thread quit pipe and client_sock. Nothing
4584 * more will be added to this poll set.
4586 ret
= create_thread_poll_set(&events
, 2);
4591 /* Add the application registration socket */
4592 ret
= lttng_poll_add(&events
, client_sock
, LPOLLIN
| LPOLLPRI
);
4598 * Notify parent pid that we are ready to accept command for client side.
4600 if (opt_sig_parent
) {
4601 kill(ppid
, SIGUSR1
);
4605 DBG("Accepting client command ...");
4607 nb_fd
= LTTNG_POLL_GETNB(&events
);
4609 /* Inifinite blocking call, waiting for transmission */
4611 ret
= lttng_poll_wait(&events
, -1);
4614 * Restart interrupted system call.
4616 if (errno
== EINTR
) {
4622 for (i
= 0; i
< nb_fd
; i
++) {
4623 /* Fetch once the poll data */
4624 revents
= LTTNG_POLL_GETEV(&events
, i
);
4625 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
4627 /* Thread quit pipe has been closed. Killing thread. */
4628 ret
= check_thread_quit_pipe(pollfd
, revents
);
4633 /* Event on the registration socket */
4634 if (pollfd
== client_sock
) {
4635 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
4636 ERR("Client socket poll error");
4642 DBG("Wait for client response");
4644 sock
= lttcomm_accept_unix_sock(client_sock
);
4649 /* Set socket option for credentials retrieval */
4650 ret
= lttcomm_setsockopt_creds_unix_sock(sock
);
4655 /* Allocate context command to process the client request */
4656 cmd_ctx
= zmalloc(sizeof(struct command_ctx
));
4657 if (cmd_ctx
== NULL
) {
4658 PERROR("zmalloc cmd_ctx");
4662 /* Allocate data buffer for reception */
4663 cmd_ctx
->lsm
= zmalloc(sizeof(struct lttcomm_session_msg
));
4664 if (cmd_ctx
->lsm
== NULL
) {
4665 PERROR("zmalloc cmd_ctx->lsm");
4669 cmd_ctx
->llm
= NULL
;
4670 cmd_ctx
->session
= NULL
;
4673 * Data is received from the lttng client. The struct
4674 * lttcomm_session_msg (lsm) contains the command and data request of
4677 DBG("Receiving data from client ...");
4678 ret
= lttcomm_recv_creds_unix_sock(sock
, cmd_ctx
->lsm
,
4679 sizeof(struct lttcomm_session_msg
), &cmd_ctx
->creds
);
4681 DBG("Nothing recv() from client... continuing");
4687 clean_command_ctx(&cmd_ctx
);
4691 // TODO: Validate cmd_ctx including sanity check for
4692 // security purpose.
4694 rcu_thread_online();
4696 * This function dispatch the work to the kernel or userspace tracer
4697 * libs and fill the lttcomm_lttng_msg data structure of all the needed
4698 * informations for the client. The command context struct contains
4699 * everything this function may needs.
4701 ret
= process_client_msg(cmd_ctx
, sock
, &sock_error
);
4702 rcu_thread_offline();
4712 * TODO: Inform client somehow of the fatal error. At
4713 * this point, ret < 0 means that a zmalloc failed
4714 * (ENOMEM). Error detected but still accept
4715 * command, unless a socket error has been
4718 clean_command_ctx(&cmd_ctx
);
4722 DBG("Sending response (size: %d, retcode: %s)",
4723 cmd_ctx
->lttng_msg_size
,
4724 lttng_strerror(-cmd_ctx
->llm
->ret_code
));
4725 ret
= send_unix_sock(sock
, cmd_ctx
->llm
, cmd_ctx
->lttng_msg_size
);
4727 ERR("Failed to send data back to client");
4730 /* End of transmission */
4737 clean_command_ctx(&cmd_ctx
);
4741 DBG("Client thread dying");
4742 unlink(client_unix_sock_path
);
4743 if (client_sock
>= 0) {
4744 ret
= close(client_sock
);
4756 lttng_poll_clean(&events
);
4757 clean_command_ctx(&cmd_ctx
);
4759 rcu_unregister_thread();
4765 * usage function on stderr
4767 static void usage(void)
4769 fprintf(stderr
, "Usage: %s OPTIONS\n\nOptions:\n", progname
);
4770 fprintf(stderr
, " -h, --help Display this usage.\n");
4771 fprintf(stderr
, " -c, --client-sock PATH Specify path for the client unix socket\n");
4772 fprintf(stderr
, " -a, --apps-sock PATH Specify path for apps unix socket\n");
4773 fprintf(stderr
, " --kconsumerd-err-sock PATH Specify path for the kernel consumer error socket\n");
4774 fprintf(stderr
, " --kconsumerd-cmd-sock PATH Specify path for the kernel consumer command socket\n");
4775 fprintf(stderr
, " --ustconsumerd32-err-sock PATH Specify path for the 32-bit UST consumer error socket\n");
4776 fprintf(stderr
, " --ustconsumerd64-err-sock PATH Specify path for the 64-bit UST consumer error socket\n");
4777 fprintf(stderr
, " --ustconsumerd32-cmd-sock PATH Specify path for the 32-bit UST consumer command socket\n");
4778 fprintf(stderr
, " --ustconsumerd64-cmd-sock PATH Specify path for the 64-bit UST consumer command socket\n");
4779 fprintf(stderr
, " --consumerd32-path PATH Specify path for the 32-bit UST consumer daemon binary\n");
4780 fprintf(stderr
, " --consumerd32-libdir PATH Specify path for the 32-bit UST consumer daemon libraries\n");
4781 fprintf(stderr
, " --consumerd64-path PATH Specify path for the 64-bit UST consumer daemon binary\n");
4782 fprintf(stderr
, " --consumerd64-libdir PATH Specify path for the 64-bit UST consumer daemon libraries\n");
4783 fprintf(stderr
, " -d, --daemonize Start as a daemon.\n");
4784 fprintf(stderr
, " -g, --group NAME Specify the tracing group name. (default: tracing)\n");
4785 fprintf(stderr
, " -V, --version Show version number.\n");
4786 fprintf(stderr
, " -S, --sig-parent Send SIGCHLD to parent pid to notify readiness.\n");
4787 fprintf(stderr
, " -q, --quiet No output at all.\n");
4788 fprintf(stderr
, " -v, --verbose Verbose mode. Activate DBG() macro.\n");
4789 fprintf(stderr
, " --verbose-consumer Verbose mode for consumer. Activate DBG() macro.\n");
4790 fprintf(stderr
, " --no-kernel Disable kernel tracer\n");
4794 * daemon argument parsing
4796 static int parse_args(int argc
, char **argv
)
4800 static struct option long_options
[] = {
4801 { "client-sock", 1, 0, 'c' },
4802 { "apps-sock", 1, 0, 'a' },
4803 { "kconsumerd-cmd-sock", 1, 0, 'C' },
4804 { "kconsumerd-err-sock", 1, 0, 'E' },
4805 { "ustconsumerd32-cmd-sock", 1, 0, 'G' },
4806 { "ustconsumerd32-err-sock", 1, 0, 'H' },
4807 { "ustconsumerd64-cmd-sock", 1, 0, 'D' },
4808 { "ustconsumerd64-err-sock", 1, 0, 'F' },
4809 { "consumerd32-path", 1, 0, 'u' },
4810 { "consumerd32-libdir", 1, 0, 'U' },
4811 { "consumerd64-path", 1, 0, 't' },
4812 { "consumerd64-libdir", 1, 0, 'T' },
4813 { "daemonize", 0, 0, 'd' },
4814 { "sig-parent", 0, 0, 'S' },
4815 { "help", 0, 0, 'h' },
4816 { "group", 1, 0, 'g' },
4817 { "version", 0, 0, 'V' },
4818 { "quiet", 0, 0, 'q' },
4819 { "verbose", 0, 0, 'v' },
4820 { "verbose-consumer", 0, 0, 'Z' },
4821 { "no-kernel", 0, 0, 'N' },
4826 int option_index
= 0;
4827 c
= getopt_long(argc
, argv
, "dhqvVSN" "a:c:g:s:C:E:D:F:Z:u:t",
4828 long_options
, &option_index
);
4835 fprintf(stderr
, "option %s", long_options
[option_index
].name
);
4837 fprintf(stderr
, " with arg %s\n", optarg
);
4841 snprintf(client_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4844 snprintf(apps_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4850 opt_tracing_group
= optarg
;
4856 fprintf(stdout
, "%s\n", VERSION
);
4862 snprintf(kconsumer_data
.err_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4865 snprintf(kconsumer_data
.cmd_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4868 snprintf(ustconsumer64_data
.err_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4871 snprintf(ustconsumer64_data
.cmd_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4874 snprintf(ustconsumer32_data
.err_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4877 snprintf(ustconsumer32_data
.cmd_unix_sock_path
, PATH_MAX
, "%s", optarg
);
4883 lttng_opt_quiet
= 1;
4886 /* Verbose level can increase using multiple -v */
4887 lttng_opt_verbose
+= 1;
4890 opt_verbose_consumer
+= 1;
4893 consumerd32_bin
= optarg
;
4896 consumerd32_libdir
= optarg
;
4899 consumerd64_bin
= optarg
;
4902 consumerd64_libdir
= optarg
;
4905 /* Unknown option or other error.
4906 * Error is printed by getopt, just return */
4915 * Creates the two needed socket by the daemon.
4916 * apps_sock - The communication socket for all UST apps.
4917 * client_sock - The communication of the cli tool (lttng).
4919 static int init_daemon_socket(void)
4924 old_umask
= umask(0);
4926 /* Create client tool unix socket */
4927 client_sock
= lttcomm_create_unix_sock(client_unix_sock_path
);
4928 if (client_sock
< 0) {
4929 ERR("Create unix sock failed: %s", client_unix_sock_path
);
4934 /* File permission MUST be 660 */
4935 ret
= chmod(client_unix_sock_path
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
4937 ERR("Set file permissions failed: %s", client_unix_sock_path
);
4942 /* Create the application unix socket */
4943 apps_sock
= lttcomm_create_unix_sock(apps_unix_sock_path
);
4944 if (apps_sock
< 0) {
4945 ERR("Create unix sock failed: %s", apps_unix_sock_path
);
4950 /* File permission MUST be 666 */
4951 ret
= chmod(apps_unix_sock_path
,
4952 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
);
4954 ERR("Set file permissions failed: %s", apps_unix_sock_path
);
4965 * Check if the global socket is available, and if a daemon is answering at the
4966 * other side. If yes, error is returned.
4968 static int check_existing_daemon(void)
4970 /* Is there anybody out there ? */
4971 if (lttng_session_daemon_alive()) {
4979 * Set the tracing group gid onto the client socket.
4981 * Race window between mkdir and chown is OK because we are going from more
4982 * permissive (root.root) to less permissive (root.tracing).
4984 static int set_permissions(char *rundir
)
4989 ret
= allowed_group();
4991 WARN("No tracing group detected");
4998 /* Set lttng run dir */
4999 ret
= chown(rundir
, 0, gid
);
5001 ERR("Unable to set group on %s", rundir
);
5005 /* Ensure tracing group can search the run dir */
5006 ret
= chmod(rundir
, S_IRWXU
| S_IXGRP
| S_IXOTH
);
5008 ERR("Unable to set permissions on %s", rundir
);
5012 /* lttng client socket path */
5013 ret
= chown(client_unix_sock_path
, 0, gid
);
5015 ERR("Unable to set group on %s", client_unix_sock_path
);
5019 /* kconsumer error socket path */
5020 ret
= chown(kconsumer_data
.err_unix_sock_path
, 0, gid
);
5022 ERR("Unable to set group on %s", kconsumer_data
.err_unix_sock_path
);
5026 /* 64-bit ustconsumer error socket path */
5027 ret
= chown(ustconsumer64_data
.err_unix_sock_path
, 0, gid
);
5029 ERR("Unable to set group on %s", ustconsumer64_data
.err_unix_sock_path
);
5033 /* 32-bit ustconsumer compat32 error socket path */
5034 ret
= chown(ustconsumer32_data
.err_unix_sock_path
, 0, gid
);
5036 ERR("Unable to set group on %s", ustconsumer32_data
.err_unix_sock_path
);
5040 DBG("All permissions are set");
5047 * Create the lttng run directory needed for all global sockets and pipe.
5049 static int create_lttng_rundir(const char *rundir
)
5053 DBG3("Creating LTTng run directory: %s", rundir
);
5055 ret
= mkdir(rundir
, S_IRWXU
);
5057 if (errno
!= EEXIST
) {
5058 ERR("Unable to create %s", rundir
);
5070 * Setup sockets and directory needed by the kconsumerd communication with the
5073 static int set_consumer_sockets(struct consumer_data
*consumer_data
,
5077 char path
[PATH_MAX
];
5079 switch (consumer_data
->type
) {
5080 case LTTNG_CONSUMER_KERNEL
:
5081 snprintf(path
, PATH_MAX
, DEFAULT_KCONSUMERD_PATH
, rundir
);
5083 case LTTNG_CONSUMER64_UST
:
5084 snprintf(path
, PATH_MAX
, DEFAULT_USTCONSUMERD64_PATH
, rundir
);
5086 case LTTNG_CONSUMER32_UST
:
5087 snprintf(path
, PATH_MAX
, DEFAULT_USTCONSUMERD32_PATH
, rundir
);
5090 ERR("Consumer type unknown");
5095 DBG2("Creating consumer directory: %s", path
);
5097 ret
= mkdir(path
, S_IRWXU
);
5099 if (errno
!= EEXIST
) {
5101 ERR("Failed to create %s", path
);
5107 /* Create the kconsumerd error unix socket */
5108 consumer_data
->err_sock
=
5109 lttcomm_create_unix_sock(consumer_data
->err_unix_sock_path
);
5110 if (consumer_data
->err_sock
< 0) {
5111 ERR("Create unix sock failed: %s", consumer_data
->err_unix_sock_path
);
5116 /* File permission MUST be 660 */
5117 ret
= chmod(consumer_data
->err_unix_sock_path
,
5118 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
5120 ERR("Set file permissions failed: %s", consumer_data
->err_unix_sock_path
);
5130 * Signal handler for the daemon
5132 * Simply stop all worker threads, leaving main() return gracefully after
5133 * joining all threads and calling cleanup().
5135 static void sighandler(int sig
)
5139 DBG("SIGPIPE caught");
5142 DBG("SIGINT caught");
5146 DBG("SIGTERM caught");
5155 * Setup signal handler for :
5156 * SIGINT, SIGTERM, SIGPIPE
5158 static int set_signal_handler(void)
5161 struct sigaction sa
;
5164 if ((ret
= sigemptyset(&sigset
)) < 0) {
5165 PERROR("sigemptyset");
5169 sa
.sa_handler
= sighandler
;
5170 sa
.sa_mask
= sigset
;
5172 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
5173 PERROR("sigaction");
5177 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
5178 PERROR("sigaction");
5182 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
5183 PERROR("sigaction");
5187 DBG("Signal handler set for SIGTERM, SIGPIPE and SIGINT");
5193 * Set open files limit to unlimited. This daemon can open a large number of
5194 * file descriptors in order to consumer multiple kernel traces.
5196 static void set_ulimit(void)
5201 /* The kernel does not allowed an infinite limit for open files */
5202 lim
.rlim_cur
= 65535;
5203 lim
.rlim_max
= 65535;
5205 ret
= setrlimit(RLIMIT_NOFILE
, &lim
);
5207 PERROR("failed to set open files limit");
5214 int main(int argc
, char **argv
)
5218 const char *home_path
;
5220 init_kernel_workarounds();
5222 rcu_register_thread();
5224 setup_consumerd_path();
5226 /* Parse arguments */
5228 if ((ret
= parse_args(argc
, argv
) < 0)) {
5238 * child: setsid, close FD 0, 1, 2, chdir /
5239 * parent: exit (if fork is successful)
5247 * We are in the child. Make sure all other file
5248 * descriptors are closed, in case we are called with
5249 * more opened file descriptors than the standard ones.
5251 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
5256 /* Create thread quit pipe */
5257 if ((ret
= init_thread_quit_pipe()) < 0) {
5261 /* Check if daemon is UID = 0 */
5262 is_root
= !getuid();
5265 rundir
= strdup(DEFAULT_LTTNG_RUNDIR
);
5267 /* Create global run dir with root access */
5268 ret
= create_lttng_rundir(rundir
);
5273 if (strlen(apps_unix_sock_path
) == 0) {
5274 snprintf(apps_unix_sock_path
, PATH_MAX
,
5275 DEFAULT_GLOBAL_APPS_UNIX_SOCK
);
5278 if (strlen(client_unix_sock_path
) == 0) {
5279 snprintf(client_unix_sock_path
, PATH_MAX
,
5280 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
);
5283 /* Set global SHM for ust */
5284 if (strlen(wait_shm_path
) == 0) {
5285 snprintf(wait_shm_path
, PATH_MAX
,
5286 DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH
);
5289 /* Setup kernel consumerd path */
5290 snprintf(kconsumer_data
.err_unix_sock_path
, PATH_MAX
,
5291 DEFAULT_KCONSUMERD_ERR_SOCK_PATH
, rundir
);
5292 snprintf(kconsumer_data
.cmd_unix_sock_path
, PATH_MAX
,
5293 DEFAULT_KCONSUMERD_CMD_SOCK_PATH
, rundir
);
5295 DBG2("Kernel consumer err path: %s",
5296 kconsumer_data
.err_unix_sock_path
);
5297 DBG2("Kernel consumer cmd path: %s",
5298 kconsumer_data
.cmd_unix_sock_path
);
5300 home_path
= get_home_dir();
5301 if (home_path
== NULL
) {
5302 /* TODO: Add --socket PATH option */
5303 ERR("Can't get HOME directory for sockets creation.");
5309 * Create rundir from home path. This will create something like
5312 ret
= asprintf(&rundir
, DEFAULT_LTTNG_HOME_RUNDIR
, home_path
);
5318 ret
= create_lttng_rundir(rundir
);
5323 if (strlen(apps_unix_sock_path
) == 0) {
5324 snprintf(apps_unix_sock_path
, PATH_MAX
,
5325 DEFAULT_HOME_APPS_UNIX_SOCK
, home_path
);
5328 /* Set the cli tool unix socket path */
5329 if (strlen(client_unix_sock_path
) == 0) {
5330 snprintf(client_unix_sock_path
, PATH_MAX
,
5331 DEFAULT_HOME_CLIENT_UNIX_SOCK
, home_path
);
5334 /* Set global SHM for ust */
5335 if (strlen(wait_shm_path
) == 0) {
5336 snprintf(wait_shm_path
, PATH_MAX
,
5337 DEFAULT_HOME_APPS_WAIT_SHM_PATH
, geteuid());
5341 /* Set consumer initial state */
5342 kernel_consumerd_state
= CONSUMER_STOPPED
;
5343 ust_consumerd_state
= CONSUMER_STOPPED
;
5345 DBG("Client socket path %s", client_unix_sock_path
);
5346 DBG("Application socket path %s", apps_unix_sock_path
);
5347 DBG("LTTng run directory path: %s", rundir
);
5349 /* 32 bits consumerd path setup */
5350 snprintf(ustconsumer32_data
.err_unix_sock_path
, PATH_MAX
,
5351 DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH
, rundir
);
5352 snprintf(ustconsumer32_data
.cmd_unix_sock_path
, PATH_MAX
,
5353 DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH
, rundir
);
5355 DBG2("UST consumer 32 bits err path: %s",
5356 ustconsumer32_data
.err_unix_sock_path
);
5357 DBG2("UST consumer 32 bits cmd path: %s",
5358 ustconsumer32_data
.cmd_unix_sock_path
);
5360 /* 64 bits consumerd path setup */
5361 snprintf(ustconsumer64_data
.err_unix_sock_path
, PATH_MAX
,
5362 DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH
, rundir
);
5363 snprintf(ustconsumer64_data
.cmd_unix_sock_path
, PATH_MAX
,
5364 DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH
, rundir
);
5366 DBG2("UST consumer 64 bits err path: %s",
5367 ustconsumer64_data
.err_unix_sock_path
);
5368 DBG2("UST consumer 64 bits cmd path: %s",
5369 ustconsumer64_data
.cmd_unix_sock_path
);
5372 * See if daemon already exist.
5374 if ((ret
= check_existing_daemon()) < 0) {
5375 ERR("Already running daemon.\n");
5377 * We do not goto exit because we must not cleanup()
5378 * because a daemon is already running.
5384 * Init UST app hash table. Alloc hash table before this point since
5385 * cleanup() can get called after that point.
5389 /* After this point, we can safely call cleanup() with "goto exit" */
5392 * These actions must be executed as root. We do that *after* setting up
5393 * the sockets path because we MUST make the check for another daemon using
5394 * those paths *before* trying to set the kernel consumer sockets and init
5398 ret
= set_consumer_sockets(&kconsumer_data
, rundir
);
5403 /* Setup kernel tracer */
5404 if (!opt_no_kernel
) {
5405 init_kernel_tracer();
5408 /* Set ulimit for open files */
5411 /* init lttng_fd tracking must be done after set_ulimit. */
5414 ret
= set_consumer_sockets(&ustconsumer64_data
, rundir
);
5419 ret
= set_consumer_sockets(&ustconsumer32_data
, rundir
);
5424 if ((ret
= set_signal_handler()) < 0) {
5428 /* Setup the needed unix socket */
5429 if ((ret
= init_daemon_socket()) < 0) {
5433 /* Set credentials to socket */
5434 if (is_root
&& ((ret
= set_permissions(rundir
)) < 0)) {
5438 /* Get parent pid if -S, --sig-parent is specified. */
5439 if (opt_sig_parent
) {
5443 /* Setup the kernel pipe for waking up the kernel thread */
5444 if ((ret
= utils_create_pipe_cloexec(kernel_poll_pipe
)) < 0) {
5448 /* Setup the thread apps communication pipe. */
5449 if ((ret
= utils_create_pipe_cloexec(apps_cmd_pipe
)) < 0) {
5453 /* Init UST command queue. */
5454 cds_wfq_init(&ust_cmd_queue
.queue
);
5457 * Get session list pointer. This pointer MUST NOT be free(). This list is
5458 * statically declared in session.c
5460 session_list_ptr
= session_get_list();
5462 /* Set up max poll set size */
5463 lttng_poll_set_max_size();
5466 * Set network sequence index to 1 for streams to match a relayd socket on
5467 * the consumer side.
5469 uatomic_set(&relayd_net_seq_idx
, 1);
5471 /* Create thread to manage the client socket */
5472 ret
= pthread_create(&client_thread
, NULL
,
5473 thread_manage_clients
, (void *) NULL
);
5475 PERROR("pthread_create clients");
5479 /* Create thread to dispatch registration */
5480 ret
= pthread_create(&dispatch_thread
, NULL
,
5481 thread_dispatch_ust_registration
, (void *) NULL
);
5483 PERROR("pthread_create dispatch");
5487 /* Create thread to manage application registration. */
5488 ret
= pthread_create(®_apps_thread
, NULL
,
5489 thread_registration_apps
, (void *) NULL
);
5491 PERROR("pthread_create registration");
5495 /* Create thread to manage application socket */
5496 ret
= pthread_create(&apps_thread
, NULL
,
5497 thread_manage_apps
, (void *) NULL
);
5499 PERROR("pthread_create apps");
5503 /* Create kernel thread to manage kernel event */
5504 ret
= pthread_create(&kernel_thread
, NULL
,
5505 thread_manage_kernel
, (void *) NULL
);
5507 PERROR("pthread_create kernel");
5511 ret
= pthread_join(kernel_thread
, &status
);
5513 PERROR("pthread_join");
5514 goto error
; /* join error, exit without cleanup */
5518 ret
= pthread_join(apps_thread
, &status
);
5520 PERROR("pthread_join");
5521 goto error
; /* join error, exit without cleanup */
5525 ret
= pthread_join(reg_apps_thread
, &status
);
5527 PERROR("pthread_join");
5528 goto error
; /* join error, exit without cleanup */
5532 ret
= pthread_join(dispatch_thread
, &status
);
5534 PERROR("pthread_join");
5535 goto error
; /* join error, exit without cleanup */
5539 ret
= pthread_join(client_thread
, &status
);
5541 PERROR("pthread_join");
5542 goto error
; /* join error, exit without cleanup */
5545 ret
= join_consumer_thread(&kconsumer_data
);
5547 PERROR("join_consumer");
5548 goto error
; /* join error, exit without cleanup */
5554 * cleanup() is called when no other thread is running.
5556 rcu_thread_online();
5558 rcu_thread_offline();
5559 rcu_unregister_thread();