8f7ce0317f68c28b99f654a5a43a53a623c5e028
[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
26 #include <lttng/lttng.h>
27 #include "lttng-share.h"
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 /* Queue size of listen(2) */
36 #define MAX_LISTEN 10
37
38 /* Get the error code index from 0 since
39 * LTTCOMM_OK start at 1000
40 */
41 #define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK)
42
43 enum lttcomm_sessiond_command {
44 /* Tracer context command */
45 LTTNG_KERNEL_CREATE_CHANNEL,
46 LTTNG_KERNEL_DISABLE_CHANNEL,
47 LTTNG_KERNEL_DISABLE_EVENT,
48 LTTNG_KERNEL_DISABLE_ALL_EVENT,
49 LTTNG_KERNEL_ENABLE_CHANNEL,
50 LTTNG_KERNEL_ENABLE_EVENT,
51 LTTNG_KERNEL_ENABLE_ALL_EVENT,
52 LTTNG_KERNEL_LIST_EVENTS,
53 /* Session daemon context command */
54 LTTNG_CREATE_SESSION,
55 LTTNG_DESTROY_SESSION,
56 LTTNG_LIST_SESSIONS,
57 LTTNG_LIST_TRACES,
58 LTTNG_LIST_EVENTS,
59 LTTNG_LIST_TRACEABLE_APPS,
60 LTTNG_START_TRACE,
61 LTTNG_STOP_TRACE,
62 };
63
64 /*
65 * lttcomm error code.
66 */
67 enum lttcomm_return_code {
68 LTTCOMM_OK = 1000, /* Ok */
69 LTTCOMM_ERR, /* Unknown Error */
70 LTTCOMM_UND, /* Undefine command */
71 LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */
72 LTTCOMM_NO_SESSION, /* No session found */
73 LTTCOMM_CREATE_FAIL, /* Create trace fail */
74 LTTCOMM_SESSION_FAIL, /* Create session fail */
75 LTTCOMM_START_FAIL, /* Start tracing fail */
76 LTTCOMM_STOP_FAIL, /* Stop tracing fail */
77 LTTCOMM_LIST_FAIL, /* Listing apps fail */
78 LTTCOMM_NO_APPS, /* No traceable application */
79 LTTCOMM_SESS_NOT_FOUND, /* Session name not found */
80 LTTCOMM_NO_TRACE, /* No trace exist */
81 LTTCOMM_FATAL, /* Session daemon had a fatal error */
82 LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */
83 LTTCOMM_SELECT_SESS, /* Must select a session */
84 LTTCOMM_EXIST_SESS, /* Session name already exist */
85 LTTCOMM_NO_EVENT, /* No event found */
86 LTTCOMM_KERN_NA, /* Kernel tracer unavalable */
87 LTTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */
88 LTTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */
89 LTTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */
90 LTTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */
91 LTTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */
92 LTTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */
93 LTTCOMM_KERN_START_FAIL, /* Kernel start trace failed */
94 LTTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */
95 LTTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */
96 LTTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */
97 LTTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */
98 LTTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */
99 LTTCOMM_KERN_NO_SESSION, /* No kernel session found */
100 LTTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */
101 KCONSUMERD_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */
102 KCONSUMERD_SUCCESS_RECV_FD, /* success on receiving fds */
103 KCONSUMERD_ERROR_RECV_FD, /* error on receiving fds */
104 KCONSUMERD_POLL_ERROR, /* Error in polling thread in kconsumerd */
105 KCONSUMERD_POLL_NVAL, /* Poll on closed fd */
106 KCONSUMERD_POLL_HUP, /* All fds have hungup */
107 KCONSUMERD_EXIT_SUCCESS, /* kconsumerd exiting normally */
108 KCONSUMERD_EXIT_FAILURE, /* kconsumerd exiting on error */
109 KCONSUMERD_OUTFD_ERROR, /* error opening the tracefile */
110 KCONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */
111 KCONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */
112 KCONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */
113 KCONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */
114 /* MUST be last element */
115 LTTCOMM_NR, /* Last element */
116 };
117
118 /*
119 * Data structure received from lttng client to session daemon.
120 */
121 struct lttcomm_session_msg {
122 u32 cmd_type; /* enum lttcomm_sessiond_command */
123 char session_name[NAME_MAX];
124 char path[PATH_MAX];
125 pid_t pid;
126 union {
127 struct {
128 char channel_name[NAME_MAX];
129 char name[NAME_MAX];
130 } disable;
131 /* Event data */
132 struct {
133 char channel_name[NAME_MAX];
134 struct lttng_event event;
135 } enable;
136 /* Create channel */
137 struct {
138 struct lttng_channel chan;
139 } channel;
140 } u;
141 };
142
143 /*
144 * Data structure for the response from sessiond to the lttng client.
145 */
146 struct lttcomm_lttng_msg {
147 u32 cmd_type; /* enum lttcomm_sessiond_command */
148 u32 ret_code; /* enum lttcomm_return_code */
149 u32 pid; /* pid_t */
150 u32 data_size;
151 /* Contains: trace_name + data */
152 char payload[];
153 };
154
155 /*
156 * Data structures for the kconsumerd communications
157 *
158 * The header structure is sent to the kconsumerd daemon to inform
159 * how many lttcomm_kconsumerd_msg it is about to receive
160 */
161 struct lttcomm_kconsumerd_header {
162 u32 payload_size;
163 u32 cmd_type; /* enum kconsumerd_command */
164 };
165
166 /* lttcomm_kconsumerd_msg represents a file descriptor to consume the
167 * data and a path name to write it
168 */
169 struct lttcomm_kconsumerd_msg {
170 char path_name[PATH_MAX];
171 int fd;
172 u32 state; /* enum lttcomm_kconsumerd_fd_state */
173 unsigned long max_sb_size; /* the subbuffer size for this channel */
174 };
175
176 extern int lttcomm_create_unix_sock(const char *pathname);
177 extern int lttcomm_connect_unix_sock(const char *pathname);
178 extern int lttcomm_accept_unix_sock(int sock);
179 extern int lttcomm_listen_unix_sock(int sock);
180 extern int lttcomm_close_unix_sock(int sock);
181 extern ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len);
182 extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len);
183 extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len);
184 extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
185
186 #endif /* _LIBLTTSESSIONDCOMM_H */
This page took 0.035918 seconds and 3 git commands to generate.