1 #ifndef _LTTNG_UST_COMM_H
2 #define _LTTNG_UST_COMM_H
5 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
6 * Julien Desfossez <julien.desfossez@polymtl.ca>
7 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; only version 2
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * This header is meant for liblttng and libust internal use ONLY.
26 * These declarations should NOT be considered stable API.
31 #include <ust/lttng-ust-abi.h>
34 * Default timeout the application waits for the sessiond to send its
35 * "register done" command. Can be overridden with the environment
36 * variable "UST_REGISTER_TIMEOUT". Note that if the sessiond is not
37 * found, the application proceeds directly without any delay.
39 #define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000
41 #define LTTNG_RUNDIR "/var/run/lttng"
43 /* Default unix socket path */
44 #define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-ltt-sessiond"
45 #define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-ltt-sessiond"
46 #define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-ltt-sessiond"
47 #define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-ltt-sessiond"
49 #define DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait"
50 #define DEFAULT_HOME_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait-%u"
52 /* Queue size of listen(2) */
53 #define LTTNG_UST_COMM_MAX_LISTEN 10
55 /* Get the error code index from 0. USTCOMM_ERR starts at 1000.
57 #define USTCOMM_ERR_INDEX(code) (code - USTCOMM_ERR)
62 enum ustcomm_return_code
{
63 USTCOMM_OK
= 0, /* Ok */
64 /* Range 1 to 999 used for standard error numbers (errno.h) */
65 USTCOMM_ERR
= 1000, /* Unknown Error */
66 USTCOMM_UND
, /* Undefine command */
67 USTCOMM_NOT_IMPLEMENTED
, /* Command not implemented */
68 USTCOMM_UNKNOWN_DOMAIN
, /* Tracing domain not known */
69 USTCOMM_ALLOC_FAIL
, /* Trace allocation fail */
70 USTCOMM_NO_SESSION
, /* No session found */
71 USTCOMM_CREATE_FAIL
, /* Create trace fail */
72 USTCOMM_SESSION_FAIL
, /* Create session fail */
73 USTCOMM_START_FAIL
, /* Start tracing fail */
74 USTCOMM_STOP_FAIL
, /* Stop tracing fail */
75 USTCOMM_LIST_FAIL
, /* Listing apps fail */
76 USTCOMM_NO_APPS
, /* No traceable application */
77 USTCOMM_SESS_NOT_FOUND
, /* Session name not found */
78 USTCOMM_NO_TRACE
, /* No trace exist */
79 USTCOMM_FATAL
, /* Session daemon had a fatal error */
80 USTCOMM_NO_TRACEABLE
, /* Error for non traceable app */
81 USTCOMM_SELECT_SESS
, /* Must select a session */
82 USTCOMM_EXIST_SESS
, /* Session name already exist */
83 USTCOMM_NO_EVENT
, /* No event found */
84 USTCOMM_KERN_NA
, /* Kernel tracer unavalable */
85 USTCOMM_KERN_EVENT_EXIST
, /* Kernel event already exists */
86 USTCOMM_KERN_SESS_FAIL
, /* Kernel create session failed */
87 USTCOMM_KERN_CHAN_FAIL
, /* Kernel create channel failed */
88 USTCOMM_KERN_CHAN_NOT_FOUND
, /* Kernel channel not found */
89 USTCOMM_KERN_CHAN_DISABLE_FAIL
, /* Kernel disable channel failed */
90 USTCOMM_KERN_CHAN_ENABLE_FAIL
, /* Kernel enable channel failed */
91 USTCOMM_KERN_CONTEXT_FAIL
, /* Kernel add context failed */
92 USTCOMM_KERN_ENABLE_FAIL
, /* Kernel enable event failed */
93 USTCOMM_KERN_DISABLE_FAIL
, /* Kernel disable event failed */
94 USTCOMM_KERN_META_FAIL
, /* Kernel open metadata failed */
95 USTCOMM_KERN_START_FAIL
, /* Kernel start trace failed */
96 USTCOMM_KERN_STOP_FAIL
, /* Kernel stop trace failed */
97 USTCOMM_KERN_CONSUMER_FAIL
, /* Kernel consumer start failed */
98 USTCOMM_KERN_STREAM_FAIL
, /* Kernel create stream failed */
99 USTCOMM_KERN_DIR_FAIL
, /* Kernel trace directory creation failed */
100 USTCOMM_KERN_DIR_EXIST
, /* Kernel trace directory exist */
101 USTCOMM_KERN_NO_SESSION
, /* No kernel session found */
102 USTCOMM_KERN_LIST_FAIL
, /* Kernel listing events failed */
103 USTCONSUMER_COMMAND_SOCK_READY
, /* when kconsumerd command socket ready */
104 USTCONSUMER_SUCCESS_RECV_FD
, /* success on receiving fds */
105 USTCONSUMER_ERROR_RECV_FD
, /* error on receiving fds */
106 USTCONSUMER_POLL_ERROR
, /* Error in polling thread in kconsumerd */
107 USTCONSUMER_POLL_NVAL
, /* Poll on closed fd */
108 USTCONSUMER_POLL_HUP
, /* All fds have hungup */
109 USTCONSUMER_EXIT_SUCCESS
, /* kconsumerd exiting normally */
110 USTCONSUMER_EXIT_FAILURE
, /* kconsumerd exiting on error */
111 USTCONSUMER_OUTFD_ERROR
, /* error opening the tracefile */
112 USTCONSUMER_SPLICE_EBADF
, /* EBADF from splice(2) */
113 USTCONSUMER_SPLICE_EINVAL
, /* EINVAL from splice(2) */
114 USTCONSUMER_SPLICE_ENOMEM
, /* ENOMEM from splice(2) */
115 USTCONSUMER_SPLICE_ESPIPE
, /* ESPIPE from splice(2) */
116 /* MUST be last element */
117 USTCOMM_NR
, /* Last element */
121 * Data structure for the commands sent from sessiond to UST.
123 struct ustcomm_ust_msg
{
127 struct lttng_ust_channel channel
;
128 struct lttng_ust_stream stream
;
129 struct lttng_ust_event event
;
130 struct lttng_ust_context context
;
131 struct lttng_ust_tracer_version version
;
136 * Data structure for the response from UST to the session daemon.
137 * cmd_type is sent back in the reply for validation.
139 struct ustcomm_ust_reply
{
142 uint32_t ret_code
; /* enum enum ustcomm_return_code */
143 uint32_t ret_val
; /* return value */
146 uint64_t memory_map_size
;
149 uint64_t memory_map_size
;
151 struct lttng_ust_tracer_version version
;
155 extern int ustcomm_create_unix_sock(const char *pathname
);
156 extern int ustcomm_connect_unix_sock(const char *pathname
);
157 extern int ustcomm_accept_unix_sock(int sock
);
158 extern int ustcomm_listen_unix_sock(int sock
);
159 extern int ustcomm_close_unix_sock(int sock
);
160 /* Send fd(s) over a unix socket. */
161 extern ssize_t
ustcomm_send_fds_unix_sock(int sock
, void *buf
, int *fds
,
162 size_t nb_fd
, size_t len
);
163 extern ssize_t
ustcomm_recv_unix_sock(int sock
, void *buf
, size_t len
);
164 extern ssize_t
ustcomm_send_unix_sock(int sock
, void *buf
, size_t len
);
165 extern const char *ustcomm_get_readable_code(int code
);
166 extern int ustcomm_send_app_msg(int sock
, struct ustcomm_ust_msg
*lum
);
167 extern int ustcomm_recv_app_reply(int sock
, struct ustcomm_ust_reply
*lur
,
168 uint32_t expected_handle
, uint32_t expected_cmd
);
169 extern int ustcomm_send_app_cmd(int sock
,
170 struct ustcomm_ust_msg
*lum
,
171 struct ustcomm_ust_reply
*lur
);
172 int ustcomm_recv_fd(int sock
);
174 #endif /* _LTTNG_UST_COMM_H */