Commit | Line | Data |
---|---|---|
2691221a MD |
1 | /* |
2 | * lttng-ust-comm.c | |
3 | * | |
4 | * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca> | |
5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; only | |
10 | * version 2.1 of the License. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | */ | |
21 | ||
80e2814b | 22 | #define _LGPL_SOURCE |
2691221a MD |
23 | #include <sys/types.h> |
24 | #include <sys/socket.h> | |
7fc90dca MD |
25 | #include <sys/mman.h> |
26 | #include <sys/stat.h> | |
58d4b2a2 MD |
27 | #include <sys/types.h> |
28 | #include <sys/wait.h> | |
7fc90dca | 29 | #include <fcntl.h> |
2691221a MD |
30 | #include <unistd.h> |
31 | #include <errno.h> | |
d9e99d10 | 32 | #include <pthread.h> |
11ff9c7d MD |
33 | #include <semaphore.h> |
34 | #include <time.h> | |
1ea11eab | 35 | #include <assert.h> |
e822f505 | 36 | #include <signal.h> |
95c25348 | 37 | #include <dlfcn.h> |
95259bd0 | 38 | #include <urcu/uatomic.h> |
80e2814b | 39 | #include <urcu/futex.h> |
c117fb1b | 40 | #include <urcu/compiler.h> |
1ea11eab | 41 | |
4318ae1b | 42 | #include <lttng/ust-events.h> |
4318ae1b | 43 | #include <lttng/ust-abi.h> |
4318ae1b | 44 | #include <lttng/ust.h> |
7bc53e94 | 45 | #include <lttng/ust-error.h> |
74d81a6c | 46 | #include <lttng/ust-ctl.h> |
8c90a710 | 47 | #include <urcu/tls-compat.h> |
44c72f10 MD |
48 | #include <ust-comm.h> |
49 | #include <usterr-signal-safe.h> | |
cd54f6d9 | 50 | #include <helper.h> |
44c72f10 | 51 | #include "tracepoint-internal.h" |
7dd08bec | 52 | #include "lttng-tracer-core.h" |
08114193 | 53 | #include "compat.h" |
f645cfa7 | 54 | #include "../libringbuffer/tlsfixup.h" |
edaa1431 MD |
55 | |
56 | /* | |
57 | * Has lttng ust comm constructor been called ? | |
58 | */ | |
59 | static int initialized; | |
60 | ||
1ea11eab | 61 | /* |
17dfb34b MD |
62 | * The ust_lock/ust_unlock lock is used as a communication thread mutex. |
63 | * Held when handling a command, also held by fork() to deal with | |
64 | * removal of threads, and by exit path. | |
1ea11eab | 65 | */ |
1ea11eab MD |
66 | |
67 | /* Should the ust comm thread quit ? */ | |
68 | static int lttng_ust_comm_should_quit; | |
69 | ||
11ff9c7d MD |
70 | /* |
71 | * Wait for either of these before continuing to the main | |
72 | * program: | |
73 | * - the register_done message from sessiond daemon | |
74 | * (will let the sessiond daemon enable sessions before main | |
75 | * starts.) | |
76 | * - sessiond daemon is not reachable. | |
77 | * - timeout (ensuring applications are resilient to session | |
78 | * daemon problems). | |
79 | */ | |
80 | static sem_t constructor_wait; | |
950aab0c MD |
81 | /* |
82 | * Doing this for both the global and local sessiond. | |
83 | */ | |
95259bd0 | 84 | static int sem_count = { 2 }; |
11ff9c7d | 85 | |
e8508a49 MD |
86 | /* |
87 | * Counting nesting within lttng-ust. Used to ensure that calling fork() | |
88 | * from liblttng-ust does not execute the pre/post fork handlers. | |
89 | */ | |
8c90a710 | 90 | static DEFINE_URCU_TLS(int, lttng_ust_nest_count); |
e8508a49 | 91 | |
1ea11eab MD |
92 | /* |
93 | * Info about socket and associated listener thread. | |
94 | */ | |
95 | struct sock_info { | |
11ff9c7d | 96 | const char *name; |
1ea11eab | 97 | pthread_t ust_listener; /* listener thread */ |
46050b1a | 98 | int root_handle; |
8d20bf54 MD |
99 | int constructor_sem_posted; |
100 | int allowed; | |
44e073f5 | 101 | int global; |
e33f3265 | 102 | int thread_active; |
7fc90dca MD |
103 | |
104 | char sock_path[PATH_MAX]; | |
105 | int socket; | |
32ce8569 | 106 | int notify_socket; |
7fc90dca MD |
107 | |
108 | char wait_shm_path[PATH_MAX]; | |
109 | char *wait_shm_mmap; | |
95c25348 | 110 | struct lttng_session *session_enabled; |
1ea11eab | 111 | }; |
2691221a MD |
112 | |
113 | /* Socket from app (connect) to session daemon (listen) for communication */ | |
1ea11eab | 114 | struct sock_info global_apps = { |
11ff9c7d | 115 | .name = "global", |
44e073f5 | 116 | .global = 1, |
7fc90dca | 117 | |
46050b1a | 118 | .root_handle = -1, |
8d20bf54 | 119 | .allowed = 1, |
e33f3265 | 120 | .thread_active = 0, |
7fc90dca | 121 | |
32ce8569 | 122 | .sock_path = LTTNG_DEFAULT_RUNDIR "/" LTTNG_UST_SOCK_FILENAME, |
7fc90dca | 123 | .socket = -1, |
32ce8569 | 124 | .notify_socket = -1, |
7fc90dca | 125 | |
32ce8569 | 126 | .wait_shm_path = "/" LTTNG_UST_WAIT_FILENAME, |
95c25348 PW |
127 | |
128 | .session_enabled = NULL, | |
1ea11eab | 129 | }; |
2691221a MD |
130 | |
131 | /* TODO: allow global_apps_sock_path override */ | |
132 | ||
1ea11eab | 133 | struct sock_info local_apps = { |
11ff9c7d | 134 | .name = "local", |
44e073f5 | 135 | .global = 0, |
46050b1a | 136 | .root_handle = -1, |
8d20bf54 | 137 | .allowed = 0, /* Check setuid bit first */ |
e33f3265 | 138 | .thread_active = 0, |
7fc90dca MD |
139 | |
140 | .socket = -1, | |
32ce8569 | 141 | .notify_socket = -1, |
95c25348 PW |
142 | |
143 | .session_enabled = NULL, | |
1ea11eab | 144 | }; |
2691221a | 145 | |
37ed587a MD |
146 | static int wait_poll_fallback; |
147 | ||
74d81a6c MD |
148 | static const char *cmd_name_mapping[] = { |
149 | [ LTTNG_UST_RELEASE ] = "Release", | |
150 | [ LTTNG_UST_SESSION ] = "Create Session", | |
151 | [ LTTNG_UST_TRACER_VERSION ] = "Get Tracer Version", | |
152 | ||
153 | [ LTTNG_UST_TRACEPOINT_LIST ] = "Create Tracepoint List", | |
154 | [ LTTNG_UST_WAIT_QUIESCENT ] = "Wait for Quiescent State", | |
155 | [ LTTNG_UST_REGISTER_DONE ] = "Registration Done", | |
156 | [ LTTNG_UST_TRACEPOINT_FIELD_LIST ] = "Create Tracepoint Field List", | |
157 | ||
158 | /* Session FD commands */ | |
159 | [ LTTNG_UST_CHANNEL ] = "Create Channel", | |
160 | [ LTTNG_UST_SESSION_START ] = "Start Session", | |
161 | [ LTTNG_UST_SESSION_STOP ] = "Stop Session", | |
162 | ||
163 | /* Channel FD commands */ | |
164 | [ LTTNG_UST_STREAM ] = "Create Stream", | |
165 | [ LTTNG_UST_EVENT ] = "Create Event", | |
166 | ||
167 | /* Event and Channel FD commands */ | |
168 | [ LTTNG_UST_CONTEXT ] = "Create Context", | |
169 | [ LTTNG_UST_FLUSH_BUFFER ] = "Flush Buffer", | |
170 | ||
171 | /* Event, Channel and Session commands */ | |
172 | [ LTTNG_UST_ENABLE ] = "Enable", | |
173 | [ LTTNG_UST_DISABLE ] = "Disable", | |
174 | ||
175 | /* Tracepoint list commands */ | |
176 | [ LTTNG_UST_TRACEPOINT_LIST_GET ] = "List Next Tracepoint", | |
177 | [ LTTNG_UST_TRACEPOINT_FIELD_LIST_GET ] = "List Next Tracepoint Field", | |
178 | ||
179 | /* Event FD commands */ | |
180 | [ LTTNG_UST_FILTER ] = "Create Filter", | |
75582b3a | 181 | [ LTTNG_UST_EXCLUSION ] = "Add exclusions to event", |
74d81a6c MD |
182 | }; |
183 | ||
ff517991 MD |
184 | static const char *str_timeout; |
185 | static int got_timeout_env; | |
95c25348 | 186 | static void *ust_baddr_handle; |
ff517991 | 187 | |
7dd08bec | 188 | extern void lttng_ring_buffer_client_overwrite_init(void); |
34a91bdb | 189 | extern void lttng_ring_buffer_client_overwrite_rt_init(void); |
7dd08bec | 190 | extern void lttng_ring_buffer_client_discard_init(void); |
34a91bdb | 191 | extern void lttng_ring_buffer_client_discard_rt_init(void); |
7dd08bec MD |
192 | extern void lttng_ring_buffer_metadata_client_init(void); |
193 | extern void lttng_ring_buffer_client_overwrite_exit(void); | |
34a91bdb | 194 | extern void lttng_ring_buffer_client_overwrite_rt_exit(void); |
7dd08bec | 195 | extern void lttng_ring_buffer_client_discard_exit(void); |
34a91bdb | 196 | extern void lttng_ring_buffer_client_discard_rt_exit(void); |
7dd08bec | 197 | extern void lttng_ring_buffer_metadata_client_exit(void); |
edaa1431 | 198 | |
3c6f6263 AM |
199 | /* |
200 | * Returns the HOME directory path. Caller MUST NOT free(3) the returned | |
201 | * pointer. | |
202 | */ | |
203 | static | |
204 | const char *get_lttng_home_dir(void) | |
205 | { | |
206 | const char *val; | |
207 | ||
208 | val = (const char *) getenv("LTTNG_HOME"); | |
209 | if (val != NULL) { | |
210 | return val; | |
211 | } | |
212 | return (const char *) getenv("HOME"); | |
213 | } | |
214 | ||
a903623f MD |
215 | /* |
216 | * Force a read (imply TLS fixup for dlopen) of TLS variables. | |
217 | */ | |
218 | static | |
219 | void lttng_fixup_nest_count_tls(void) | |
220 | { | |
8c90a710 | 221 | asm volatile ("" : : "m" (URCU_TLS(lttng_ust_nest_count))); |
a903623f MD |
222 | } |
223 | ||
32ce8569 MD |
224 | int lttng_get_notify_socket(void *owner) |
225 | { | |
226 | struct sock_info *info = owner; | |
227 | ||
228 | return info->notify_socket; | |
229 | } | |
230 | ||
74d81a6c MD |
231 | static |
232 | void print_cmd(int cmd, int handle) | |
233 | { | |
234 | const char *cmd_name = "Unknown"; | |
235 | ||
fd67a004 MD |
236 | if (cmd >= 0 && cmd < LTTNG_ARRAY_SIZE(cmd_name_mapping) |
237 | && cmd_name_mapping[cmd]) { | |
74d81a6c MD |
238 | cmd_name = cmd_name_mapping[cmd]; |
239 | } | |
fd67a004 MD |
240 | DBG("Message Received \"%s\" (%d), Handle \"%s\" (%d)", |
241 | cmd_name, cmd, | |
74d81a6c MD |
242 | lttng_ust_obj_get_name(handle), handle); |
243 | } | |
244 | ||
95c25348 PW |
245 | static |
246 | void *lttng_ust_baddr_handle(void) | |
247 | { | |
248 | if (!ust_baddr_handle) { | |
249 | ust_baddr_handle = dlopen( | |
250 | "liblttng-ust-baddr.so.0", RTLD_NOW | RTLD_GLOBAL); | |
251 | if (ust_baddr_handle == NULL) | |
252 | ERR("%s", dlerror()); | |
253 | } | |
254 | return ust_baddr_handle; | |
255 | } | |
256 | ||
257 | static | |
258 | int lttng_ust_baddr_statedump(struct lttng_session *session) | |
259 | { | |
260 | static | |
261 | int (*lttng_ust_baddr_init_fn)(struct lttng_session *); | |
262 | ||
263 | if (!lttng_ust_baddr_init_fn) { | |
264 | void *baddr_handle = lttng_ust_baddr_handle(); | |
265 | if (baddr_handle) { | |
266 | lttng_ust_baddr_init_fn = dlsym(baddr_handle, | |
267 | "lttng_ust_baddr_statedump"); | |
268 | if (lttng_ust_baddr_init_fn == NULL) | |
269 | ERR("%s", dlerror()); | |
270 | } | |
271 | if (!lttng_ust_baddr_init_fn) | |
272 | return -1; | |
273 | } | |
274 | ||
275 | return lttng_ust_baddr_init_fn(session); | |
276 | } | |
277 | ||
2691221a | 278 | static |
8d20bf54 | 279 | int setup_local_apps(void) |
2691221a MD |
280 | { |
281 | const char *home_dir; | |
7fc90dca | 282 | uid_t uid; |
2691221a | 283 | |
7fc90dca | 284 | uid = getuid(); |
8d20bf54 MD |
285 | /* |
286 | * Disallow per-user tracing for setuid binaries. | |
287 | */ | |
7fc90dca | 288 | if (uid != geteuid()) { |
9ec6895c | 289 | assert(local_apps.allowed == 0); |
d0a1ae63 | 290 | return 0; |
8d20bf54 | 291 | } |
3c6f6263 | 292 | home_dir = get_lttng_home_dir(); |
9ec6895c MD |
293 | if (!home_dir) { |
294 | WARN("HOME environment variable not set. Disabling LTTng-UST per-user tracing."); | |
295 | assert(local_apps.allowed == 0); | |
2691221a | 296 | return -ENOENT; |
9ec6895c MD |
297 | } |
298 | local_apps.allowed = 1; | |
32ce8569 MD |
299 | snprintf(local_apps.sock_path, PATH_MAX, "%s/%s/%s", |
300 | home_dir, | |
301 | LTTNG_DEFAULT_HOME_RUNDIR, | |
302 | LTTNG_UST_SOCK_FILENAME); | |
303 | snprintf(local_apps.wait_shm_path, PATH_MAX, "/%s-%u", | |
304 | LTTNG_UST_WAIT_FILENAME, | |
305 | uid); | |
2691221a MD |
306 | return 0; |
307 | } | |
308 | ||
ff517991 MD |
309 | /* |
310 | * Get notify_sock timeout, in ms. | |
311 | * -1: don't wait. 0: wait forever. >0: timeout, in ms. | |
312 | */ | |
313 | static | |
314 | long get_timeout(void) | |
315 | { | |
316 | long constructor_delay_ms = LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS; | |
317 | ||
318 | if (!got_timeout_env) { | |
319 | str_timeout = getenv("LTTNG_UST_REGISTER_TIMEOUT"); | |
320 | got_timeout_env = 1; | |
321 | } | |
322 | if (str_timeout) | |
323 | constructor_delay_ms = strtol(str_timeout, NULL, 10); | |
324 | return constructor_delay_ms; | |
325 | } | |
326 | ||
327 | static | |
328 | long get_notify_sock_timeout(void) | |
329 | { | |
330 | return get_timeout(); | |
331 | } | |
332 | ||
333 | /* | |
334 | * Return values: -1: don't wait. 0: wait forever. 1: timeout wait. | |
335 | */ | |
336 | static | |
337 | int get_constructor_timeout(struct timespec *constructor_timeout) | |
338 | { | |
339 | long constructor_delay_ms; | |
340 | int ret; | |
341 | ||
342 | constructor_delay_ms = get_timeout(); | |
343 | ||
344 | switch (constructor_delay_ms) { | |
345 | case -1:/* fall-through */ | |
346 | case 0: | |
347 | return constructor_delay_ms; | |
348 | default: | |
349 | break; | |
350 | } | |
351 | ||
352 | /* | |
353 | * If we are unable to find the current time, don't wait. | |
354 | */ | |
355 | ret = clock_gettime(CLOCK_REALTIME, constructor_timeout); | |
356 | if (ret) { | |
357 | return -1; | |
358 | } | |
359 | constructor_timeout->tv_sec += constructor_delay_ms / 1000UL; | |
360 | constructor_timeout->tv_nsec += | |
361 | (constructor_delay_ms % 1000UL) * 1000000UL; | |
362 | if (constructor_timeout->tv_nsec >= 1000000000UL) { | |
363 | constructor_timeout->tv_sec++; | |
364 | constructor_timeout->tv_nsec -= 1000000000UL; | |
365 | } | |
366 | return 1; | |
367 | } | |
368 | ||
2691221a | 369 | static |
32ce8569 | 370 | int register_to_sessiond(int socket, enum ustctl_socket_type type) |
2691221a | 371 | { |
32ce8569 MD |
372 | return ustcomm_send_reg_msg(socket, |
373 | type, | |
374 | CAA_BITS_PER_LONG, | |
375 | lttng_alignof(uint8_t) * CHAR_BIT, | |
376 | lttng_alignof(uint16_t) * CHAR_BIT, | |
377 | lttng_alignof(uint32_t) * CHAR_BIT, | |
378 | lttng_alignof(uint64_t) * CHAR_BIT, | |
379 | lttng_alignof(unsigned long) * CHAR_BIT); | |
2691221a MD |
380 | } |
381 | ||
d9e99d10 | 382 | static |
57773204 | 383 | int send_reply(int sock, struct ustcomm_ust_reply *lur) |
d9e99d10 | 384 | { |
9eb62b9c | 385 | ssize_t len; |
d3a492d1 | 386 | |
57773204 | 387 | len = ustcomm_send_unix_sock(sock, lur, sizeof(*lur)); |
d3a492d1 | 388 | switch (len) { |
a4be8962 | 389 | case sizeof(*lur): |
d3a492d1 MD |
390 | DBG("message successfully sent"); |
391 | return 0; | |
7bc53e94 MD |
392 | default: |
393 | if (len == -ECONNRESET) { | |
394 | DBG("remote end closed connection"); | |
d3a492d1 MD |
395 | return 0; |
396 | } | |
7bc53e94 MD |
397 | if (len < 0) |
398 | return len; | |
399 | DBG("incorrect message size: %zd", len); | |
400 | return -EINVAL; | |
d3a492d1 MD |
401 | } |
402 | } | |
403 | ||
404 | static | |
edaa1431 | 405 | int handle_register_done(struct sock_info *sock_info) |
11ff9c7d MD |
406 | { |
407 | int ret; | |
408 | ||
edaa1431 MD |
409 | if (sock_info->constructor_sem_posted) |
410 | return 0; | |
411 | sock_info->constructor_sem_posted = 1; | |
56cd7e2f MD |
412 | if (uatomic_read(&sem_count) <= 0) { |
413 | return 0; | |
414 | } | |
95259bd0 MD |
415 | ret = uatomic_add_return(&sem_count, -1); |
416 | if (ret == 0) { | |
417 | ret = sem_post(&constructor_wait); | |
418 | assert(!ret); | |
419 | } | |
11ff9c7d MD |
420 | return 0; |
421 | } | |
422 | ||
423 | static | |
424 | int handle_message(struct sock_info *sock_info, | |
57773204 | 425 | int sock, struct ustcomm_ust_msg *lum) |
d3a492d1 | 426 | { |
1ea11eab | 427 | int ret = 0; |
b61ce3b2 | 428 | const struct lttng_ust_objd_ops *ops; |
57773204 | 429 | struct ustcomm_ust_reply lur; |
ef9ff354 | 430 | union ust_args args; |
40003310 | 431 | ssize_t len; |
1ea11eab | 432 | |
17dfb34b | 433 | ust_lock(); |
1ea11eab | 434 | |
46050b1a MD |
435 | memset(&lur, 0, sizeof(lur)); |
436 | ||
1ea11eab | 437 | if (lttng_ust_comm_should_quit) { |
74d81a6c | 438 | ret = -LTTNG_UST_ERR_EXITING; |
1ea11eab MD |
439 | goto end; |
440 | } | |
9eb62b9c | 441 | |
46050b1a MD |
442 | ops = objd_ops(lum->handle); |
443 | if (!ops) { | |
444 | ret = -ENOENT; | |
445 | goto end; | |
1ea11eab | 446 | } |
46050b1a MD |
447 | |
448 | switch (lum->cmd) { | |
11ff9c7d MD |
449 | case LTTNG_UST_REGISTER_DONE: |
450 | if (lum->handle == LTTNG_UST_ROOT_HANDLE) | |
edaa1431 | 451 | ret = handle_register_done(sock_info); |
11ff9c7d MD |
452 | else |
453 | ret = -EINVAL; | |
454 | break; | |
46050b1a MD |
455 | case LTTNG_UST_RELEASE: |
456 | if (lum->handle == LTTNG_UST_ROOT_HANDLE) | |
457 | ret = -EPERM; | |
458 | else | |
1849ef7c | 459 | ret = lttng_ust_objd_unref(lum->handle, 1); |
d9e99d10 | 460 | break; |
2d78951a MD |
461 | case LTTNG_UST_FILTER: |
462 | { | |
463 | /* Receive filter data */ | |
f488575f | 464 | struct lttng_ust_filter_bytecode_node *bytecode; |
2d78951a | 465 | |
cd54f6d9 | 466 | if (lum->u.filter.data_size > FILTER_BYTECODE_MAX_LEN) { |
7bc53e94 | 467 | ERR("Filter data size is too large: %u bytes", |
2d78951a MD |
468 | lum->u.filter.data_size); |
469 | ret = -EINVAL; | |
470 | goto error; | |
471 | } | |
2734ca65 | 472 | |
885b1dfd | 473 | if (lum->u.filter.reloc_offset > lum->u.filter.data_size) { |
7bc53e94 | 474 | ERR("Filter reloc offset %u is not within data", |
2734ca65 CB |
475 | lum->u.filter.reloc_offset); |
476 | ret = -EINVAL; | |
477 | goto error; | |
478 | } | |
479 | ||
cd54f6d9 MD |
480 | bytecode = zmalloc(sizeof(*bytecode) + lum->u.filter.data_size); |
481 | if (!bytecode) { | |
482 | ret = -ENOMEM; | |
483 | goto error; | |
484 | } | |
f488575f | 485 | len = ustcomm_recv_unix_sock(sock, bytecode->bc.data, |
2d78951a MD |
486 | lum->u.filter.data_size); |
487 | switch (len) { | |
488 | case 0: /* orderly shutdown */ | |
489 | ret = 0; | |
cd54f6d9 | 490 | free(bytecode); |
2d78951a | 491 | goto error; |
2d78951a MD |
492 | default: |
493 | if (len == lum->u.filter.data_size) { | |
7bc53e94 | 494 | DBG("filter data received"); |
2d78951a | 495 | break; |
7bc53e94 MD |
496 | } else if (len < 0) { |
497 | DBG("Receive failed from lttng-sessiond with errno %d", (int) -len); | |
498 | if (len == -ECONNRESET) { | |
499 | ERR("%s remote end closed connection", sock_info->name); | |
500 | ret = len; | |
501 | free(bytecode); | |
502 | goto error; | |
503 | } | |
504 | ret = len; | |
eb8bf361 | 505 | free(bytecode); |
7bc53e94 | 506 | goto end; |
2d78951a | 507 | } else { |
7bc53e94 | 508 | DBG("incorrect filter data message size: %zd", len); |
2d78951a | 509 | ret = -EINVAL; |
cd54f6d9 | 510 | free(bytecode); |
2d78951a MD |
511 | goto end; |
512 | } | |
513 | } | |
f488575f MD |
514 | bytecode->bc.len = lum->u.filter.data_size; |
515 | bytecode->bc.reloc_offset = lum->u.filter.reloc_offset; | |
3f6fd224 | 516 | bytecode->bc.seqnum = lum->u.filter.seqnum; |
cd54f6d9 | 517 | if (ops->cmd) { |
2d78951a | 518 | ret = ops->cmd(lum->handle, lum->cmd, |
cd54f6d9 | 519 | (unsigned long) bytecode, |
f59ed768 | 520 | &args, sock_info); |
cd54f6d9 MD |
521 | if (ret) { |
522 | free(bytecode); | |
523 | } | |
524 | /* don't free bytecode if everything went fine. */ | |
525 | } else { | |
2d78951a | 526 | ret = -ENOSYS; |
cd54f6d9 MD |
527 | free(bytecode); |
528 | } | |
2d78951a MD |
529 | break; |
530 | } | |
86e36163 JI |
531 | case LTTNG_UST_EXCLUSION: |
532 | { | |
533 | /* Receive exclusion names */ | |
534 | struct lttng_ust_excluder_node *node; | |
535 | unsigned int count; | |
536 | ||
537 | count = lum->u.exclusion.count; | |
538 | if (count == 0) { | |
539 | /* There are no names to read */ | |
540 | ret = 0; | |
541 | goto error; | |
542 | } | |
543 | node = zmalloc(sizeof(*node) + | |
544 | count * LTTNG_UST_SYM_NAME_LEN); | |
545 | if (!node) { | |
546 | ret = -ENOMEM; | |
547 | goto error; | |
548 | } | |
549 | node->excluder.count = count; | |
550 | len = ustcomm_recv_unix_sock(sock, node->excluder.names, | |
551 | count * LTTNG_UST_SYM_NAME_LEN); | |
552 | switch (len) { | |
553 | case 0: /* orderly shutdown */ | |
554 | ret = 0; | |
555 | free(node); | |
556 | goto error; | |
557 | default: | |
558 | if (len == count * LTTNG_UST_SYM_NAME_LEN) { | |
559 | DBG("Exclusion data received"); | |
560 | break; | |
561 | } else if (len < 0) { | |
562 | DBG("Receive failed from lttng-sessiond with errno %d", (int) -len); | |
563 | if (len == -ECONNRESET) { | |
564 | ERR("%s remote end closed connection", sock_info->name); | |
565 | ret = len; | |
566 | free(node); | |
567 | goto error; | |
568 | } | |
569 | ret = len; | |
570 | free(node); | |
571 | goto end; | |
572 | } else { | |
573 | DBG("Incorrect exclusion data message size: %zd", len); | |
574 | ret = -EINVAL; | |
575 | free(node); | |
576 | goto end; | |
577 | } | |
578 | } | |
579 | if (ops->cmd) { | |
580 | ret = ops->cmd(lum->handle, lum->cmd, | |
581 | (unsigned long) node, | |
582 | &args, sock_info); | |
583 | if (ret) { | |
584 | free(node); | |
585 | } | |
586 | /* Don't free exclusion data if everything went fine. */ | |
587 | } else { | |
588 | ret = -ENOSYS; | |
589 | free(node); | |
590 | } | |
591 | break; | |
592 | } | |
74d81a6c MD |
593 | case LTTNG_UST_CHANNEL: |
594 | { | |
595 | void *chan_data; | |
ff0f5728 | 596 | int wakeup_fd; |
74d81a6c MD |
597 | |
598 | len = ustcomm_recv_channel_from_sessiond(sock, | |
ff0f5728 MD |
599 | &chan_data, lum->u.channel.len, |
600 | &wakeup_fd); | |
74d81a6c MD |
601 | switch (len) { |
602 | case 0: /* orderly shutdown */ | |
603 | ret = 0; | |
604 | goto error; | |
605 | default: | |
606 | if (len == lum->u.channel.len) { | |
607 | DBG("channel data received"); | |
608 | break; | |
609 | } else if (len < 0) { | |
610 | DBG("Receive failed from lttng-sessiond with errno %d", (int) -len); | |
611 | if (len == -ECONNRESET) { | |
612 | ERR("%s remote end closed connection", sock_info->name); | |
613 | ret = len; | |
614 | goto error; | |
615 | } | |
616 | ret = len; | |
617 | goto end; | |
618 | } else { | |
619 | DBG("incorrect channel data message size: %zd", len); | |
620 | ret = -EINVAL; | |
621 | goto end; | |
622 | } | |
623 | } | |
624 | args.channel.chan_data = chan_data; | |
ff0f5728 | 625 | args.channel.wakeup_fd = wakeup_fd; |
74d81a6c MD |
626 | if (ops->cmd) |
627 | ret = ops->cmd(lum->handle, lum->cmd, | |
628 | (unsigned long) &lum->u, | |
629 | &args, sock_info); | |
630 | else | |
631 | ret = -ENOSYS; | |
632 | break; | |
633 | } | |
634 | case LTTNG_UST_STREAM: | |
635 | { | |
636 | /* Receive shm_fd, wakeup_fd */ | |
637 | ret = ustcomm_recv_stream_from_sessiond(sock, | |
638 | &lum->u.stream.len, | |
639 | &args.stream.shm_fd, | |
640 | &args.stream.wakeup_fd); | |
641 | if (ret) { | |
642 | goto end; | |
643 | } | |
644 | if (ops->cmd) | |
645 | ret = ops->cmd(lum->handle, lum->cmd, | |
646 | (unsigned long) &lum->u, | |
647 | &args, sock_info); | |
648 | else | |
649 | ret = -ENOSYS; | |
650 | break; | |
651 | } | |
d9e99d10 | 652 | default: |
46050b1a MD |
653 | if (ops->cmd) |
654 | ret = ops->cmd(lum->handle, lum->cmd, | |
ef9ff354 | 655 | (unsigned long) &lum->u, |
f59ed768 | 656 | &args, sock_info); |
46050b1a MD |
657 | else |
658 | ret = -ENOSYS; | |
659 | break; | |
d9e99d10 | 660 | } |
46050b1a | 661 | |
1ea11eab | 662 | end: |
46050b1a MD |
663 | lur.handle = lum->handle; |
664 | lur.cmd = lum->cmd; | |
665 | lur.ret_val = ret; | |
666 | if (ret >= 0) { | |
7bc53e94 | 667 | lur.ret_code = LTTNG_UST_OK; |
46050b1a | 668 | } else { |
7bc53e94 MD |
669 | /* |
670 | * Use -LTTNG_UST_ERR as wildcard for UST internal | |
671 | * error that are not caused by the transport, except if | |
672 | * we already have a more precise error message to | |
673 | * report. | |
674 | */ | |
64b2564e DG |
675 | if (ret > -LTTNG_UST_ERR) { |
676 | /* Translate code to UST error. */ | |
677 | switch (ret) { | |
678 | case -EEXIST: | |
679 | lur.ret_code = -LTTNG_UST_ERR_EXIST; | |
680 | break; | |
681 | case -EINVAL: | |
682 | lur.ret_code = -LTTNG_UST_ERR_INVAL; | |
683 | break; | |
684 | case -ENOENT: | |
685 | lur.ret_code = -LTTNG_UST_ERR_NOENT; | |
686 | break; | |
687 | case -EPERM: | |
688 | lur.ret_code = -LTTNG_UST_ERR_PERM; | |
689 | break; | |
690 | case -ENOSYS: | |
691 | lur.ret_code = -LTTNG_UST_ERR_NOSYS; | |
692 | break; | |
693 | default: | |
694 | lur.ret_code = -LTTNG_UST_ERR; | |
695 | break; | |
696 | } | |
697 | } else { | |
7bc53e94 | 698 | lur.ret_code = ret; |
64b2564e | 699 | } |
46050b1a | 700 | } |
e6ea14c5 MD |
701 | if (ret >= 0) { |
702 | switch (lum->cmd) { | |
e6ea14c5 MD |
703 | case LTTNG_UST_TRACER_VERSION: |
704 | lur.u.version = lum->u.version; | |
705 | break; | |
706 | case LTTNG_UST_TRACEPOINT_LIST_GET: | |
707 | memcpy(&lur.u.tracepoint, &lum->u.tracepoint, sizeof(lur.u.tracepoint)); | |
708 | break; | |
709 | } | |
381c0f1e | 710 | } |
74d81a6c | 711 | DBG("Return value: %d", lur.ret_val); |
46050b1a | 712 | ret = send_reply(sock, &lur); |
193183fb | 713 | if (ret < 0) { |
7bc53e94 | 714 | DBG("error sending reply"); |
193183fb MD |
715 | goto error; |
716 | } | |
46050b1a | 717 | |
40003310 MD |
718 | /* |
719 | * LTTNG_UST_TRACEPOINT_FIELD_LIST_GET needs to send the field | |
720 | * after the reply. | |
721 | */ | |
7bc53e94 | 722 | if (lur.ret_code == LTTNG_UST_OK) { |
40003310 MD |
723 | switch (lum->cmd) { |
724 | case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET: | |
725 | len = ustcomm_send_unix_sock(sock, | |
726 | &args.field_list.entry, | |
727 | sizeof(args.field_list.entry)); | |
7bc53e94 MD |
728 | if (len < 0) { |
729 | ret = len; | |
730 | goto error; | |
731 | } | |
40003310 | 732 | if (len != sizeof(args.field_list.entry)) { |
7bc53e94 | 733 | ret = -EINVAL; |
40003310 MD |
734 | goto error; |
735 | } | |
736 | } | |
737 | } | |
ef9ff354 | 738 | |
381c0f1e | 739 | error: |
17dfb34b | 740 | ust_unlock(); |
1ea11eab | 741 | return ret; |
d9e99d10 MD |
742 | } |
743 | ||
46050b1a | 744 | static |
efe0de09 | 745 | void cleanup_sock_info(struct sock_info *sock_info, int exiting) |
46050b1a MD |
746 | { |
747 | int ret; | |
748 | ||
5b14aab3 MD |
749 | if (sock_info->root_handle != -1) { |
750 | ret = lttng_ust_objd_unref(sock_info->root_handle, 1); | |
751 | if (ret) { | |
752 | ERR("Error unref root handle"); | |
753 | } | |
754 | sock_info->root_handle = -1; | |
755 | } | |
756 | sock_info->constructor_sem_posted = 0; | |
757 | ||
758 | /* | |
759 | * wait_shm_mmap, socket and notify socket are used by listener | |
760 | * threads outside of the ust lock, so we cannot tear them down | |
761 | * ourselves, because we cannot join on these threads. Leave | |
762 | * responsibility of cleaning up these resources to the OS | |
763 | * process exit. | |
764 | */ | |
765 | if (exiting) | |
766 | return; | |
767 | ||
46050b1a | 768 | if (sock_info->socket != -1) { |
e6973a89 | 769 | ret = ustcomm_close_unix_sock(sock_info->socket); |
46050b1a | 770 | if (ret) { |
32ce8569 | 771 | ERR("Error closing ust cmd socket"); |
46050b1a MD |
772 | } |
773 | sock_info->socket = -1; | |
774 | } | |
32ce8569 MD |
775 | if (sock_info->notify_socket != -1) { |
776 | ret = ustcomm_close_unix_sock(sock_info->notify_socket); | |
777 | if (ret) { | |
778 | ERR("Error closing ust notify socket"); | |
779 | } | |
780 | sock_info->notify_socket = -1; | |
781 | } | |
5b14aab3 | 782 | if (sock_info->wait_shm_mmap) { |
7fc90dca MD |
783 | ret = munmap(sock_info->wait_shm_mmap, sysconf(_SC_PAGE_SIZE)); |
784 | if (ret) { | |
785 | ERR("Error unmapping wait shm"); | |
786 | } | |
787 | sock_info->wait_shm_mmap = NULL; | |
788 | } | |
789 | } | |
790 | ||
58d4b2a2 | 791 | /* |
33bbeb90 MD |
792 | * Using fork to set umask in the child process (not multi-thread safe). |
793 | * We deal with the shm_open vs ftruncate race (happening when the | |
794 | * sessiond owns the shm and does not let everybody modify it, to ensure | |
795 | * safety against shm_unlink) by simply letting the mmap fail and | |
796 | * retrying after a few seconds. | |
797 | * For global shm, everybody has rw access to it until the sessiond | |
798 | * starts. | |
58d4b2a2 | 799 | */ |
7fc90dca | 800 | static |
58d4b2a2 | 801 | int get_wait_shm(struct sock_info *sock_info, size_t mmap_size) |
7fc90dca | 802 | { |
7fc90dca | 803 | int wait_shm_fd, ret; |
58d4b2a2 | 804 | pid_t pid; |
44e073f5 | 805 | |
58d4b2a2 | 806 | /* |
33bbeb90 | 807 | * Try to open read-only. |
58d4b2a2 | 808 | */ |
33bbeb90 | 809 | wait_shm_fd = shm_open(sock_info->wait_shm_path, O_RDONLY, 0); |
58d4b2a2 | 810 | if (wait_shm_fd >= 0) { |
7aa76730 MD |
811 | int32_t tmp_read; |
812 | ssize_t len; | |
813 | size_t bytes_read = 0; | |
814 | ||
815 | /* | |
816 | * Try to read the fd. If unable to do so, try opening | |
817 | * it in write mode. | |
818 | */ | |
819 | do { | |
820 | len = read(wait_shm_fd, | |
821 | &((char *) &tmp_read)[bytes_read], | |
822 | sizeof(tmp_read) - bytes_read); | |
823 | if (len > 0) { | |
824 | bytes_read += len; | |
825 | } | |
826 | } while ((len < 0 && errno == EINTR) | |
827 | || (len > 0 && bytes_read < sizeof(tmp_read))); | |
828 | if (bytes_read != sizeof(tmp_read)) { | |
829 | ret = close(wait_shm_fd); | |
830 | if (ret) { | |
831 | ERR("close wait_shm_fd"); | |
832 | } | |
833 | goto open_write; | |
834 | } | |
58d4b2a2 MD |
835 | goto end; |
836 | } else if (wait_shm_fd < 0 && errno != ENOENT) { | |
837 | /* | |
33bbeb90 MD |
838 | * Real-only open did not work, and it's not because the |
839 | * entry was not present. It's a failure that prohibits | |
840 | * using shm. | |
58d4b2a2 | 841 | */ |
7fc90dca | 842 | ERR("Error opening shm %s", sock_info->wait_shm_path); |
58d4b2a2 | 843 | goto end; |
7fc90dca | 844 | } |
7aa76730 MD |
845 | |
846 | open_write: | |
7fc90dca | 847 | /* |
7aa76730 MD |
848 | * If the open failed because the file did not exist, or because |
849 | * the file was not truncated yet, try creating it ourself. | |
7fc90dca | 850 | */ |
8c90a710 | 851 | URCU_TLS(lttng_ust_nest_count)++; |
58d4b2a2 | 852 | pid = fork(); |
8c90a710 | 853 | URCU_TLS(lttng_ust_nest_count)--; |
58d4b2a2 MD |
854 | if (pid > 0) { |
855 | int status; | |
856 | ||
857 | /* | |
858 | * Parent: wait for child to return, in which case the | |
859 | * shared memory map will have been created. | |
860 | */ | |
861 | pid = wait(&status); | |
b7d3cb32 | 862 | if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
58d4b2a2 MD |
863 | wait_shm_fd = -1; |
864 | goto end; | |
7fc90dca | 865 | } |
58d4b2a2 MD |
866 | /* |
867 | * Try to open read-only again after creation. | |
868 | */ | |
33bbeb90 | 869 | wait_shm_fd = shm_open(sock_info->wait_shm_path, O_RDONLY, 0); |
58d4b2a2 MD |
870 | if (wait_shm_fd < 0) { |
871 | /* | |
872 | * Real-only open did not work. It's a failure | |
873 | * that prohibits using shm. | |
874 | */ | |
875 | ERR("Error opening shm %s", sock_info->wait_shm_path); | |
876 | goto end; | |
877 | } | |
878 | goto end; | |
879 | } else if (pid == 0) { | |
880 | int create_mode; | |
881 | ||
882 | /* Child */ | |
33bbeb90 | 883 | create_mode = S_IRUSR | S_IWUSR | S_IRGRP; |
58d4b2a2 | 884 | if (sock_info->global) |
33bbeb90 | 885 | create_mode |= S_IROTH | S_IWGRP | S_IWOTH; |
58d4b2a2 MD |
886 | /* |
887 | * We're alone in a child process, so we can modify the | |
888 | * process-wide umask. | |
889 | */ | |
33bbeb90 | 890 | umask(~create_mode); |
58d4b2a2 | 891 | /* |
33bbeb90 MD |
892 | * Try creating shm (or get rw access). |
893 | * We don't do an exclusive open, because we allow other | |
894 | * processes to create+ftruncate it concurrently. | |
58d4b2a2 MD |
895 | */ |
896 | wait_shm_fd = shm_open(sock_info->wait_shm_path, | |
897 | O_RDWR | O_CREAT, create_mode); | |
898 | if (wait_shm_fd >= 0) { | |
899 | ret = ftruncate(wait_shm_fd, mmap_size); | |
900 | if (ret) { | |
901 | PERROR("ftruncate"); | |
b0c1425d | 902 | _exit(EXIT_FAILURE); |
58d4b2a2 | 903 | } |
b0c1425d | 904 | _exit(EXIT_SUCCESS); |
58d4b2a2 | 905 | } |
33bbeb90 MD |
906 | /* |
907 | * For local shm, we need to have rw access to accept | |
908 | * opening it: this means the local sessiond will be | |
909 | * able to wake us up. For global shm, we open it even | |
910 | * if rw access is not granted, because the root.root | |
911 | * sessiond will be able to override all rights and wake | |
912 | * us up. | |
913 | */ | |
914 | if (!sock_info->global && errno != EACCES) { | |
58d4b2a2 | 915 | ERR("Error opening shm %s", sock_info->wait_shm_path); |
5d3bc5ed | 916 | _exit(EXIT_FAILURE); |
58d4b2a2 MD |
917 | } |
918 | /* | |
33bbeb90 MD |
919 | * The shm exists, but we cannot open it RW. Report |
920 | * success. | |
58d4b2a2 | 921 | */ |
5d3bc5ed | 922 | _exit(EXIT_SUCCESS); |
58d4b2a2 MD |
923 | } else { |
924 | return -1; | |
7fc90dca | 925 | } |
58d4b2a2 | 926 | end: |
33bbeb90 MD |
927 | if (wait_shm_fd >= 0 && !sock_info->global) { |
928 | struct stat statbuf; | |
929 | ||
930 | /* | |
931 | * Ensure that our user is the owner of the shm file for | |
932 | * local shm. If we do not own the file, it means our | |
933 | * sessiond will not have access to wake us up (there is | |
934 | * probably a rogue process trying to fake our | |
935 | * sessiond). Fallback to polling method in this case. | |
936 | */ | |
937 | ret = fstat(wait_shm_fd, &statbuf); | |
938 | if (ret) { | |
939 | PERROR("fstat"); | |
940 | goto error_close; | |
941 | } | |
942 | if (statbuf.st_uid != getuid()) | |
943 | goto error_close; | |
944 | } | |
58d4b2a2 | 945 | return wait_shm_fd; |
33bbeb90 MD |
946 | |
947 | error_close: | |
948 | ret = close(wait_shm_fd); | |
949 | if (ret) { | |
950 | PERROR("Error closing fd"); | |
951 | } | |
952 | return -1; | |
58d4b2a2 MD |
953 | } |
954 | ||
955 | static | |
956 | char *get_map_shm(struct sock_info *sock_info) | |
957 | { | |
958 | size_t mmap_size = sysconf(_SC_PAGE_SIZE); | |
959 | int wait_shm_fd, ret; | |
960 | char *wait_shm_mmap; | |
961 | ||
962 | wait_shm_fd = get_wait_shm(sock_info, mmap_size); | |
963 | if (wait_shm_fd < 0) { | |
964 | goto error; | |
44e073f5 | 965 | } |
7fc90dca MD |
966 | wait_shm_mmap = mmap(NULL, mmap_size, PROT_READ, |
967 | MAP_SHARED, wait_shm_fd, 0); | |
7fc90dca MD |
968 | /* close shm fd immediately after taking the mmap reference */ |
969 | ret = close(wait_shm_fd); | |
970 | if (ret) { | |
33bbeb90 MD |
971 | PERROR("Error closing fd"); |
972 | } | |
973 | if (wait_shm_mmap == MAP_FAILED) { | |
974 | DBG("mmap error (can be caused by race with sessiond). Fallback to poll mode."); | |
975 | goto error; | |
7fc90dca MD |
976 | } |
977 | return wait_shm_mmap; | |
978 | ||
979 | error: | |
980 | return NULL; | |
981 | } | |
982 | ||
983 | static | |
984 | void wait_for_sessiond(struct sock_info *sock_info) | |
985 | { | |
efe0de09 | 986 | int ret; |
80e2814b | 987 | |
7fc90dca MD |
988 | ust_lock(); |
989 | if (lttng_ust_comm_should_quit) { | |
990 | goto quit; | |
991 | } | |
37ed587a MD |
992 | if (wait_poll_fallback) { |
993 | goto error; | |
994 | } | |
7fc90dca MD |
995 | if (!sock_info->wait_shm_mmap) { |
996 | sock_info->wait_shm_mmap = get_map_shm(sock_info); | |
997 | if (!sock_info->wait_shm_mmap) | |
998 | goto error; | |
999 | } | |
1000 | ust_unlock(); | |
1001 | ||
1002 | DBG("Waiting for %s apps sessiond", sock_info->name); | |
80e2814b MD |
1003 | /* Wait for futex wakeup */ |
1004 | if (uatomic_read((int32_t *) sock_info->wait_shm_mmap) == 0) { | |
1005 | ret = futex_async((int32_t *) sock_info->wait_shm_mmap, | |
1006 | FUTEX_WAIT, 0, NULL, NULL, 0); | |
80e2814b | 1007 | if (ret < 0) { |
37ed587a MD |
1008 | if (errno == EFAULT) { |
1009 | wait_poll_fallback = 1; | |
a8b870ad | 1010 | DBG( |
37ed587a MD |
1011 | "Linux kernels 2.6.33 to 3.0 (with the exception of stable versions) " |
1012 | "do not support FUTEX_WAKE on read-only memory mappings correctly. " | |
1013 | "Please upgrade your kernel " | |
1014 | "(fix is commit 9ea71503a8ed9184d2d0b8ccc4d269d05f7940ae in Linux kernel " | |
1015 | "mainline). LTTng-UST will use polling mode fallback."); | |
cd27263b MD |
1016 | if (ust_debug()) |
1017 | PERROR("futex"); | |
37ed587a | 1018 | } |
80e2814b MD |
1019 | } |
1020 | } | |
7fc90dca MD |
1021 | return; |
1022 | ||
1023 | quit: | |
1024 | ust_unlock(); | |
1025 | return; | |
1026 | ||
1027 | error: | |
1028 | ust_unlock(); | |
7fc90dca | 1029 | return; |
46050b1a MD |
1030 | } |
1031 | ||
1ea11eab MD |
1032 | /* |
1033 | * This thread does not allocate any resource, except within | |
1034 | * handle_message, within mutex protection. This mutex protects against | |
1035 | * fork and exit. | |
98bf993f | 1036 | * The other moment it allocates resources is at socket connection, which |
1ea11eab MD |
1037 | * is also protected by the mutex. |
1038 | */ | |
d9e99d10 MD |
1039 | static |
1040 | void *ust_listener_thread(void *arg) | |
1041 | { | |
1ea11eab | 1042 | struct sock_info *sock_info = arg; |
c0eedf81 | 1043 | int sock, ret, prev_connect_failed = 0, has_waited = 0; |
ff517991 | 1044 | long timeout; |
d9e99d10 | 1045 | |
9eb62b9c MD |
1046 | /* Restart trying to connect to the session daemon */ |
1047 | restart: | |
c0eedf81 MD |
1048 | if (prev_connect_failed) { |
1049 | /* Wait for sessiond availability with pipe */ | |
1050 | wait_for_sessiond(sock_info); | |
1051 | if (has_waited) { | |
1052 | has_waited = 0; | |
1053 | /* | |
1054 | * Sleep for 5 seconds before retrying after a | |
1055 | * sequence of failure / wait / failure. This | |
1056 | * deals with a killed or broken session daemon. | |
1057 | */ | |
1058 | sleep(5); | |
1059 | } | |
1060 | has_waited = 1; | |
1061 | prev_connect_failed = 0; | |
1062 | } | |
9eb62b9c | 1063 | |
1ea11eab | 1064 | if (sock_info->socket != -1) { |
e6973a89 | 1065 | ret = ustcomm_close_unix_sock(sock_info->socket); |
1ea11eab | 1066 | if (ret) { |
32ce8569 MD |
1067 | ERR("Error closing %s ust cmd socket", |
1068 | sock_info->name); | |
1ea11eab MD |
1069 | } |
1070 | sock_info->socket = -1; | |
1071 | } | |
32ce8569 MD |
1072 | if (sock_info->notify_socket != -1) { |
1073 | ret = ustcomm_close_unix_sock(sock_info->notify_socket); | |
1074 | if (ret) { | |
1075 | ERR("Error closing %s ust notify socket", | |
1076 | sock_info->name); | |
1077 | } | |
1078 | sock_info->notify_socket = -1; | |
1079 | } | |
46050b1a | 1080 | |
321f2351 MD |
1081 | /* |
1082 | * Register. We need to perform both connect and sending | |
1083 | * registration message before doing the next connect otherwise | |
1084 | * we may reach unix socket connect queue max limits and block | |
1085 | * on the 2nd connect while the session daemon is awaiting the | |
1086 | * first connect registration message. | |
1087 | */ | |
1088 | /* Connect cmd socket */ | |
1089 | ret = ustcomm_connect_unix_sock(sock_info->sock_path); | |
1090 | if (ret < 0) { | |
1091 | DBG("Info: sessiond not accepting connections to %s apps socket", sock_info->name); | |
1092 | prev_connect_failed = 1; | |
5b14aab3 | 1093 | |
321f2351 | 1094 | ust_lock(); |
5b14aab3 | 1095 | |
321f2351 MD |
1096 | if (lttng_ust_comm_should_quit) { |
1097 | goto quit; | |
32ce8569 | 1098 | } |
46050b1a | 1099 | |
e3426ddc | 1100 | /* |
321f2351 MD |
1101 | * If we cannot find the sessiond daemon, don't delay |
1102 | * constructor execution. | |
e3426ddc | 1103 | */ |
321f2351 MD |
1104 | ret = handle_register_done(sock_info); |
1105 | assert(!ret); | |
1106 | ust_unlock(); | |
1107 | goto restart; | |
27fe9f21 | 1108 | } |
321f2351 | 1109 | sock_info->socket = ret; |
27fe9f21 | 1110 | |
5b14aab3 MD |
1111 | ust_lock(); |
1112 | ||
1113 | if (lttng_ust_comm_should_quit) { | |
1114 | goto quit; | |
1115 | } | |
1116 | ||
46050b1a MD |
1117 | /* |
1118 | * Create only one root handle per listener thread for the whole | |
f59ed768 MD |
1119 | * process lifetime, so we ensure we get ID which is statically |
1120 | * assigned to the root handle. | |
46050b1a MD |
1121 | */ |
1122 | if (sock_info->root_handle == -1) { | |
1123 | ret = lttng_abi_create_root_handle(); | |
a51070bb | 1124 | if (ret < 0) { |
46050b1a | 1125 | ERR("Error creating root handle"); |
46050b1a MD |
1126 | goto quit; |
1127 | } | |
1128 | sock_info->root_handle = ret; | |
9eb62b9c | 1129 | } |
1ea11eab | 1130 | |
32ce8569 | 1131 | ret = register_to_sessiond(sock_info->socket, USTCTL_SOCKET_CMD); |
9eb62b9c | 1132 | if (ret < 0) { |
32ce8569 MD |
1133 | ERR("Error registering to %s ust cmd socket", |
1134 | sock_info->name); | |
c0eedf81 | 1135 | prev_connect_failed = 1; |
11ff9c7d MD |
1136 | /* |
1137 | * If we cannot register to the sessiond daemon, don't | |
1138 | * delay constructor execution. | |
1139 | */ | |
edaa1431 | 1140 | ret = handle_register_done(sock_info); |
11ff9c7d | 1141 | assert(!ret); |
17dfb34b | 1142 | ust_unlock(); |
9eb62b9c MD |
1143 | goto restart; |
1144 | } | |
321f2351 MD |
1145 | |
1146 | ust_unlock(); | |
1147 | ||
1148 | /* Connect notify socket */ | |
1149 | ret = ustcomm_connect_unix_sock(sock_info->sock_path); | |
1150 | if (ret < 0) { | |
1151 | DBG("Info: sessiond not accepting connections to %s apps socket", sock_info->name); | |
1152 | prev_connect_failed = 1; | |
1153 | ||
1154 | ust_lock(); | |
1155 | ||
1156 | if (lttng_ust_comm_should_quit) { | |
1157 | goto quit; | |
1158 | } | |
1159 | ||
1160 | /* | |
1161 | * If we cannot find the sessiond daemon, don't delay | |
1162 | * constructor execution. | |
1163 | */ | |
1164 | ret = handle_register_done(sock_info); | |
1165 | assert(!ret); | |
1166 | ust_unlock(); | |
1167 | goto restart; | |
1168 | } | |
1169 | sock_info->notify_socket = ret; | |
1170 | ||
1171 | timeout = get_notify_sock_timeout(); | |
1172 | if (timeout >= 0) { | |
1173 | /* | |
1174 | * Give at least 10ms to sessiond to reply to | |
1175 | * notifications. | |
1176 | */ | |
1177 | if (timeout < 10) | |
1178 | timeout = 10; | |
1179 | ret = ustcomm_setsockopt_rcv_timeout(sock_info->notify_socket, | |
1180 | timeout); | |
1181 | if (ret < 0) { | |
1182 | WARN("Error setting socket receive timeout"); | |
1183 | } | |
1184 | ret = ustcomm_setsockopt_snd_timeout(sock_info->notify_socket, | |
1185 | timeout); | |
1186 | if (ret < 0) { | |
1187 | WARN("Error setting socket send timeout"); | |
1188 | } | |
1189 | } else if (timeout < -1) { | |
1190 | WARN("Unsupported timeout value %ld", timeout); | |
1191 | } | |
1192 | ||
1193 | ust_lock(); | |
1194 | ||
1195 | if (lttng_ust_comm_should_quit) { | |
1196 | goto quit; | |
1197 | } | |
1198 | ||
32ce8569 MD |
1199 | ret = register_to_sessiond(sock_info->notify_socket, |
1200 | USTCTL_SOCKET_NOTIFY); | |
1201 | if (ret < 0) { | |
1202 | ERR("Error registering to %s ust notify socket", | |
1203 | sock_info->name); | |
1204 | prev_connect_failed = 1; | |
1205 | /* | |
1206 | * If we cannot register to the sessiond daemon, don't | |
1207 | * delay constructor execution. | |
1208 | */ | |
1209 | ret = handle_register_done(sock_info); | |
1210 | assert(!ret); | |
1211 | ust_unlock(); | |
1212 | goto restart; | |
1213 | } | |
1214 | sock = sock_info->socket; | |
1215 | ||
17dfb34b | 1216 | ust_unlock(); |
46050b1a | 1217 | |
d9e99d10 MD |
1218 | for (;;) { |
1219 | ssize_t len; | |
57773204 | 1220 | struct ustcomm_ust_msg lum; |
d9e99d10 | 1221 | |
57773204 | 1222 | len = ustcomm_recv_unix_sock(sock, &lum, sizeof(lum)); |
d9e99d10 MD |
1223 | switch (len) { |
1224 | case 0: /* orderly shutdown */ | |
7dd08bec | 1225 | DBG("%s lttng-sessiond has performed an orderly shutdown", sock_info->name); |
8236ba10 | 1226 | ust_lock(); |
d5e1fea6 | 1227 | if (lttng_ust_comm_should_quit) { |
d5e1fea6 MD |
1228 | goto quit; |
1229 | } | |
8236ba10 MD |
1230 | /* |
1231 | * Either sessiond has shutdown or refused us by closing the socket. | |
1232 | * In either case, we don't want to delay construction execution, | |
1233 | * and we need to wait before retry. | |
1234 | */ | |
1235 | prev_connect_failed = 1; | |
1236 | /* | |
1237 | * If we cannot register to the sessiond daemon, don't | |
1238 | * delay constructor execution. | |
1239 | */ | |
1240 | ret = handle_register_done(sock_info); | |
1241 | assert(!ret); | |
1242 | ust_unlock(); | |
d9e99d10 | 1243 | goto end; |
e7723462 | 1244 | case sizeof(lum): |
74d81a6c | 1245 | print_cmd(lum.cmd, lum.handle); |
11ff9c7d | 1246 | ret = handle_message(sock_info, sock, &lum); |
7bc53e94 | 1247 | if (ret) { |
11ff9c7d | 1248 | ERR("Error handling message for %s socket", sock_info->name); |
95c25348 PW |
1249 | } else { |
1250 | struct lttng_session *session = | |
1251 | sock_info->session_enabled; | |
1252 | if (session) { | |
1253 | sock_info->session_enabled = NULL; | |
1254 | lttng_ust_baddr_statedump(session); | |
1255 | } | |
d9e99d10 MD |
1256 | } |
1257 | continue; | |
7bc53e94 MD |
1258 | default: |
1259 | if (len < 0) { | |
1260 | DBG("Receive failed from lttng-sessiond with errno %d", (int) -len); | |
1261 | } else { | |
1262 | DBG("incorrect message size (%s socket): %zd", sock_info->name, len); | |
1263 | } | |
1264 | if (len == -ECONNRESET) { | |
1265 | DBG("%s remote end closed connection", sock_info->name); | |
d9e99d10 MD |
1266 | goto end; |
1267 | } | |
1268 | goto end; | |
d9e99d10 MD |
1269 | } |
1270 | ||
1271 | } | |
1272 | end: | |
f59ed768 | 1273 | ust_lock(); |
d5e1fea6 | 1274 | if (lttng_ust_comm_should_quit) { |
d5e1fea6 MD |
1275 | goto quit; |
1276 | } | |
f59ed768 MD |
1277 | /* Cleanup socket handles before trying to reconnect */ |
1278 | lttng_ust_objd_table_owner_cleanup(sock_info); | |
1279 | ust_unlock(); | |
9eb62b9c | 1280 | goto restart; /* try to reconnect */ |
e33f3265 | 1281 | |
1ea11eab | 1282 | quit: |
e33f3265 MD |
1283 | sock_info->thread_active = 0; |
1284 | ust_unlock(); | |
d9e99d10 MD |
1285 | return NULL; |
1286 | } | |
1287 | ||
2691221a MD |
1288 | /* |
1289 | * sessiond monitoring thread: monitor presence of global and per-user | |
1290 | * sessiond by polling the application common named pipe. | |
1291 | */ | |
edaa1431 | 1292 | void __attribute__((constructor)) lttng_ust_init(void) |
2691221a | 1293 | { |
11ff9c7d | 1294 | struct timespec constructor_timeout; |
ae6a58bf | 1295 | sigset_t sig_all_blocked, orig_parent_mask; |
1879f67f | 1296 | pthread_attr_t thread_attr; |
cf12a773 | 1297 | int timeout_mode; |
2691221a MD |
1298 | int ret; |
1299 | ||
edaa1431 MD |
1300 | if (uatomic_xchg(&initialized, 1) == 1) |
1301 | return; | |
1302 | ||
eddd8d5d MD |
1303 | /* |
1304 | * Fixup interdependency between TLS fixup mutex (which happens | |
1305 | * to be the dynamic linker mutex) and ust_lock, taken within | |
1306 | * the ust lock. | |
1307 | */ | |
f645cfa7 | 1308 | lttng_fixup_ringbuffer_tls(); |
4158a15a | 1309 | lttng_fixup_vtid_tls(); |
a903623f | 1310 | lttng_fixup_nest_count_tls(); |
009745db | 1311 | lttng_fixup_procname_tls(); |
eddd8d5d | 1312 | |
edaa1431 MD |
1313 | /* |
1314 | * We want precise control over the order in which we construct | |
1315 | * our sub-libraries vs starting to receive commands from | |
1316 | * sessiond (otherwise leading to errors when trying to create | |
1317 | * sessiond before the init functions are completed). | |
1318 | */ | |
2691221a | 1319 | init_usterr(); |
edaa1431 | 1320 | init_tracepoint(); |
7dd08bec MD |
1321 | lttng_ring_buffer_metadata_client_init(); |
1322 | lttng_ring_buffer_client_overwrite_init(); | |
34a91bdb | 1323 | lttng_ring_buffer_client_overwrite_rt_init(); |
7dd08bec | 1324 | lttng_ring_buffer_client_discard_init(); |
34a91bdb | 1325 | lttng_ring_buffer_client_discard_rt_init(); |
a0a3bef9 | 1326 | lttng_context_init(); |
2691221a | 1327 | |
ff517991 | 1328 | timeout_mode = get_constructor_timeout(&constructor_timeout); |
11ff9c7d | 1329 | |
95259bd0 | 1330 | ret = sem_init(&constructor_wait, 0, 0); |
11ff9c7d MD |
1331 | assert(!ret); |
1332 | ||
8d20bf54 | 1333 | ret = setup_local_apps(); |
2691221a | 1334 | if (ret) { |
9ec6895c | 1335 | DBG("local apps setup returned %d", ret); |
2691221a | 1336 | } |
ae6a58bf WP |
1337 | |
1338 | /* A new thread created by pthread_create inherits the signal mask | |
1339 | * from the parent. To avoid any signal being received by the | |
1340 | * listener thread, we block all signals temporarily in the parent, | |
1341 | * while we create the listener thread. | |
1342 | */ | |
1343 | sigfillset(&sig_all_blocked); | |
1344 | ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_parent_mask); | |
1345 | if (ret) { | |
d94d802c | 1346 | ERR("pthread_sigmask: %s", strerror(ret)); |
ae6a58bf WP |
1347 | } |
1348 | ||
1879f67f MG |
1349 | ret = pthread_attr_init(&thread_attr); |
1350 | if (ret) { | |
1351 | ERR("pthread_attr_init: %s", strerror(ret)); | |
1352 | } | |
1353 | ret = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); | |
1354 | if (ret) { | |
1355 | ERR("pthread_attr_setdetachstate: %s", strerror(ret)); | |
1356 | } | |
1357 | ||
e33f3265 | 1358 | ust_lock(); |
1879f67f | 1359 | ret = pthread_create(&global_apps.ust_listener, &thread_attr, |
dde70ea0 | 1360 | ust_listener_thread, &global_apps); |
d94d802c MD |
1361 | if (ret) { |
1362 | ERR("pthread_create global: %s", strerror(ret)); | |
1363 | } | |
e33f3265 MD |
1364 | global_apps.thread_active = 1; |
1365 | ust_unlock(); | |
1366 | ||
8d20bf54 | 1367 | if (local_apps.allowed) { |
e33f3265 | 1368 | ust_lock(); |
1879f67f | 1369 | ret = pthread_create(&local_apps.ust_listener, &thread_attr, |
dde70ea0 | 1370 | ust_listener_thread, &local_apps); |
d94d802c MD |
1371 | if (ret) { |
1372 | ERR("pthread_create local: %s", strerror(ret)); | |
1373 | } | |
e33f3265 MD |
1374 | local_apps.thread_active = 1; |
1375 | ust_unlock(); | |
8d20bf54 MD |
1376 | } else { |
1377 | handle_register_done(&local_apps); | |
1378 | } | |
1879f67f MG |
1379 | ret = pthread_attr_destroy(&thread_attr); |
1380 | if (ret) { | |
1381 | ERR("pthread_attr_destroy: %s", strerror(ret)); | |
1382 | } | |
8d20bf54 | 1383 | |
ae6a58bf WP |
1384 | /* Restore original signal mask in parent */ |
1385 | ret = pthread_sigmask(SIG_SETMASK, &orig_parent_mask, NULL); | |
1386 | if (ret) { | |
d94d802c | 1387 | ERR("pthread_sigmask: %s", strerror(ret)); |
ae6a58bf WP |
1388 | } |
1389 | ||
cf12a773 MD |
1390 | switch (timeout_mode) { |
1391 | case 1: /* timeout wait */ | |
95259bd0 MD |
1392 | do { |
1393 | ret = sem_timedwait(&constructor_wait, | |
1394 | &constructor_timeout); | |
1395 | } while (ret < 0 && errno == EINTR); | |
cf12a773 | 1396 | if (ret < 0 && errno == ETIMEDOUT) { |
7dd08bec | 1397 | ERR("Timed out waiting for lttng-sessiond"); |
cf12a773 MD |
1398 | } else { |
1399 | assert(!ret); | |
1400 | } | |
1401 | break; | |
7b766b16 | 1402 | case -1:/* wait forever */ |
95259bd0 MD |
1403 | do { |
1404 | ret = sem_wait(&constructor_wait); | |
1405 | } while (ret < 0 && errno == EINTR); | |
11ff9c7d | 1406 | assert(!ret); |
cf12a773 | 1407 | break; |
7b766b16 | 1408 | case 0: /* no timeout */ |
cf12a773 | 1409 | break; |
11ff9c7d | 1410 | } |
2691221a MD |
1411 | } |
1412 | ||
17dfb34b MD |
1413 | static |
1414 | void lttng_ust_cleanup(int exiting) | |
1415 | { | |
efe0de09 | 1416 | cleanup_sock_info(&global_apps, exiting); |
17dfb34b | 1417 | if (local_apps.allowed) { |
efe0de09 | 1418 | cleanup_sock_info(&local_apps, exiting); |
17dfb34b | 1419 | } |
efe0de09 MD |
1420 | /* |
1421 | * The teardown in this function all affect data structures | |
1422 | * accessed under the UST lock by the listener thread. This | |
1423 | * lock, along with the lttng_ust_comm_should_quit flag, ensure | |
1424 | * that none of these threads are accessing this data at this | |
1425 | * point. | |
1426 | */ | |
17dfb34b | 1427 | lttng_ust_abi_exit(); |
003fedf4 | 1428 | lttng_ust_events_exit(); |
a0a3bef9 | 1429 | lttng_context_exit(); |
34a91bdb | 1430 | lttng_ring_buffer_client_discard_rt_exit(); |
7dd08bec | 1431 | lttng_ring_buffer_client_discard_exit(); |
34a91bdb | 1432 | lttng_ring_buffer_client_overwrite_rt_exit(); |
7dd08bec MD |
1433 | lttng_ring_buffer_client_overwrite_exit(); |
1434 | lttng_ring_buffer_metadata_client_exit(); | |
17dfb34b MD |
1435 | exit_tracepoint(); |
1436 | if (!exiting) { | |
1437 | /* Reinitialize values for fork */ | |
1438 | sem_count = 2; | |
1439 | lttng_ust_comm_should_quit = 0; | |
1440 | initialized = 0; | |
1441 | } | |
1442 | } | |
1443 | ||
edaa1431 | 1444 | void __attribute__((destructor)) lttng_ust_exit(void) |
2691221a MD |
1445 | { |
1446 | int ret; | |
1447 | ||
9eb62b9c MD |
1448 | /* |
1449 | * Using pthread_cancel here because: | |
1450 | * A) we don't want to hang application teardown. | |
1451 | * B) the thread is not allocating any resource. | |
1452 | */ | |
1ea11eab MD |
1453 | |
1454 | /* | |
1455 | * Require the communication thread to quit. Synchronize with | |
1456 | * mutexes to ensure it is not in a mutex critical section when | |
1457 | * pthread_cancel is later called. | |
1458 | */ | |
17dfb34b | 1459 | ust_lock(); |
1ea11eab | 1460 | lttng_ust_comm_should_quit = 1; |
1ea11eab | 1461 | |
f5f94532 | 1462 | /* cancel threads */ |
e33f3265 MD |
1463 | if (global_apps.thread_active) { |
1464 | ret = pthread_cancel(global_apps.ust_listener); | |
1465 | if (ret) { | |
1466 | ERR("Error cancelling global ust listener thread: %s", | |
1467 | strerror(ret)); | |
1468 | } else { | |
1469 | global_apps.thread_active = 0; | |
1470 | } | |
2691221a | 1471 | } |
e33f3265 | 1472 | if (local_apps.thread_active) { |
8d20bf54 MD |
1473 | ret = pthread_cancel(local_apps.ust_listener); |
1474 | if (ret) { | |
d94d802c MD |
1475 | ERR("Error cancelling local ust listener thread: %s", |
1476 | strerror(ret)); | |
e33f3265 MD |
1477 | } else { |
1478 | local_apps.thread_active = 0; | |
8d20bf54 | 1479 | } |
8d20bf54 | 1480 | } |
e33f3265 MD |
1481 | ust_unlock(); |
1482 | ||
efe0de09 MD |
1483 | /* |
1484 | * Do NOT join threads: use of sys_futex makes it impossible to | |
1485 | * join the threads without using async-cancel, but async-cancel | |
1486 | * is delivered by a signal, which could hit the target thread | |
1487 | * anywhere in its code path, including while the ust_lock() is | |
1488 | * held, causing a deadlock for the other thread. Let the OS | |
1489 | * cleanup the threads if there are stalled in a syscall. | |
1490 | */ | |
17dfb34b | 1491 | lttng_ust_cleanup(1); |
95c25348 PW |
1492 | |
1493 | if (ust_baddr_handle) { | |
1494 | int ret = dlclose(ust_baddr_handle); | |
1495 | if (ret) | |
1496 | ERR("%s", dlerror()); | |
1497 | } | |
2691221a | 1498 | } |
e822f505 MD |
1499 | |
1500 | /* | |
1501 | * We exclude the worker threads across fork and clone (except | |
1502 | * CLONE_VM), because these system calls only keep the forking thread | |
1503 | * running in the child. Therefore, we don't want to call fork or clone | |
1504 | * in the middle of an tracepoint or ust tracing state modification. | |
1505 | * Holding this mutex protects these structures across fork and clone. | |
1506 | */ | |
b728d87e | 1507 | void ust_before_fork(sigset_t *save_sigset) |
e822f505 MD |
1508 | { |
1509 | /* | |
1510 | * Disable signals. This is to avoid that the child intervenes | |
1511 | * before it is properly setup for tracing. It is safer to | |
1512 | * disable all signals, because then we know we are not breaking | |
1513 | * anything by restoring the original mask. | |
1514 | */ | |
1515 | sigset_t all_sigs; | |
1516 | int ret; | |
1517 | ||
8c90a710 | 1518 | if (URCU_TLS(lttng_ust_nest_count)) |
e8508a49 | 1519 | return; |
e822f505 MD |
1520 | /* Disable signals */ |
1521 | sigfillset(&all_sigs); | |
b728d87e | 1522 | ret = sigprocmask(SIG_BLOCK, &all_sigs, save_sigset); |
e822f505 MD |
1523 | if (ret == -1) { |
1524 | PERROR("sigprocmask"); | |
1525 | } | |
17dfb34b | 1526 | ust_lock(); |
e822f505 MD |
1527 | rcu_bp_before_fork(); |
1528 | } | |
1529 | ||
b728d87e | 1530 | static void ust_after_fork_common(sigset_t *restore_sigset) |
e822f505 MD |
1531 | { |
1532 | int ret; | |
1533 | ||
17dfb34b MD |
1534 | DBG("process %d", getpid()); |
1535 | ust_unlock(); | |
e822f505 | 1536 | /* Restore signals */ |
23c8854a | 1537 | ret = sigprocmask(SIG_SETMASK, restore_sigset, NULL); |
e822f505 MD |
1538 | if (ret == -1) { |
1539 | PERROR("sigprocmask"); | |
1540 | } | |
1541 | } | |
1542 | ||
b728d87e | 1543 | void ust_after_fork_parent(sigset_t *restore_sigset) |
e822f505 | 1544 | { |
8c90a710 | 1545 | if (URCU_TLS(lttng_ust_nest_count)) |
e8508a49 | 1546 | return; |
17dfb34b | 1547 | DBG("process %d", getpid()); |
e822f505 MD |
1548 | rcu_bp_after_fork_parent(); |
1549 | /* Release mutexes and reenable signals */ | |
b728d87e | 1550 | ust_after_fork_common(restore_sigset); |
e822f505 MD |
1551 | } |
1552 | ||
17dfb34b MD |
1553 | /* |
1554 | * After fork, in the child, we need to cleanup all the leftover state, | |
1555 | * except the worker thread which already magically disappeared thanks | |
1556 | * to the weird Linux fork semantics. After tyding up, we call | |
1557 | * lttng_ust_init() again to start over as a new PID. | |
1558 | * | |
1559 | * This is meant for forks() that have tracing in the child between the | |
1560 | * fork and following exec call (if there is any). | |
1561 | */ | |
b728d87e | 1562 | void ust_after_fork_child(sigset_t *restore_sigset) |
e822f505 | 1563 | { |
8c90a710 | 1564 | if (URCU_TLS(lttng_ust_nest_count)) |
e8508a49 | 1565 | return; |
17dfb34b | 1566 | DBG("process %d", getpid()); |
e822f505 MD |
1567 | /* Release urcu mutexes */ |
1568 | rcu_bp_after_fork_child(); | |
17dfb34b | 1569 | lttng_ust_cleanup(0); |
a93bfc45 | 1570 | lttng_context_vtid_reset(); |
e822f505 | 1571 | /* Release mutexes and reenable signals */ |
b728d87e | 1572 | ust_after_fork_common(restore_sigset); |
318dfea9 | 1573 | lttng_ust_init(); |
e822f505 | 1574 | } |
95c25348 PW |
1575 | |
1576 | void lttng_ust_sockinfo_session_enabled(void *owner, | |
1577 | struct lttng_session *session_enabled) | |
1578 | { | |
1579 | struct sock_info *sock_info = owner; | |
1580 | sock_info->session_enabled = session_enabled; | |
1581 | } |