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 | |
7 | * as published by the Free Software Foundation; either version 2 | |
8 | * of the License, or (at your option) any later version. | |
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> | |
25 | #include <uuid/uuid.h> | |
26 | ||
5e16da05 MD |
27 | /* |
28 | * FIXME: 32, 64bit enums -> uint32_t uint64_t for data exchange. | |
29 | * Same for pid_t. | |
30 | */ | |
31 | ||
d6f42150 DG |
32 | #define LTTNG_RUNDIR "/var/run/lttng" |
33 | ||
fac6795d | 34 | /* Default unix socket path */ |
d6f42150 DG |
35 | #define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-ltt-sessiond" |
36 | #define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-ltt-sessiond" | |
fac6795d DG |
37 | #define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-ltt-sessiond" |
38 | #define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-ltt-sessiond" | |
39 | ||
d6f42150 DG |
40 | /* Kernel consumer path */ |
41 | #define KCONSUMERD_PATH LTTNG_RUNDIR "/kconsumerd" | |
42 | #define KCONSUMERD_CMD_SOCK_PATH KCONSUMERD_PATH "/command" | |
43 | #define KCONSUMERD_ERR_SOCK_PATH KCONSUMERD_PATH "/error" | |
44 | ||
fac6795d DG |
45 | /* Queue size of listen(2) */ |
46 | #define MAX_LISTEN 10 | |
47 | ||
fac6795d DG |
48 | /* Get the error code index from 0 since |
49 | * LTTCOMM_OK start at 1000 | |
50 | */ | |
686204ab | 51 | #define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK) |
fac6795d | 52 | |
6abb15de | 53 | enum lttcomm_sessiond_command { |
fac6795d DG |
54 | LTTNG_CREATE_SESSION, |
55 | LTTNG_DESTROY_SESSION, | |
56 | LTTNG_FORCE_SUBBUF_SWITCH, | |
57 | LTTNG_GET_ALL_SESSION, | |
58 | LTTNG_GET_SOCK_PATH, | |
59 | LTTNG_GET_SUBBUF_NUM_SIZE, | |
60 | LTTNG_LIST_MARKERS, | |
61 | LTTNG_LIST_SESSIONS, | |
1657e9bb | 62 | LTTNG_LIST_TRACES, |
fac6795d DG |
63 | LTTNG_LIST_TRACE_EVENTS, |
64 | LTTNG_SETUP_TRACE, | |
65 | LTTNG_SET_SOCK_PATH, | |
66 | LTTNG_SET_SUBBUF_NUM, | |
67 | LTTNG_SET_SUBBUF_SIZE, | |
68 | UST_ALLOC_TRACE, | |
69 | UST_CREATE_TRACE, | |
70 | UST_DESTROY_TRACE, | |
71 | UST_DISABLE_MARKER, | |
72 | UST_ENABLE_MARKER, | |
73 | UST_LIST_APPS, | |
74 | UST_START_TRACE, | |
75 | UST_STOP_TRACE, | |
76 | }; | |
77 | ||
78 | /* | |
79 | * lttcomm error code. | |
80 | */ | |
81 | enum lttcomm_return_code { | |
82 | LTTCOMM_OK = 1000, /* Ok */ | |
83 | LTTCOMM_ERR, /* Unknown Error */ | |
84 | LTTCOMM_UND, /* Undefine command */ | |
85 | LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */ | |
86 | LTTCOMM_NO_SESSION, /* No session found */ | |
87 | LTTCOMM_CREATE_FAIL, /* Create trace fail */ | |
88 | LTTCOMM_SESSION_FAIL, /* Create session fail */ | |
89 | LTTCOMM_START_FAIL, /* Start tracing fail */ | |
520ff687 | 90 | LTTCOMM_STOP_FAIL, /* Stop tracing fail */ |
fac6795d | 91 | LTTCOMM_LIST_FAIL, /* Listing apps fail */ |
e065084a | 92 | LTTCOMM_NO_APPS, /* No traceable application */ |
57167058 | 93 | LTTCOMM_NO_SESS, /* No sessions available */ |
ce3d728c | 94 | LTTCOMM_NO_TRACE, /* No trace exist */ |
ca95a216 | 95 | LTTCOMM_FATAL, /* Session daemon had a fatal error */ |
379473d2 DG |
96 | LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */ |
97 | LTTCOMM_SELECT_SESS, /* Must select a session */ | |
27673bb6 | 98 | LTTCOMM_EXIST_SESS, /* Session name already exist */ |
fac6795d DG |
99 | LTTCOMM_NR, /* Last element */ |
100 | }; | |
101 | ||
6e3805e2 DG |
102 | /* commands for kconsumerd */ |
103 | enum lttcomm_consumerd_command { | |
104 | LTTCOMM_ADD_STREAM = 1100, | |
105 | LTTCOMM_UPDATE_STREAM, /* pause, delete, start depending on fd state */ | |
106 | LTTCOMM_STOP, /* delete all */ | |
107 | }; | |
108 | ||
109 | /* state of each fd in consumerd */ | |
110 | enum lttcomm_kconsumerd_fd_state { | |
111 | ACTIVE_FD, | |
112 | PAUSE_FD, | |
113 | DELETE_FD, | |
114 | }; | |
115 | ||
fac6795d DG |
116 | /* |
117 | * Data structure for ltt-session received message | |
118 | */ | |
119 | struct lttcomm_session_msg { | |
120 | /* Common data to almost all command */ | |
6abb15de | 121 | enum lttcomm_sessiond_command cmd_type; |
8028d920 | 122 | uuid_t session_id; |
fac6795d DG |
123 | char trace_name[NAME_MAX]; |
124 | char session_name[NAME_MAX]; | |
125 | pid_t pid; | |
126 | union { | |
127 | struct { | |
128 | int auto_session; | |
129 | } create_session; | |
130 | /* Marker data */ | |
131 | struct { | |
132 | char channel[NAME_MAX]; | |
133 | char marker[NAME_MAX]; | |
134 | } marker; | |
135 | /* SET_SOCK_PATH */ | |
136 | struct { | |
137 | char sock_path[PATH_MAX]; | |
138 | } sock_path; | |
139 | /* SET_SUBBUF_NUM */ | |
140 | struct { | |
141 | unsigned int subbuf_num; | |
142 | char channel[NAME_MAX]; | |
143 | } subbuf_num; | |
144 | /* SET_SUBBUF_SIZE */ | |
145 | struct { | |
146 | unsigned int subbuf_size; | |
147 | char channel[NAME_MAX]; | |
148 | } subbuf_size; | |
149 | } u; | |
150 | }; | |
151 | ||
152 | /* | |
5e16da05 | 153 | * Data structure for the response from sessiond to the lttng client. |
ca95a216 DG |
154 | * |
155 | * This data structure is the control struct use in | |
156 | * the header of the transmission. NEVER put variable | |
157 | * size data in here. | |
fac6795d | 158 | */ |
6abb15de DG |
159 | struct lttcomm_lttng_header { |
160 | enum lttcomm_sessiond_command cmd_type; | |
fac6795d | 161 | enum lttcomm_return_code ret_code; |
8028d920 | 162 | uuid_t session_id; |
fac6795d DG |
163 | pid_t pid; |
164 | char trace_name[NAME_MAX]; | |
6abb15de | 165 | unsigned int payload_size; |
fac6795d DG |
166 | }; |
167 | ||
6e3805e2 DG |
168 | /* |
169 | * Data structures for the kconsumerd communications | |
170 | * | |
171 | * The header structure is sent to the kconsumerd daemon to inform | |
172 | * how many lttcomm_kconsumerd_msg it is about to receive | |
173 | */ | |
174 | struct lttcomm_kconsumerd_header { | |
175 | unsigned int payload_size; | |
176 | enum lttcomm_consumerd_command cmd_type; | |
177 | enum lttcomm_return_code ret_code; | |
178 | }; | |
179 | ||
180 | /* lttcomm_kconsumerd_msg represents a file descriptor to consume the | |
181 | * data and a path name to write it | |
182 | */ | |
183 | struct lttcomm_kconsumerd_msg { | |
184 | char path_name[PATH_MAX]; | |
185 | int fd; | |
186 | enum lttcomm_kconsumerd_fd_state state; | |
187 | }; | |
188 | ||
fac6795d DG |
189 | extern int lttcomm_create_unix_sock(const char *pathname); |
190 | extern int lttcomm_connect_unix_sock(const char *pathname); | |
191 | extern int lttcomm_accept_unix_sock(int sock); | |
192 | extern int lttcomm_listen_unix_sock(int sock); | |
87378cf5 | 193 | extern int lttcomm_close_unix_sock(int sock); |
fac6795d DG |
194 | extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len); |
195 | extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len); | |
196 | extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code); | |
197 | ||
198 | #endif /* _LIBLTTSESSIONDCOMM_H */ |