1 /* Copyright (C) 2009 Pierre-Marc Fournier
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <sys/types.h>
23 #include <urcu/list.h>
25 #include <ust/kcompat/kcompat.h>
27 #define SOCK_DIR "/tmp/ust-app-socks"
30 struct list_head list
;
35 struct ustcomm_header
{
42 #define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header))
44 /* Specify a sata size that leaves margin at the end of a buffer
45 * in order to make sure that we never have more data than
46 * will fit in the buffer AND that the last chars (due to a
47 * pre-receive memset) will always be 0, terminating any string
49 #define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *))
51 enum tracectl_commands
{
60 GET_BUF_SHMID_PIPE_FD
,
81 struct ustcomm_trace_info
{
83 char data
[USTCOMM_DATA_SIZE
];
86 struct ustcomm_channel_info
{
88 unsigned int subbuf_size
;
89 unsigned int subbuf_num
;
90 char data
[USTCOMM_DATA_SIZE
];
93 struct ustcomm_buffer_info
{
100 char data
[USTCOMM_DATA_SIZE
];
103 struct ustcomm_marker_info
{
106 char data
[USTCOMM_DATA_SIZE
];
109 struct ustcomm_sock_path
{
111 char data
[USTCOMM_DATA_SIZE
];
114 struct ustcomm_pidunique
{
118 struct ustcomm_notify_buf_mapped
{
119 char data
[USTCOMM_DATA_SIZE
];
122 /* Ensure directory existence, usefull for unix sockets */
123 extern int ensure_dir_exists(const char *dir
);
125 /* Create and delete sockets */
126 extern struct ustcomm_sock
* ustcomm_init_sock(int fd
, int epoll_fd
,
127 struct list_head
*list
);
128 extern void ustcomm_del_sock(struct ustcomm_sock
*sock
, int keep_in_epoll
);
130 /* Create and delete named sockets */
131 extern struct ustcomm_sock
* ustcomm_init_named_socket(const char *name
,
133 extern void ustcomm_del_named_sock(struct ustcomm_sock
*sock
,
134 int keep_socket_file
);
136 /* Send and receive functions for file descriptors */
137 extern int ustcomm_send_fd(int sock
, const struct ustcomm_header
*header
,
138 const char *data
, int *fd
);
139 extern int ustcomm_recv_fd(int sock
, struct ustcomm_header
*header
,
140 char *data
, int *fd
);
142 /* Normal send and receive functions */
143 extern int ustcomm_send(int sock
, const struct ustcomm_header
*header
,
145 extern int ustcomm_recv(int sock
, struct ustcomm_header
*header
,
148 /* Receive and allocate data, not to be used inside libust */
149 extern int ustcomm_recv_alloc(int sock
,
150 struct ustcomm_header
*header
,
153 /* Request function, send and receive */
154 extern int ustcomm_req(int sock
,
155 const struct ustcomm_header
*req_header
,
156 const char *req_data
,
157 struct ustcomm_header
*res_header
,
160 extern int ustcomm_request_consumer(pid_t pid
, const char *channel
);
161 extern int ustcomm_connect_app(pid_t pid
, int *app_fd
);
162 extern int ustcomm_connect_path(const char *path
, int *connection_fd
);
164 extern int nth_token_is(const char *str
, const char *token
, int tok_no
);
166 extern char *nth_token(const char *str
, int tok_no
);
168 /* String serialising functions, printf straight into a buffer */
169 #define USTCOMM_POISON_PTR (void *)0x19831018
171 extern char * ustcomm_print_data(char *data_field
, int field_size
,
172 int *offset
, const char *format
, ...);
173 extern char * ustcomm_restore_ptr(char *ptr
, char *data_field
,
174 int data_field_size
);
176 #define COMPUTE_MSG_SIZE(struct_ptr, offset) \
177 (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset)
179 /* Packing and unpacking functions, making life easier */
180 extern int ustcomm_pack_trace_info(struct ustcomm_header
*header
,
181 struct ustcomm_trace_info
*trace_inf
,
184 extern int ustcomm_unpack_trace_info(struct ustcomm_trace_info
*trace_inf
);
186 extern int ustcomm_pack_channel_info(struct ustcomm_header
*header
,
187 struct ustcomm_channel_info
*ch_inf
,
188 const char *channel
);
190 extern int ustcomm_unpack_channel_info(struct ustcomm_channel_info
*ch_inf
);
192 extern int ustcomm_pack_buffer_info(struct ustcomm_header
*header
,
193 struct ustcomm_buffer_info
*buf_inf
,
197 extern int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info
*buf_inf
);
199 extern int ustcomm_pack_marker_info(struct ustcomm_header
*header
,
200 struct ustcomm_marker_info
*marker_inf
,
204 extern int ustcomm_unpack_marker_info(struct ustcomm_marker_info
*marker_inf
);
207 extern int ustcomm_pack_sock_path(struct ustcomm_header
*header
,
208 struct ustcomm_sock_path
*sock_path_inf
,
209 const char *socket_path
);
211 extern int ustcomm_unpack_sock_path(struct ustcomm_sock_path
*sock_path_inf
);
213 #endif /* USTCOMM_H */