2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2013 Raphaƫl Beamonte <raphael.beamonte@gmail.com>
5 * SPDX-License-Identifier: GPL-2.0-only
9 #ifndef _LTT_SESSIOND_H
10 #define _LTT_SESSIOND_H
13 #include <urcu/wfcqueue.h>
15 #include <common/sessiond-comm/sessiond-comm.hpp>
16 #include <common/payload.hpp>
17 #include <common/compat/poll.hpp>
18 #include <common/compat/socket.hpp>
19 #include <common/uuid.hpp>
21 #include "session.hpp"
22 #include "ust-app.hpp"
23 #include "notification-thread.hpp"
24 #include "sessiond-config.hpp"
27 * Consumer daemon state which is changed when spawning it, killing it or in
28 * case of a fatal error.
30 enum consumerd_state {
36 /* Unique identifier of a session daemon instance. */
37 extern lttng_uuid the_sessiond_uuid;
40 * This consumer daemon state is used to validate if a client command will be
41 * able to reach the consumer. If not, the client is informed. For instance,
42 * doing a "lttng start" when the consumer state is set to ERROR will return an
43 * error to the client.
45 * The following example shows a possible race condition of this scheme:
47 * consumer thread error happens
49 * client cmd checks state -> still OK
50 * consumer thread exit, sets error
51 * client cmd try to talk to consumer
54 * However, since the consumer is a different daemon, we have no way of making
55 * sure the command will reach it safely even with this state flag. This is why
56 * we consider that up to the state validation during command processing, the
57 * command is safe. After that, we can not guarantee the correctness of the
58 * client request vis-a-vis the consumer.
60 extern enum consumerd_state the_ust_consumerd_state;
61 extern enum consumerd_state the_kernel_consumerd_state;
63 /* Set in main.c at boot time of the daemon */
64 extern struct lttng_kernel_abi_tracer_version the_kernel_tracer_version;
65 extern struct lttng_kernel_abi_tracer_abi_version the_kernel_tracer_abi_version;
67 /* Notification thread handle. */
68 extern struct notification_thread_handle *the_notification_thread_handle;
71 * This contains extra data needed for processing a command received by the
72 * session daemon from the lttng client.
75 unsigned int lttng_msg_size;
76 struct ltt_session *session;
78 struct lttcomm_session_msg lsm;
79 /* Reply content, starts with an lttcomm_lttng_msg header. */
80 struct lttng_payload reply_payload;
81 lttng_sock_cred creds;
86 struct ust_register_msg reg_msg;
87 struct cds_wfcq_node node;
91 * Queue used to enqueue UST registration request (ust_command) and synchronized
92 * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h
94 struct ust_cmd_queue {
96 struct cds_wfcq_head head;
97 struct cds_wfcq_tail tail;
101 * This is the wait queue containing wait nodes during the application
102 * registration process.
104 struct ust_reg_wait_queue {
106 struct cds_list_head head;
110 * Use by the dispatch registration to queue UST command socket to wait for the
113 struct ust_reg_wait_node {
115 struct cds_list_head head;
118 extern int the_kernel_poll_pipe[2];
121 * Populated when the daemon starts with the current page size of the system.
122 * Set in main() with the current page size.
124 extern long the_page_size;
126 /* Application health monitoring */
127 extern struct health_app *the_health_sessiond;
129 extern struct sessiond_config the_config;
131 extern int the_ust_consumerd64_fd, the_ust_consumerd32_fd;
133 /* Parent PID for --sig-parent option */
134 extern pid_t the_ppid;
135 /* Internal parent PID use with daemonize. */
136 extern pid_t the_child_ppid;
138 /* Consumer daemon specific control data. */
139 extern struct consumer_data the_ustconsumer32_data;
140 extern struct consumer_data the_ustconsumer64_data;
141 extern struct consumer_data the_kconsumer_data;
143 int sessiond_init_main_quit_pipe(void);
144 int sessiond_wait_for_main_quit_pipe(int timeout_ms);
145 int sessiond_notify_main_quit_pipe(void);
146 void sessiond_close_main_quit_pipe(void);
148 int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size);
149 void sessiond_signal_parents(void);
151 void sessiond_set_client_thread_state(bool running);
152 void sessiond_wait_client_thread_stopped(void);
154 void *thread_manage_consumer(void *data);
156 #endif /* _LTT_SESSIOND_H */