Fix return code to 0 on success and 1 on error
[lttng-tools.git] / libustcomm / libustcomm.h
CommitLineData
62d3069f
DG
1/*
2 * Copyright (C) 2009 Pierre-Marc Fournier
3 * 2010 Nils Carlson <nils.carlson@ericsson.com>
4 * 2011 David Goulet <david.goulet@polymtl.ca>
5 *
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.
10 *
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.
15 *
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
19 */
20
21#ifndef _LTT_LIBUSTCOMM_H
22#define _LTT_LIBUSTCOMM_H
23
24#include <sys/types.h>
25#include <sys/un.h>
26#include <urcu/list.h>
27
28#include "lttng-share.h"
29
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
34
35struct ustcomm_sock {
36 struct cds_list_head list;
37 int fd;
38 int epoll_fd;
39};
40
41struct ustcomm_header {
42 int command;
43 long size;
44 int result;
45 int fd_included;
46};
47
48#define USTCOMM_BUFFER_SIZE ((1 << 12) - sizeof(struct ustcomm_header))
49
50/*
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
55 */
56#define USTCOMM_DATA_SIZE (USTCOMM_BUFFER_SIZE - 20 * sizeof(void *))
57
58enum ustcomm_tracectl_commands {
59 ALLOC_TRACE,
60 CONSUME_BUFFER,
61 CREATE_TRACE,
62 DESTROY_TRACE,
63 DISABLE_MARKER,
64 ENABLE_MARKER,
65 EXIT,
66 FORCE_SUBBUF_SWITCH,
67 GET_BUF_SHMID_PIPE_FD,
68 GET_PIDUNIQUE,
69 GET_SOCK_PATH,
70 GET_SUBBUFFER,
71 GET_SUBBUF_NUM_SIZE,
72 LIST_MARKERS,
73 LIST_TRACE_EVENTS,
74 LOAD_PROBE_LIB,
75 NOTIFY_BUF_MAPPED,
76 PRINT_MARKERS,
77 PRINT_TRACE_EVENTS,
78 PUT_SUBBUFFER,
79 SETUP_TRACE,
80 SET_SOCK_PATH,
81 SET_SUBBUF_NUM,
82 SET_SUBBUF_SIZE,
83 START,
84 START_TRACE,
85 STOP_TRACE,
86};
87
88struct ustcomm_single_field {
89 char *field;
90 char data[USTCOMM_DATA_SIZE];
91};
92
93struct ustcomm_channel_info {
94 char *trace;
95 char *channel;
96 unsigned int subbuf_size;
97 unsigned int subbuf_num;
98 char data[USTCOMM_DATA_SIZE];
99};
100
101struct ustcomm_buffer_info {
102 char *trace;
103 char *channel;
104 int ch_cpu;
105 pid_t pid;
106 int buf_shmid;
107 int buf_struct_shmid;
108 long consumed_old;
109 char data[USTCOMM_DATA_SIZE];
110};
111
112struct ustcomm_ust_marker_info {
113 char *trace;
114 char *channel;
115 char *ust_marker;
116 char data[USTCOMM_DATA_SIZE];
117};
118
119struct ustcomm_pidunique {
120 s64 pidunique;
121};
122
123struct ustcomm_notify_buf_mapped {
124 char data[USTCOMM_DATA_SIZE];
125};
126
127/* Create and delete sockets */
128struct ustcomm_sock *ustcomm_init_sock(int fd, int epoll_fd, struct cds_list_head *list);
129void ustcomm_del_sock(struct ustcomm_sock *sock, int keep_in_epoll);
130
131/* Create and delete named sockets */
132struct ustcomm_sock *ustcomm_init_named_socket(const char *name, int epoll_fd);
133void ustcomm_del_named_sock(struct ustcomm_sock *sock, int keep_socket_file);
134
135/* Send and receive functions for file descriptors */
136int ustcomm_send_fd(int sock, const struct ustcomm_header *header,
137 const char *data, int *fd);
138int ustcomm_recv_fd(int sock, struct ustcomm_header *header,
139 char *data, int *fd);
140
141/* Normal send and receive functions */
142int ustcomm_send(int sock, const struct ustcomm_header *header,
143 const char *data);
144int ustcomm_recv(int sock, struct ustcomm_header *header,
145 char *data);
146
147/* Receive and allocate data, not to be used inside libust */
148int ustcomm_recv_alloc(int sock, struct ustcomm_header *header, char **data);
149
150/* Request function, send and receive */
151int ustcomm_req(int sock,
152 const struct ustcomm_header *req_header,
153 const char *req_data,
154 struct ustcomm_header *res_header,
155 char *res_data);
156
157int ustcomm_request_consumer(pid_t pid, const char *channel);
158
159/* Returns the current users socket directory, must be freed */
160char *ustcomm_user_sock_dir(void);
161
162/* Get the st_m_time from proc*/
163time_t ustcomm_pid_st_mtime(pid_t pid);
164
165/* Check that a socket is live */
166int ustcomm_is_socket_live(char *sock_name, pid_t *read_pid);
167
168int ustcomm_connect_app(pid_t pid, int *app_fd);
169int ustcomm_connect_path(const char *path, int *connection_fd);
170
171/* String serialising functions, printf straight into a buffer */
172#define USTCOMM_POISON_PTR (void *)0x19831018
173
174char *ustcomm_print_data(char *data_field, int field_size,
175 int *offset, const char *format, ...);
176char *ustcomm_restore_ptr(char *ptr, char *data_field, 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 */
182int ustcomm_pack_single_field(struct ustcomm_header *header,
183 struct ustcomm_single_field *sf, const char *trace);
184
185int ustcomm_unpack_single_field(struct ustcomm_single_field *sf);
186
187int ustcomm_pack_channel_info(struct ustcomm_header *header,
188 struct ustcomm_channel_info *ch_inf,
189 const char *trace, const char *channel);
190
191int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf);
192
193int ustcomm_pack_buffer_info(struct ustcomm_header *header,
194 struct ustcomm_buffer_info *buf_inf,
195 const char *trace,
196 const char *channel,
197 int channel_cpu);
198
199int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf);
200
201int ustcomm_pack_ust_marker_info(struct ustcomm_header *header,
202 struct ustcomm_ust_marker_info *ust_marker_inf,
203 const char *trace,
204 const char *channel,
205 const char *ust_marker);
206
207int ustcomm_unpack_ust_marker_info(struct ustcomm_ust_marker_info *ust_marker_inf);
208
209#endif /* _LTT_LIBUSTCOMM_H */
This page took 0.032419 seconds and 4 git commands to generate.