Commit | Line | Data |
---|---|---|
6e3805e2 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * Julien Desfossez <julien.desfossez@polymtl.ca> | |
fac6795d DG |
4 | * |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU General Public License | |
82a3637f DG |
7 | * as published by the Free Software Foundation; only version 2 |
8 | * of the License. | |
fac6795d DG |
9 | * |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | * | |
19 | */ | |
20 | ||
21 | #ifndef _LIBLTTSESSIONDCOMM_H | |
22 | #define _LIBLTTSESSIONDCOMM_H | |
23 | ||
24 | #include <limits.h> | |
fac6795d | 25 | |
f3ed775e | 26 | #include <lttng/lttng.h> |
9bda164d | 27 | #include "lttng-share.h" |
5e16da05 | 28 | |
fac6795d | 29 | /* Default unix socket path */ |
d6f42150 DG |
30 | #define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-ltt-sessiond" |
31 | #define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-ltt-sessiond" | |
fac6795d DG |
32 | #define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-ltt-sessiond" |
33 | #define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-ltt-sessiond" | |
34 | ||
35 | /* Queue size of listen(2) */ | |
36 | #define MAX_LISTEN 10 | |
37 | ||
fac6795d DG |
38 | /* Get the error code index from 0 since |
39 | * LTTCOMM_OK start at 1000 | |
40 | */ | |
686204ab | 41 | #define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK) |
fac6795d | 42 | |
6abb15de | 43 | enum lttcomm_sessiond_command { |
0d0c377a | 44 | /* Tracer command */ |
b579acd9 | 45 | LTTNG_ADD_CONTEXT, |
0b97ec54 | 46 | LTTNG_DISABLE_CHANNEL, |
f5177a38 DG |
47 | LTTNG_DISABLE_EVENT, |
48 | LTTNG_DISABLE_ALL_EVENT, | |
0d0c377a DG |
49 | LTTNG_ENABLE_CHANNEL, |
50 | LTTNG_ENABLE_EVENT, | |
51 | LTTNG_ENABLE_ALL_EVENT, | |
52 | /* Session daemon command */ | |
fac6795d DG |
53 | LTTNG_CREATE_SESSION, |
54 | LTTNG_DESTROY_SESSION, | |
9f19cc17 DG |
55 | LTTNG_LIST_CHANNELS, |
56 | LTTNG_LIST_DOMAINS, | |
f3ed775e | 57 | LTTNG_LIST_EVENTS, |
9f19cc17 | 58 | LTTNG_LIST_SESSIONS, |
052da939 | 59 | LTTNG_LIST_TRACEPOINTS, |
f3ed775e DG |
60 | LTTNG_START_TRACE, |
61 | LTTNG_STOP_TRACE, | |
fac6795d DG |
62 | }; |
63 | ||
64 | /* | |
65 | * lttcomm error code. | |
66 | */ | |
67 | enum lttcomm_return_code { | |
20fe2104 DG |
68 | LTTCOMM_OK = 1000, /* Ok */ |
69 | LTTCOMM_ERR, /* Unknown Error */ | |
70 | LTTCOMM_UND, /* Undefine command */ | |
7d29a247 DG |
71 | LTTCOMM_NOT_IMPLEMENTED, /* Command not implemented */ |
72 | LTTCOMM_UNKNOWN_DOMAIN, /* Tracing domain not known */ | |
20fe2104 DG |
73 | LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */ |
74 | LTTCOMM_NO_SESSION, /* No session found */ | |
75 | LTTCOMM_CREATE_FAIL, /* Create trace fail */ | |
76 | LTTCOMM_SESSION_FAIL, /* Create session fail */ | |
77 | LTTCOMM_START_FAIL, /* Start tracing fail */ | |
78 | LTTCOMM_STOP_FAIL, /* Stop tracing fail */ | |
79 | LTTCOMM_LIST_FAIL, /* Listing apps fail */ | |
80 | LTTCOMM_NO_APPS, /* No traceable application */ | |
f3ed775e | 81 | LTTCOMM_SESS_NOT_FOUND, /* Session name not found */ |
20fe2104 DG |
82 | LTTCOMM_NO_TRACE, /* No trace exist */ |
83 | LTTCOMM_FATAL, /* Session daemon had a fatal error */ | |
84 | LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */ | |
85 | LTTCOMM_SELECT_SESS, /* Must select a session */ | |
86 | LTTCOMM_EXIST_SESS, /* Session name already exist */ | |
87 | LTTCOMM_NO_EVENT, /* No event found */ | |
88 | LTTCOMM_KERN_NA, /* Kernel tracer unavalable */ | |
7d29a247 | 89 | LTTCOMM_KERN_EVENT_EXIST, /* Kernel event already exists */ |
20fe2104 DG |
90 | LTTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ |
91 | LTTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ | |
f3ed775e | 92 | LTTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */ |
26cc6b4e | 93 | LTTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */ |
d36b8583 | 94 | LTTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */ |
d65106b1 | 95 | LTTCOMM_KERN_CONTEXT_FAIL, /* Kernel add context failed */ |
f34daff7 DG |
96 | LTTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ |
97 | LTTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ | |
aaf26714 | 98 | LTTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */ |
8c0faa1d DG |
99 | LTTCOMM_KERN_START_FAIL, /* Kernel start trace failed */ |
100 | LTTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */ | |
101 | LTTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */ | |
102 | LTTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */ | |
103 | LTTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */ | |
84291629 DG |
104 | LTTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ |
105 | LTTCOMM_KERN_NO_SESSION, /* No kernel session found */ | |
2ef84c95 | 106 | LTTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */ |
d4a1283e | 107 | KCONSUMERD_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ |
20fe2104 DG |
108 | KCONSUMERD_SUCCESS_RECV_FD, /* success on receiving fds */ |
109 | KCONSUMERD_ERROR_RECV_FD, /* error on receiving fds */ | |
110 | KCONSUMERD_POLL_ERROR, /* Error in polling thread in kconsumerd */ | |
111 | KCONSUMERD_POLL_NVAL, /* Poll on closed fd */ | |
112 | KCONSUMERD_POLL_HUP, /* All fds have hungup */ | |
113 | KCONSUMERD_EXIT_SUCCESS, /* kconsumerd exiting normally */ | |
114 | KCONSUMERD_EXIT_FAILURE, /* kconsumerd exiting on error */ | |
115 | KCONSUMERD_OUTFD_ERROR, /* error opening the tracefile */ | |
0632499a JD |
116 | KCONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */ |
117 | KCONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */ | |
118 | KCONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */ | |
119 | KCONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */ | |
20fe2104 DG |
120 | /* MUST be last element */ |
121 | LTTCOMM_NR, /* Last element */ | |
fac6795d DG |
122 | }; |
123 | ||
124 | /* | |
9bda164d | 125 | * Data structure received from lttng client to session daemon. |
fac6795d DG |
126 | */ |
127 | struct lttcomm_session_msg { | |
9bda164d | 128 | u32 cmd_type; /* enum lttcomm_sessiond_command */ |
42abccdb | 129 | struct lttng_session session; |
9f19cc17 | 130 | struct lttng_domain domain; |
fac6795d DG |
131 | union { |
132 | struct { | |
f3ed775e DG |
133 | char channel_name[NAME_MAX]; |
134 | char name[NAME_MAX]; | |
135 | } disable; | |
136 | /* Event data */ | |
fac6795d | 137 | struct { |
f3ed775e DG |
138 | char channel_name[NAME_MAX]; |
139 | struct lttng_event event; | |
140 | } enable; | |
141 | /* Create channel */ | |
142 | struct { | |
143 | struct lttng_channel chan; | |
144 | } channel; | |
d65106b1 DG |
145 | /* Context */ |
146 | struct { | |
147 | char channel_name[NAME_MAX]; | |
148 | char event_name[NAME_MAX]; | |
7d29a247 | 149 | struct lttng_event_context ctx; |
d65106b1 | 150 | } context; |
9f19cc17 DG |
151 | /* List */ |
152 | struct { | |
153 | char channel_name[NAME_MAX]; | |
154 | } list; | |
fac6795d DG |
155 | } u; |
156 | }; | |
157 | ||
158 | /* | |
5e16da05 | 159 | * Data structure for the response from sessiond to the lttng client. |
fac6795d | 160 | */ |
5461b305 | 161 | struct lttcomm_lttng_msg { |
9bda164d DG |
162 | u32 cmd_type; /* enum lttcomm_sessiond_command */ |
163 | u32 ret_code; /* enum lttcomm_return_code */ | |
164 | u32 pid; /* pid_t */ | |
5461b305 | 165 | u32 data_size; |
5461b305 DG |
166 | /* Contains: trace_name + data */ |
167 | char payload[]; | |
fac6795d DG |
168 | }; |
169 | ||
6e3805e2 DG |
170 | /* |
171 | * Data structures for the kconsumerd communications | |
172 | * | |
173 | * The header structure is sent to the kconsumerd daemon to inform | |
174 | * how many lttcomm_kconsumerd_msg it is about to receive | |
175 | */ | |
176 | struct lttcomm_kconsumerd_header { | |
9bda164d | 177 | u32 payload_size; |
9d26659a | 178 | u32 cmd_type; /* enum kconsumerd_command */ |
6e3805e2 DG |
179 | }; |
180 | ||
181 | /* lttcomm_kconsumerd_msg represents a file descriptor to consume the | |
182 | * data and a path name to write it | |
183 | */ | |
184 | struct lttcomm_kconsumerd_msg { | |
185 | char path_name[PATH_MAX]; | |
186 | int fd; | |
9bda164d | 187 | u32 state; /* enum lttcomm_kconsumerd_fd_state */ |
d4a1283e | 188 | unsigned long max_sb_size; /* the subbuffer size for this channel */ |
6e3805e2 DG |
189 | }; |
190 | ||
fac6795d DG |
191 | extern int lttcomm_create_unix_sock(const char *pathname); |
192 | extern int lttcomm_connect_unix_sock(const char *pathname); | |
193 | extern int lttcomm_accept_unix_sock(int sock); | |
194 | extern int lttcomm_listen_unix_sock(int sock); | |
87378cf5 | 195 | extern int lttcomm_close_unix_sock(int sock); |
8c0faa1d | 196 | extern ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len); |
fac6795d DG |
197 | extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len); |
198 | extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len); | |
199 | extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code); | |
200 | ||
201 | #endif /* _LIBLTTSESSIONDCOMM_H */ |