2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Julien Desfossez <julien.desfossez@polymtl.ca>
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.
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.
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.
21 #ifndef _LIBLTTSESSIONDCOMM_H
22 #define _LIBLTTSESSIONDCOMM_H
25 #include <uuid/uuid.h>
27 #define LTTNG_RUNDIR "/var/run/lttng"
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"
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"
40 /* Queue size of listen(2) */
43 /* Get the error code index from 0 since
44 * LTTCOMM_OK start at 1000
46 #define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK)
48 enum lttcomm_command_type
{
50 LTTNG_DESTROY_SESSION
,
51 LTTNG_FORCE_SUBBUF_SWITCH
,
52 LTTNG_GET_ALL_SESSION
,
54 LTTNG_GET_SUBBUF_NUM_SIZE
,
58 LTTNG_LIST_TRACE_EVENTS
,
62 LTTNG_SET_SUBBUF_SIZE
,
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 */
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 */
104 /* state of each fd in consumerd */
105 enum lttcomm_kconsumerd_fd_state
{
112 * Data structure for ltt-session received message
114 struct lttcomm_session_msg
{
115 /* Common data to almost all command */
116 enum lttcomm_command_type cmd_type
;
118 char trace_name
[NAME_MAX
];
119 char session_name
[NAME_MAX
];
127 char channel
[NAME_MAX
];
128 char marker
[NAME_MAX
];
132 char sock_path
[PATH_MAX
];
136 unsigned int subbuf_num
;
137 char channel
[NAME_MAX
];
139 /* SET_SUBBUF_SIZE */
141 unsigned int subbuf_size
;
142 char channel
[NAME_MAX
];
148 * Data structure for the lttng client response.
150 * This data structure is the control struct use in
151 * the header of the transmission. NEVER put variable
154 struct lttcomm_lttng_msg
{
155 enum lttcomm_command_type cmd_type
;
156 enum lttcomm_return_code ret_code
;
159 char trace_name
[NAME_MAX
];
160 unsigned int size_payload
;
164 * Data structures for the kconsumerd communications
166 * The header structure is sent to the kconsumerd daemon to inform
167 * how many lttcomm_kconsumerd_msg it is about to receive
169 struct lttcomm_kconsumerd_header
{
170 unsigned int payload_size
;
171 enum lttcomm_consumerd_command cmd_type
;
172 enum lttcomm_return_code ret_code
;
175 /* lttcomm_kconsumerd_msg represents a file descriptor to consume the
176 * data and a path name to write it
178 struct lttcomm_kconsumerd_msg
{
179 char path_name
[PATH_MAX
];
181 enum lttcomm_kconsumerd_fd_state state
;
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
);
193 #endif /* _LIBLTTSESSIONDCOMM_H */