Make app socket directories per-user v2
[lttng-ust.git] / libustcomm / ustcomm.h
1 /* Copyright (C) 2009 Pierre-Marc Fournier
2 *
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.
7 *
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.
12 *
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
16 */
17
18 #ifndef USTCOMM_H
19 #define USTCOMM_H
20
21 #include <sys/types.h>
22 #include <sys/un.h>
23 #include <urcu/list.h>
24
25 #include <ust/kcompat/kcompat.h>
26
27 #define SOCK_DIR "/tmp/ust-app-socks"
28 #define USER_SOCK_DIR "/tmp/ust-socks-"
29
30 struct ustcomm_sock {
31 struct cds_list_head list;
32 int fd;
33 int epoll_fd;
34 };
35
36 struct ustcomm_header {
37 int command;
38 long size;
39 int result;
40 int fd_included;
41 };
42
43 #define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header))
44
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
49 */
50 #define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *))
51
52 enum tracectl_commands {
53 ALLOC_TRACE,
54 CONSUME_BUFFER,
55 CREATE_TRACE,
56 DESTROY_TRACE,
57 DISABLE_MARKER,
58 ENABLE_MARKER,
59 EXIT,
60 FORCE_SUBBUF_SWITCH,
61 GET_BUF_SHMID_PIPE_FD,
62 GET_PIDUNIQUE,
63 GET_SOCK_PATH,
64 GET_SUBBUFFER,
65 GET_SUBBUF_NUM_SIZE,
66 LIST_MARKERS,
67 LIST_TRACE_EVENTS,
68 LOAD_PROBE_LIB,
69 NOTIFY_BUF_MAPPED,
70 PRINT_MARKERS,
71 PRINT_TRACE_EVENTS,
72 PUT_SUBBUFFER,
73 SETUP_TRACE,
74 SET_SOCK_PATH,
75 SET_SUBBUF_NUM,
76 SET_SUBBUF_SIZE,
77 START,
78 START_TRACE,
79 STOP_TRACE,
80 };
81
82 struct ustcomm_single_field {
83 char *field;
84 char data[USTCOMM_DATA_SIZE];
85 };
86
87 struct ustcomm_channel_info {
88 char *trace;
89 char *channel;
90 unsigned int subbuf_size;
91 unsigned int subbuf_num;
92 char data[USTCOMM_DATA_SIZE];
93 };
94
95 struct ustcomm_buffer_info {
96 char *trace;
97 char *channel;
98 int ch_cpu;
99 pid_t pid;
100 int buf_shmid;
101 int buf_struct_shmid;
102 long consumed_old;
103 char data[USTCOMM_DATA_SIZE];
104 };
105
106 struct ustcomm_marker_info {
107 char *trace;
108 char *channel;
109 char *marker;
110 char data[USTCOMM_DATA_SIZE];
111 };
112
113 struct ustcomm_pidunique {
114 s64 pidunique;
115 };
116
117 struct ustcomm_notify_buf_mapped {
118 char data[USTCOMM_DATA_SIZE];
119 };
120
121 /* Ensure directory existence, usefull for unix sockets */
122 extern int ensure_dir_exists(const char *dir);
123
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);
128
129 /* Create and delete named sockets */
130 extern struct ustcomm_sock * ustcomm_init_named_socket(const char *name,
131 int epoll_fd);
132 extern void ustcomm_del_named_sock(struct ustcomm_sock *sock,
133 int keep_socket_file);
134
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);
140
141 /* Normal send and receive functions */
142 extern int ustcomm_send(int sock, const struct ustcomm_header *header,
143 const char *data);
144 extern int ustcomm_recv(int sock, struct ustcomm_header *header,
145 char *data);
146
147 /* Receive and allocate data, not to be used inside libust */
148 extern int ustcomm_recv_alloc(int sock,
149 struct ustcomm_header *header,
150 char **data);
151
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,
157 char *res_data);
158
159 extern int ustcomm_request_consumer(pid_t pid, const char *channel);
160
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);
165
166 extern int nth_token_is(const char *str, const char *token, int tok_no);
167
168 extern char *nth_token(const char *str, int tok_no);
169
170 /* String serialising functions, printf straight into a buffer */
171 #define USTCOMM_POISON_PTR (void *)0x19831018
172
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);
177
178 #define COMPUTE_MSG_SIZE(struct_ptr, offset) \
179 (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset)
180
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,
184 const char *trace);
185
186 extern int ustcomm_unpack_single_field(struct ustcomm_single_field *sf);
187
188 extern int ustcomm_pack_channel_info(struct ustcomm_header *header,
189 struct ustcomm_channel_info *ch_inf,
190 const char *trace,
191 const char *channel);
192
193 extern int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf);
194
195 extern int ustcomm_pack_buffer_info(struct ustcomm_header *header,
196 struct ustcomm_buffer_info *buf_inf,
197 const char *trace,
198 const char *channel,
199 int channel_cpu);
200
201 extern int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf);
202
203 extern int ustcomm_pack_marker_info(struct ustcomm_header *header,
204 struct ustcomm_marker_info *marker_inf,
205 const char *trace,
206 const char *channel,
207 const char *marker);
208
209 extern int ustcomm_unpack_marker_info(struct ustcomm_marker_info *marker_inf);
210
211 #endif /* USTCOMM_H */
This page took 0.055348 seconds and 5 git commands to generate.