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