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"
28 #define USER_SOCK_DIR "/tmp/ust-socks-"
31 struct cds_list_head list
;
36 struct ustcomm_header
{
43 #define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header))
45 /* Specify a sata size that leaves margin at the end of a buffer
46 * in order to make sure that we never have more data than
47 * will fit in the buffer AND that the last chars (due to a
48 * pre-receive memset) will always be 0, terminating any string
50 #define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *))
52 enum tracectl_commands
{
61 GET_BUF_SHMID_PIPE_FD
,
82 struct ustcomm_single_field
{
84 char data
[USTCOMM_DATA_SIZE
];
87 struct ustcomm_channel_info
{
90 unsigned int subbuf_size
;
91 unsigned int subbuf_num
;
92 char data
[USTCOMM_DATA_SIZE
];
95 struct ustcomm_buffer_info
{
101 int buf_struct_shmid
;
103 char data
[USTCOMM_DATA_SIZE
];
106 struct ustcomm_marker_info
{
110 char data
[USTCOMM_DATA_SIZE
];
113 struct ustcomm_pidunique
{
117 struct ustcomm_notify_buf_mapped
{
118 char data
[USTCOMM_DATA_SIZE
];
121 /* Ensure directory existence, usefull for unix sockets */
122 extern int ensure_dir_exists(const char *dir
);
124 /* Create and delete sockets */
125 extern struct ustcomm_sock
* ustcomm_init_sock(int fd
, int epoll_fd
,
126 struct cds_list_head
*list
);
127 extern void ustcomm_del_sock(struct ustcomm_sock
*sock
, int keep_in_epoll
);
129 /* Create and delete named sockets */
130 extern struct ustcomm_sock
* ustcomm_init_named_socket(const char *name
,
132 extern void ustcomm_del_named_sock(struct ustcomm_sock
*sock
,
133 int keep_socket_file
);
135 /* Send and receive functions for file descriptors */
136 extern int ustcomm_send_fd(int sock
, const struct ustcomm_header
*header
,
137 const char *data
, int *fd
);
138 extern int ustcomm_recv_fd(int sock
, struct ustcomm_header
*header
,
139 char *data
, int *fd
);
141 /* Normal send and receive functions */
142 extern int ustcomm_send(int sock
, const struct ustcomm_header
*header
,
144 extern int ustcomm_recv(int sock
, struct ustcomm_header
*header
,
147 /* Receive and allocate data, not to be used inside libust */
148 extern int ustcomm_recv_alloc(int sock
,
149 struct ustcomm_header
*header
,
152 /* Request function, send and receive */
153 extern int ustcomm_req(int sock
,
154 const struct ustcomm_header
*req_header
,
155 const char *req_data
,
156 struct ustcomm_header
*res_header
,
159 extern int ustcomm_request_consumer(pid_t pid
, const char *channel
);
161 /* Returns the current users socket directory, must be freed */
162 extern char *ustcomm_user_sock_dir(void);
163 extern int ustcomm_connect_app(pid_t pid
, int *app_fd
);
164 extern int ustcomm_connect_path(const char *path
, int *connection_fd
);
166 extern int nth_token_is(const char *str
, const char *token
, int tok_no
);
168 extern char *nth_token(const char *str
, int tok_no
);
170 /* String serialising functions, printf straight into a buffer */
171 #define USTCOMM_POISON_PTR (void *)0x19831018
173 extern char * ustcomm_print_data(char *data_field
, int field_size
,
174 int *offset
, const char *format
, ...);
175 extern char * ustcomm_restore_ptr(char *ptr
, char *data_field
,
176 int data_field_size
);
178 #define COMPUTE_MSG_SIZE(struct_ptr, offset) \
179 (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset)
181 /* Packing and unpacking functions, making life easier */
182 extern int ustcomm_pack_single_field(struct ustcomm_header
*header
,
183 struct ustcomm_single_field
*sf
,
186 extern int ustcomm_unpack_single_field(struct ustcomm_single_field
*sf
);
188 extern int ustcomm_pack_channel_info(struct ustcomm_header
*header
,
189 struct ustcomm_channel_info
*ch_inf
,
191 const char *channel
);
193 extern int ustcomm_unpack_channel_info(struct ustcomm_channel_info
*ch_inf
);
195 extern int ustcomm_pack_buffer_info(struct ustcomm_header
*header
,
196 struct ustcomm_buffer_info
*buf_inf
,
201 extern int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info
*buf_inf
);
203 extern int ustcomm_pack_marker_info(struct ustcomm_header
*header
,
204 struct ustcomm_marker_info
*marker_inf
,
209 extern int ustcomm_unpack_marker_info(struct ustcomm_marker_info
*marker_inf
);
211 #endif /* USTCOMM_H */