2 * Copyright (C) 2009 Pierre-Marc Fournier
3 * 2010 Nils Carlson <nils.carlson@ericsson.com>
4 * 2011 David Goulet <david.goulet@polymtl.ca>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef _LTT_LIBUSTCOMM_H
22 #define _LTT_LIBUSTCOMM_H
24 #include <sys/types.h>
26 #include <urcu/list.h>
28 #include "lttng-share.h"
30 #define UST_SOCK_DIR "/tmp/ust-app-socks"
31 #define USER_TMP_DIR "/tmp"
32 #define USER_SOCK_DIR_BASE "ust-socks-"
33 #define USER_SOCK_DIR USER_TMP_DIR "/" USER_SOCK_DIR_BASE
36 struct cds_list_head list
;
41 struct ustcomm_header
{
48 #define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header))
51 * Specify a sata size that leaves margin at the end of a buffer
52 * in order to make sure that we never have more data than
53 * will fit in the buffer AND that the last chars (due to a
54 * pre-receive memset) will always be 0, terminating any string
56 #define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *))
58 enum ustcomm_tracectl_commands
{
67 GET_BUF_SHMID_PIPE_FD
,
88 struct ustcomm_single_field
{
90 char data
[USTCOMM_DATA_SIZE
];
93 struct ustcomm_channel_info
{
96 unsigned int subbuf_size
;
97 unsigned int subbuf_num
;
98 char data
[USTCOMM_DATA_SIZE
];
101 struct ustcomm_buffer_info
{
107 int buf_struct_shmid
;
109 char data
[USTCOMM_DATA_SIZE
];
112 struct ustcomm_ust_marker_info
{
116 char data
[USTCOMM_DATA_SIZE
];
119 struct ustcomm_pidunique
{
123 struct ustcomm_notify_buf_mapped
{
124 char data
[USTCOMM_DATA_SIZE
];
127 /* Create and delete sockets */
128 struct ustcomm_sock
*ustcomm_init_sock(int fd
, int epoll_fd
, struct cds_list_head
*list
);
129 void ustcomm_del_sock(struct ustcomm_sock
*sock
, int keep_in_epoll
);
131 /* Create and delete named sockets */
132 struct ustcomm_sock
*ustcomm_init_named_socket(const char *name
, int epoll_fd
);
133 void ustcomm_del_named_sock(struct ustcomm_sock
*sock
, int keep_socket_file
);
135 /* Send and receive functions for file descriptors */
136 int ustcomm_send_fd(int sock
, const struct ustcomm_header
*header
,
137 const char *data
, int *fd
);
138 int ustcomm_recv_fd(int sock
, struct ustcomm_header
*header
,
139 char *data
, int *fd
);
141 /* Normal send and receive functions */
142 int ustcomm_send(int sock
, const struct ustcomm_header
*header
,
144 int ustcomm_recv(int sock
, struct ustcomm_header
*header
,
147 /* Receive and allocate data, not to be used inside libust */
148 int ustcomm_recv_alloc(int sock
, struct ustcomm_header
*header
, char **data
);
150 /* Request function, send and receive */
151 int ustcomm_req(int sock
,
152 const struct ustcomm_header
*req_header
,
153 const char *req_data
,
154 struct ustcomm_header
*res_header
,
157 int ustcomm_request_consumer(pid_t pid
, const char *channel
);
159 /* Returns the current users socket directory, must be freed */
160 char *ustcomm_user_sock_dir(void);
162 /* Get the st_m_time from proc*/
163 time_t ustcomm_pid_st_mtime(pid_t pid
);
165 /* Check that a socket is live */
166 int ustcomm_is_socket_live(char *sock_name
, pid_t
*read_pid
);
168 int ustcomm_connect_app(pid_t pid
, int *app_fd
);
169 int ustcomm_connect_path(const char *path
, int *connection_fd
);
171 /* String serialising functions, printf straight into a buffer */
172 #define USTCOMM_POISON_PTR (void *)0x19831018
174 char *ustcomm_print_data(char *data_field
, int field_size
,
175 int *offset
, const char *format
, ...);
176 char *ustcomm_restore_ptr(char *ptr
, char *data_field
, 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 int ustcomm_pack_single_field(struct ustcomm_header
*header
,
183 struct ustcomm_single_field
*sf
, const char *trace
);
185 int ustcomm_unpack_single_field(struct ustcomm_single_field
*sf
);
187 int ustcomm_pack_channel_info(struct ustcomm_header
*header
,
188 struct ustcomm_channel_info
*ch_inf
,
189 const char *trace
, const char *channel
);
191 int ustcomm_unpack_channel_info(struct ustcomm_channel_info
*ch_inf
);
193 int ustcomm_pack_buffer_info(struct ustcomm_header
*header
,
194 struct ustcomm_buffer_info
*buf_inf
,
199 int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info
*buf_inf
);
201 int ustcomm_pack_ust_marker_info(struct ustcomm_header
*header
,
202 struct ustcomm_ust_marker_info
*ust_marker_inf
,
205 const char *ust_marker
);
207 int ustcomm_unpack_ust_marker_info(struct ustcomm_ust_marker_info
*ust_marker_inf
);
209 #endif /* _LTT_LIBUSTCOMM_H */