Cleanup: don't spawn per-user thread if HOME is not set
[lttng-ust.git] / include / ust-comm.h
CommitLineData
b35d179d
MD
1#ifndef _LTTNG_UST_COMM_H
2#define _LTTNG_UST_COMM_H
67c5b804
MD
3
4/*
5 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
6 * Julien Desfossez <julien.desfossez@polymtl.ca>
7 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
15f672f9
MD
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; only
12 * version 2.1 of the License.
13 *
14 * This library is distributed in the hope that it will be useful,
67c5b804 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15f672f9
MD
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
67c5b804
MD
22 */
23
24/*
25 * This header is meant for liblttng and libust internal use ONLY.
26 * These declarations should NOT be considered stable API.
27 */
28
29#include <limits.h>
57773204 30#include <unistd.h>
4318ae1b 31#include <lttng/ust-abi.h>
67c5b804 32
11ff9c7d 33/*
cf12a773
MD
34 * Default timeout the application waits for the sessiond to send its
35 * "register done" command. Can be overridden with the environment
69400ac4 36 * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not
cf12a773 37 * found, the application proceeds directly without any delay.
11ff9c7d 38 */
cf12a773 39#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000
11ff9c7d 40
67c5b804 41#define LTTNG_RUNDIR "/var/run/lttng"
6a47c1fb 42#define LTTNG_HOME_RUNDIR "%s/.lttng"
67c5b804
MD
43
44/* Default unix socket path */
8d1dae7c
MD
45#define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-lttng-sessiond"
46#define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-lttng-sessiond"
6a47c1fb
DG
47#define DEFAULT_HOME_APPS_UNIX_SOCK LTTNG_HOME_RUNDIR "/apps-lttng-sessiond"
48#define DEFAULT_HOME_CLIENT_UNIX_SOCK LTTNG_HOME_RUNDIR "/client-lttng-sessiond"
67c5b804 49
7fc90dca 50#define DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait"
58d4b2a2 51#define DEFAULT_HOME_APPS_WAIT_SHM_PATH "/lttng-ust-apps-wait-%u"
7fc90dca 52
67c5b804 53/* Queue size of listen(2) */
e41474be 54#define LTTNG_UST_COMM_MAX_LISTEN 10
67c5b804 55
57773204 56/* Get the error code index from 0. USTCOMM_ERR starts at 1000.
67c5b804 57 */
57773204 58#define USTCOMM_ERR_INDEX(code) (code - USTCOMM_ERR)
67c5b804 59
67c5b804 60/*
57773204 61 * ustcomm error code.
67c5b804 62 */
57773204
MD
63enum ustcomm_return_code {
64 USTCOMM_OK = 0, /* Ok */
65 /* Range 1 to 999 used for standard error numbers (errno.h) */
66 USTCOMM_ERR = 1000, /* Unknown Error */
67 USTCOMM_UND, /* Undefine command */
68 USTCOMM_NOT_IMPLEMENTED, /* Command not implemented */
69 USTCOMM_UNKNOWN_DOMAIN, /* Tracing domain not known */
70 USTCOMM_ALLOC_FAIL, /* Trace allocation fail */
71 USTCOMM_NO_SESSION, /* No session found */
72 USTCOMM_CREATE_FAIL, /* Create trace fail */
73 USTCOMM_SESSION_FAIL, /* Create session fail */
74 USTCOMM_START_FAIL, /* Start tracing fail */
75 USTCOMM_STOP_FAIL, /* Stop tracing fail */
76 USTCOMM_LIST_FAIL, /* Listing apps fail */
77 USTCOMM_NO_APPS, /* No traceable application */
78 USTCOMM_SESS_NOT_FOUND, /* Session name not found */
79 USTCOMM_NO_TRACE, /* No trace exist */
80 USTCOMM_FATAL, /* Session daemon had a fatal error */
81 USTCOMM_NO_TRACEABLE, /* Error for non traceable app */
82 USTCOMM_SELECT_SESS, /* Must select a session */
83 USTCOMM_EXIST_SESS, /* Session name already exist */
84 USTCOMM_NO_EVENT, /* No event found */
85 USTCOMM_KERN_NA, /* Kernel tracer unavalable */
86 USTCOMM_KERN_EVENT_EXIST, /* Kernel event already exists */
87 USTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */
88 USTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */
89 USTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */
90 USTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */
91 USTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */
92 USTCOMM_KERN_CONTEXT_FAIL, /* Kernel add context failed */
93 USTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */
94 USTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */
95 USTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */
96 USTCOMM_KERN_START_FAIL, /* Kernel start trace failed */
97 USTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */
98 USTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */
99 USTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */
100 USTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */
101 USTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */
102 USTCOMM_KERN_NO_SESSION, /* No kernel session found */
103 USTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */
104 USTCONSUMER_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */
105 USTCONSUMER_SUCCESS_RECV_FD, /* success on receiving fds */
106 USTCONSUMER_ERROR_RECV_FD, /* error on receiving fds */
107 USTCONSUMER_POLL_ERROR, /* Error in polling thread in kconsumerd */
108 USTCONSUMER_POLL_NVAL, /* Poll on closed fd */
109 USTCONSUMER_POLL_HUP, /* All fds have hungup */
110 USTCONSUMER_EXIT_SUCCESS, /* kconsumerd exiting normally */
111 USTCONSUMER_EXIT_FAILURE, /* kconsumerd exiting on error */
112 USTCONSUMER_OUTFD_ERROR, /* error opening the tracefile */
113 USTCONSUMER_SPLICE_EBADF, /* EBADF from splice(2) */
114 USTCONSUMER_SPLICE_EINVAL, /* EINVAL from splice(2) */
115 USTCONSUMER_SPLICE_ENOMEM, /* ENOMEM from splice(2) */
116 USTCONSUMER_SPLICE_ESPIPE, /* ESPIPE from splice(2) */
67c5b804 117 /* MUST be last element */
57773204 118 USTCOMM_NR, /* Last element */
67c5b804
MD
119};
120
121/*
e7723462 122 * Data structure for the commands sent from sessiond to UST.
67c5b804 123 */
57773204 124struct ustcomm_ust_msg {
1ece9766 125 uint32_t handle;
46050b1a 126 uint32_t cmd;
67c5b804 127 union {
1ece9766 128 struct lttng_ust_channel channel;
381c0f1e 129 struct lttng_ust_stream stream;
1ece9766
MD
130 struct lttng_ust_event event;
131 struct lttng_ust_context context;
57773204 132 struct lttng_ust_tracer_version version;
cbef6901 133 struct lttng_ust_tracepoint_iter tracepoint;
2d78951a 134 struct {
2734ca65
CB
135 uint32_t data_size; /* following filter data */
136 uint32_t reloc_offset;
2d78951a 137 } filter;
67c5b804
MD
138 } u;
139};
140
9eb62b9c
MD
141/*
142 * Data structure for the response from UST to the session daemon.
143 * cmd_type is sent back in the reply for validation.
144 */
57773204 145struct ustcomm_ust_reply {
46050b1a
MD
146 uint32_t handle;
147 uint32_t cmd;
57773204 148 uint32_t ret_code; /* enum enum ustcomm_return_code */
1ece9766 149 uint32_t ret_val; /* return value */
9eb62b9c 150 union {
193183fb
MD
151 struct {
152 uint64_t memory_map_size;
153 } channel;
381c0f1e
MD
154 struct {
155 uint64_t memory_map_size;
156 } stream;
57773204 157 struct lttng_ust_tracer_version version;
cbef6901 158 struct lttng_ust_tracepoint_iter tracepoint;
9eb62b9c
MD
159 } u;
160};
161
40003310
MD
162/*
163 * LTTNG_UST_TRACEPOINT_FIELD_LIST reply is followed by a
164 * struct lttng_ust_field_iter field.
165 */
166
57773204
MD
167extern int ustcomm_create_unix_sock(const char *pathname);
168extern int ustcomm_connect_unix_sock(const char *pathname);
169extern int ustcomm_accept_unix_sock(int sock);
170extern int ustcomm_listen_unix_sock(int sock);
171extern int ustcomm_close_unix_sock(int sock);
67c5b804 172/* Send fd(s) over a unix socket. */
57773204 173extern ssize_t ustcomm_send_fds_unix_sock(int sock, void *buf, int *fds,
67c5b804 174 size_t nb_fd, size_t len);
57773204
MD
175extern ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len);
176extern ssize_t ustcomm_send_unix_sock(int sock, void *buf, size_t len);
177extern const char *ustcomm_get_readable_code(int code);
178extern int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum);
179extern int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur,
180 uint32_t expected_handle, uint32_t expected_cmd);
181extern int ustcomm_send_app_cmd(int sock,
182 struct ustcomm_ust_msg *lum,
183 struct ustcomm_ust_reply *lur);
184int ustcomm_recv_fd(int sock);
67c5b804 185
b35d179d 186#endif /* _LTTNG_UST_COMM_H */
This page took 0.034556 seconds and 4 git commands to generate.