Fix: event notifier group: fix fd leak on error
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
CommitLineData
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
b4051ad8 23#include <stddef.h>
fb31eb73 24#include <stdint.h>
2691221a
MD
25#include <sys/types.h>
26#include <sys/socket.h>
7fc90dca
MD
27#include <sys/mman.h>
28#include <sys/stat.h>
58d4b2a2
MD
29#include <sys/types.h>
30#include <sys/wait.h>
b2292d85 31#include <dlfcn.h>
7fc90dca 32#include <fcntl.h>
2691221a
MD
33#include <unistd.h>
34#include <errno.h>
d9e99d10 35#include <pthread.h>
11ff9c7d
MD
36#include <semaphore.h>
37#include <time.h>
1ea11eab 38#include <assert.h>
e822f505 39#include <signal.h>
6f97f9c2 40#include <limits.h>
95259bd0 41#include <urcu/uatomic.h>
10544ee8 42#include "futex.h"
c117fb1b 43#include <urcu/compiler.h>
10544ee8 44#include <lttng/urcu/urcu-ust.h>
1ea11eab 45
b72687b8 46#include <lttng/align.h>
4318ae1b 47#include <lttng/ust-events.h>
4318ae1b 48#include <lttng/ust-abi.h>
4318ae1b 49#include <lttng/ust.h>
7bc53e94 50#include <lttng/ust-error.h>
74d81a6c 51#include <lttng/ust-ctl.h>
8c90a710 52#include <urcu/tls-compat.h>
44c72f10 53#include <ust-comm.h>
6548fca4 54#include <ust-fd.h>
44c72f10 55#include <usterr-signal-safe.h>
cd54f6d9 56#include <helper.h>
44c72f10 57#include "tracepoint-internal.h"
7dd08bec 58#include "lttng-tracer-core.h"
08114193 59#include "compat.h"
6f97f9c2 60#include "../libringbuffer/rb-init.h"
cf73e0fe 61#include "lttng-ust-statedump.h"
f9364363 62#include "clock.h"
5e1b7b8b 63#include "../libringbuffer/getcpu.h"
13efba44 64#include "getenv.h"
92495593 65#include "ust-events-internal.h"
edaa1431 66
b2292d85 67/* Concatenate lttng ust shared library name with its major version number. */
6be9efc1 68#define LTTNG_UST_LIB_SO_NAME "liblttng-ust.so." __ust_stringify(CONFIG_LTTNG_UST_LIBRARY_VERSION_MAJOR)
b2292d85 69
edaa1431
MD
70/*
71 * Has lttng ust comm constructor been called ?
72 */
73static int initialized;
74
1ea11eab 75/*
17dfb34b
MD
76 * The ust_lock/ust_unlock lock is used as a communication thread mutex.
77 * Held when handling a command, also held by fork() to deal with
78 * removal of threads, and by exit path.
3327ac33
MD
79 *
80 * The UST lock is the centralized mutex across UST tracing control and
81 * probe registration.
82 *
83 * ust_exit_mutex must never nest in ust_mutex.
d58d1454 84 *
4770bd47
MD
85 * ust_fork_mutex must never nest in ust_mutex.
86 *
d58d1454
MD
87 * ust_mutex_nest is a per-thread nesting counter, allowing the perf
88 * counter lazy initialization called by events within the statedump,
89 * which traces while the ust_mutex is held.
4770bd47
MD
90 *
91 * ust_lock nests within the dynamic loader lock (within glibc) because
92 * it is taken within the library constructor.
c1be081a
MD
93 *
94 * The ust fd tracker lock nests within the ust_mutex.
3327ac33
MD
95 */
96static pthread_mutex_t ust_mutex = PTHREAD_MUTEX_INITIALIZER;
97
d58d1454 98/* Allow nesting the ust_mutex within the same thread. */
16adecf1 99static DEFINE_URCU_TLS(int, ust_mutex_nest);
d58d1454 100
3327ac33
MD
101/*
102 * ust_exit_mutex protects thread_active variable wrt thread exit. It
103 * cannot be done by ust_mutex because pthread_cancel(), which takes an
104 * internal libc lock, cannot nest within ust_mutex.
105 *
106 * It never nests within a ust_mutex.
1ea11eab 107 */
3327ac33 108static pthread_mutex_t ust_exit_mutex = PTHREAD_MUTEX_INITIALIZER;
1ea11eab 109
458d678c
PW
110/*
111 * ust_fork_mutex protects base address statedump tracing against forks. It
112 * prevents the dynamic loader lock to be taken (by base address statedump
113 * tracing) while a fork is happening, thus preventing deadlock issues with
114 * the dynamic loader lock.
115 */
116static pthread_mutex_t ust_fork_mutex = PTHREAD_MUTEX_INITIALIZER;
117
1ea11eab
MD
118/* Should the ust comm thread quit ? */
119static int lttng_ust_comm_should_quit;
120
07b57e5e
MD
121/*
122 * This variable can be tested by applications to check whether
123 * lttng-ust is loaded. They simply have to define their own
124 * "lttng_ust_loaded" weak symbol, and test it. It is set to 1 by the
125 * library constructor.
126 */
127int lttng_ust_loaded __attribute__((weak));
128
3327ac33 129/*
d58d1454 130 * Return 0 on success, -1 if should quit.
3327ac33 131 * The lock is taken in both cases.
d58d1454 132 * Signal-safe.
3327ac33
MD
133 */
134int ust_lock(void)
135{
d58d1454 136 sigset_t sig_all_blocked, orig_mask;
e446ad80 137 int ret, oldstate;
d58d1454 138
e446ad80
MD
139 ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
140 if (ret) {
141 ERR("pthread_setcancelstate: %s", strerror(ret));
142 }
143 if (oldstate != PTHREAD_CANCEL_ENABLE) {
144 ERR("pthread_setcancelstate: unexpected oldstate");
145 }
d58d1454
MD
146 sigfillset(&sig_all_blocked);
147 ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
148 if (ret) {
149 ERR("pthread_sigmask: %s", strerror(ret));
150 }
151 if (!URCU_TLS(ust_mutex_nest)++)
152 pthread_mutex_lock(&ust_mutex);
153 ret = pthread_sigmask(SIG_SETMASK, &orig_mask, NULL);
154 if (ret) {
155 ERR("pthread_sigmask: %s", strerror(ret));
156 }
3327ac33
MD
157 if (lttng_ust_comm_should_quit) {
158 return -1;
159 } else {
160 return 0;
161 }
162}
163
164/*
165 * ust_lock_nocheck() can be used in constructors/destructors, because
166 * they are already nested within the dynamic loader lock, and therefore
167 * have exclusive access against execution of liblttng-ust destructor.
d58d1454 168 * Signal-safe.
3327ac33
MD
169 */
170void ust_lock_nocheck(void)
171{
d58d1454 172 sigset_t sig_all_blocked, orig_mask;
e446ad80 173 int ret, oldstate;
d58d1454 174
e446ad80
MD
175 ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
176 if (ret) {
177 ERR("pthread_setcancelstate: %s", strerror(ret));
178 }
179 if (oldstate != PTHREAD_CANCEL_ENABLE) {
180 ERR("pthread_setcancelstate: unexpected oldstate");
181 }
d58d1454
MD
182 sigfillset(&sig_all_blocked);
183 ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
184 if (ret) {
185 ERR("pthread_sigmask: %s", strerror(ret));
186 }
187 if (!URCU_TLS(ust_mutex_nest)++)
188 pthread_mutex_lock(&ust_mutex);
189 ret = pthread_sigmask(SIG_SETMASK, &orig_mask, NULL);
190 if (ret) {
191 ERR("pthread_sigmask: %s", strerror(ret));
192 }
3327ac33
MD
193}
194
d58d1454
MD
195/*
196 * Signal-safe.
197 */
3327ac33
MD
198void ust_unlock(void)
199{
d58d1454 200 sigset_t sig_all_blocked, orig_mask;
e446ad80 201 int ret, oldstate;
d58d1454
MD
202
203 sigfillset(&sig_all_blocked);
204 ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
205 if (ret) {
206 ERR("pthread_sigmask: %s", strerror(ret));
207 }
208 if (!--URCU_TLS(ust_mutex_nest))
209 pthread_mutex_unlock(&ust_mutex);
210 ret = pthread_sigmask(SIG_SETMASK, &orig_mask, NULL);
211 if (ret) {
212 ERR("pthread_sigmask: %s", strerror(ret));
213 }
e446ad80
MD
214 ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
215 if (ret) {
216 ERR("pthread_setcancelstate: %s", strerror(ret));
217 }
218 if (oldstate != PTHREAD_CANCEL_DISABLE) {
219 ERR("pthread_setcancelstate: unexpected oldstate");
220 }
3327ac33
MD
221}
222
11ff9c7d
MD
223/*
224 * Wait for either of these before continuing to the main
225 * program:
226 * - the register_done message from sessiond daemon
227 * (will let the sessiond daemon enable sessions before main
228 * starts.)
229 * - sessiond daemon is not reachable.
230 * - timeout (ensuring applications are resilient to session
231 * daemon problems).
232 */
233static sem_t constructor_wait;
950aab0c
MD
234/*
235 * Doing this for both the global and local sessiond.
236 */
eb0e6022
GAPG
237enum {
238 sem_count_initial_value = 4,
239};
240
241static int sem_count = sem_count_initial_value;
11ff9c7d 242
e8508a49
MD
243/*
244 * Counting nesting within lttng-ust. Used to ensure that calling fork()
245 * from liblttng-ust does not execute the pre/post fork handlers.
246 */
8c90a710 247static DEFINE_URCU_TLS(int, lttng_ust_nest_count);
e8508a49 248
1ea11eab
MD
249/*
250 * Info about socket and associated listener thread.
251 */
252struct sock_info {
11ff9c7d 253 const char *name;
1ea11eab 254 pthread_t ust_listener; /* listener thread */
46050b1a 255 int root_handle;
eb0e6022 256 int registration_done;
8d20bf54 257 int allowed;
44e073f5 258 int global;
e33f3265 259 int thread_active;
7fc90dca
MD
260
261 char sock_path[PATH_MAX];
262 int socket;
32ce8569 263 int notify_socket;
7fc90dca
MD
264
265 char wait_shm_path[PATH_MAX];
266 char *wait_shm_mmap;
37dddb65
MD
267 /* Keep track of lazy state dump not performed yet. */
268 int statedump_pending;
eb0e6022 269 int initial_statedump_done;
94be38e8 270 /* Keep procname for statedump */
0db3d6ee 271 char procname[LTTNG_UST_ABI_PROCNAME_LEN];
1ea11eab 272};
2691221a
MD
273
274/* Socket from app (connect) to session daemon (listen) for communication */
1ea11eab 275struct sock_info global_apps = {
11ff9c7d 276 .name = "global",
44e073f5 277 .global = 1,
7fc90dca 278
46050b1a 279 .root_handle = -1,
eb0e6022 280 .registration_done = 0,
060577e3 281 .allowed = 0,
e33f3265 282 .thread_active = 0,
7fc90dca 283
32ce8569 284 .sock_path = LTTNG_DEFAULT_RUNDIR "/" LTTNG_UST_SOCK_FILENAME,
7fc90dca 285 .socket = -1,
32ce8569 286 .notify_socket = -1,
7fc90dca 287
32ce8569 288 .wait_shm_path = "/" LTTNG_UST_WAIT_FILENAME,
95c25348 289
37dddb65 290 .statedump_pending = 0,
eb0e6022 291 .initial_statedump_done = 0,
94be38e8 292 .procname[0] = '\0'
1ea11eab 293};
2691221a
MD
294
295/* TODO: allow global_apps_sock_path override */
296
1ea11eab 297struct sock_info local_apps = {
11ff9c7d 298 .name = "local",
44e073f5 299 .global = 0,
46050b1a 300 .root_handle = -1,
eb0e6022 301 .registration_done = 0,
8d20bf54 302 .allowed = 0, /* Check setuid bit first */
e33f3265 303 .thread_active = 0,
7fc90dca
MD
304
305 .socket = -1,
32ce8569 306 .notify_socket = -1,
95c25348 307
37dddb65 308 .statedump_pending = 0,
eb0e6022 309 .initial_statedump_done = 0,
94be38e8 310 .procname[0] = '\0'
1ea11eab 311};
2691221a 312
37ed587a
MD
313static int wait_poll_fallback;
314
74d81a6c
MD
315static const char *cmd_name_mapping[] = {
316 [ LTTNG_UST_RELEASE ] = "Release",
317 [ LTTNG_UST_SESSION ] = "Create Session",
318 [ LTTNG_UST_TRACER_VERSION ] = "Get Tracer Version",
319
320 [ LTTNG_UST_TRACEPOINT_LIST ] = "Create Tracepoint List",
321 [ LTTNG_UST_WAIT_QUIESCENT ] = "Wait for Quiescent State",
322 [ LTTNG_UST_REGISTER_DONE ] = "Registration Done",
323 [ LTTNG_UST_TRACEPOINT_FIELD_LIST ] = "Create Tracepoint Field List",
324
d8d2416d
FD
325 [ LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE ] = "Create event notifier group",
326
74d81a6c
MD
327 /* Session FD commands */
328 [ LTTNG_UST_CHANNEL ] = "Create Channel",
329 [ LTTNG_UST_SESSION_START ] = "Start Session",
330 [ LTTNG_UST_SESSION_STOP ] = "Stop Session",
331
332 /* Channel FD commands */
333 [ LTTNG_UST_STREAM ] = "Create Stream",
334 [ LTTNG_UST_EVENT ] = "Create Event",
335
336 /* Event and Channel FD commands */
337 [ LTTNG_UST_CONTEXT ] = "Create Context",
338 [ LTTNG_UST_FLUSH_BUFFER ] = "Flush Buffer",
339
340 /* Event, Channel and Session commands */
341 [ LTTNG_UST_ENABLE ] = "Enable",
342 [ LTTNG_UST_DISABLE ] = "Disable",
343
344 /* Tracepoint list commands */
345 [ LTTNG_UST_TRACEPOINT_LIST_GET ] = "List Next Tracepoint",
346 [ LTTNG_UST_TRACEPOINT_FIELD_LIST_GET ] = "List Next Tracepoint Field",
347
348 /* Event FD commands */
349 [ LTTNG_UST_FILTER ] = "Create Filter",
75582b3a 350 [ LTTNG_UST_EXCLUSION ] = "Add exclusions to event",
d8d2416d
FD
351
352 /* Event notifier group commands */
353 [ LTTNG_UST_EVENT_NOTIFIER_CREATE ] = "Create event notifier",
ebabbf58
MD
354
355 /* Session and event notifier group commands */
356 [ LTTNG_UST_COUNTER ] = "Create Counter",
357
358 /* Counter commands */
359 [ LTTNG_UST_COUNTER_GLOBAL ] = "Create Counter Global",
360 [ LTTNG_UST_COUNTER_CPU ] = "Create Counter CPU",
74d81a6c
MD
361};
362
ff517991
MD
363static const char *str_timeout;
364static int got_timeout_env;
365
7dd08bec 366extern void lttng_ring_buffer_client_overwrite_init(void);
34a91bdb 367extern void lttng_ring_buffer_client_overwrite_rt_init(void);
7dd08bec 368extern void lttng_ring_buffer_client_discard_init(void);
34a91bdb 369extern void lttng_ring_buffer_client_discard_rt_init(void);
7dd08bec
MD
370extern void lttng_ring_buffer_metadata_client_init(void);
371extern void lttng_ring_buffer_client_overwrite_exit(void);
34a91bdb 372extern void lttng_ring_buffer_client_overwrite_rt_exit(void);
7dd08bec 373extern void lttng_ring_buffer_client_discard_exit(void);
34a91bdb 374extern void lttng_ring_buffer_client_discard_rt_exit(void);
7dd08bec 375extern void lttng_ring_buffer_metadata_client_exit(void);
ebabbf58
MD
376extern void lttng_counter_client_percpu_32_modular_init(void);
377extern void lttng_counter_client_percpu_32_modular_exit(void);
378extern void lttng_counter_client_percpu_64_modular_init(void);
379extern void lttng_counter_client_percpu_64_modular_exit(void);
edaa1431 380
060577e3
JR
381static char *get_map_shm(struct sock_info *sock_info);
382
405be658
MD
383ssize_t lttng_ust_read(int fd, void *buf, size_t len)
384{
385 ssize_t ret;
386 size_t copied = 0, to_copy = len;
387
388 do {
389 ret = read(fd, buf + copied, to_copy);
390 if (ret > 0) {
391 copied += ret;
392 to_copy -= ret;
393 }
394 } while ((ret > 0 && to_copy > 0)
395 || (ret < 0 && errno == EINTR));
396 if (ret > 0) {
397 ret = copied;
398 }
399 return ret;
400}
3c6f6263
AM
401/*
402 * Returns the HOME directory path. Caller MUST NOT free(3) the returned
403 * pointer.
404 */
405static
406const char *get_lttng_home_dir(void)
407{
408 const char *val;
409
6f626d28 410 val = (const char *) lttng_getenv("LTTNG_HOME");
3c6f6263
AM
411 if (val != NULL) {
412 return val;
413 }
6f626d28 414 return (const char *) lttng_getenv("HOME");
3c6f6263
AM
415}
416
a903623f
MD
417/*
418 * Force a read (imply TLS fixup for dlopen) of TLS variables.
419 */
420static
421void lttng_fixup_nest_count_tls(void)
422{
8c90a710 423 asm volatile ("" : : "m" (URCU_TLS(lttng_ust_nest_count)));
a903623f
MD
424}
425
d58d1454
MD
426static
427void lttng_fixup_ust_mutex_nest_tls(void)
428{
429 asm volatile ("" : : "m" (URCU_TLS(ust_mutex_nest)));
430}
431
1556a549
MD
432/*
433 * Fixup urcu bp TLS.
434 */
435static
436void lttng_fixup_urcu_bp_tls(void)
437{
10544ee8 438 (void) lttng_ust_urcu_read_ongoing();
1556a549
MD
439}
440
c362addf
MD
441void lttng_ust_fixup_tls(void)
442{
443 lttng_fixup_urcu_bp_tls();
444 lttng_fixup_ringbuffer_tls();
445 lttng_fixup_vtid_tls();
446 lttng_fixup_nest_count_tls();
447 lttng_fixup_procname_tls();
448 lttng_fixup_ust_mutex_nest_tls();
20142124 449 lttng_ust_fixup_perf_counter_tls();
6548fca4 450 lttng_ust_fixup_fd_tracker_tls();
735bef47
MJ
451 lttng_fixup_cgroup_ns_tls();
452 lttng_fixup_ipc_ns_tls();
453 lttng_fixup_net_ns_tls();
cefef7a7 454 lttng_fixup_time_ns_tls();
735bef47 455 lttng_fixup_uts_ns_tls();
c362addf
MD
456}
457
32ce8569
MD
458int lttng_get_notify_socket(void *owner)
459{
460 struct sock_info *info = owner;
461
462 return info->notify_socket;
463}
464
94be38e8
JR
465
466LTTNG_HIDDEN
467char* lttng_ust_sockinfo_get_procname(void *owner)
468{
469 struct sock_info *info = owner;
470
471 return info->procname;
472}
473
74d81a6c
MD
474static
475void print_cmd(int cmd, int handle)
476{
477 const char *cmd_name = "Unknown";
478
fd67a004
MD
479 if (cmd >= 0 && cmd < LTTNG_ARRAY_SIZE(cmd_name_mapping)
480 && cmd_name_mapping[cmd]) {
74d81a6c
MD
481 cmd_name = cmd_name_mapping[cmd];
482 }
fd67a004
MD
483 DBG("Message Received \"%s\" (%d), Handle \"%s\" (%d)",
484 cmd_name, cmd,
74d81a6c
MD
485 lttng_ust_obj_get_name(handle), handle);
486}
487
060577e3
JR
488static
489int setup_global_apps(void)
490{
491 int ret = 0;
492 assert(!global_apps.wait_shm_mmap);
493
494 global_apps.wait_shm_mmap = get_map_shm(&global_apps);
495 if (!global_apps.wait_shm_mmap) {
496 WARN("Unable to get map shm for global apps. Disabling LTTng-UST global tracing.");
497 global_apps.allowed = 0;
498 ret = -EIO;
499 goto error;
500 }
501
502 global_apps.allowed = 1;
0db3d6ee 503 lttng_pthread_getname_np(global_apps.procname, LTTNG_UST_ABI_PROCNAME_LEN);
060577e3
JR
504error:
505 return ret;
506}
2691221a 507static
8d20bf54 508int setup_local_apps(void)
2691221a 509{
060577e3 510 int ret = 0;
2691221a 511 const char *home_dir;
7fc90dca 512 uid_t uid;
2691221a 513
060577e3
JR
514 assert(!local_apps.wait_shm_mmap);
515
7fc90dca 516 uid = getuid();
8d20bf54
MD
517 /*
518 * Disallow per-user tracing for setuid binaries.
519 */
7fc90dca 520 if (uid != geteuid()) {
9ec6895c 521 assert(local_apps.allowed == 0);
060577e3
JR
522 ret = 0;
523 goto end;
8d20bf54 524 }
3c6f6263 525 home_dir = get_lttng_home_dir();
9ec6895c
MD
526 if (!home_dir) {
527 WARN("HOME environment variable not set. Disabling LTTng-UST per-user tracing.");
528 assert(local_apps.allowed == 0);
060577e3
JR
529 ret = -ENOENT;
530 goto end;
9ec6895c
MD
531 }
532 local_apps.allowed = 1;
32ce8569
MD
533 snprintf(local_apps.sock_path, PATH_MAX, "%s/%s/%s",
534 home_dir,
535 LTTNG_DEFAULT_HOME_RUNDIR,
536 LTTNG_UST_SOCK_FILENAME);
537 snprintf(local_apps.wait_shm_path, PATH_MAX, "/%s-%u",
538 LTTNG_UST_WAIT_FILENAME,
539 uid);
060577e3
JR
540
541 local_apps.wait_shm_mmap = get_map_shm(&local_apps);
542 if (!local_apps.wait_shm_mmap) {
543 WARN("Unable to get map shm for local apps. Disabling LTTng-UST per-user tracing.");
544 local_apps.allowed = 0;
545 ret = -EIO;
546 goto end;
547 }
94be38e8 548
0db3d6ee 549 lttng_pthread_getname_np(local_apps.procname, LTTNG_UST_ABI_PROCNAME_LEN);
060577e3
JR
550end:
551 return ret;
2691221a
MD
552}
553
ff517991 554/*
451d66b2 555 * Get socket timeout, in ms.
28515902 556 * -1: wait forever. 0: don't wait. >0: timeout, in ms.
ff517991
MD
557 */
558static
559long get_timeout(void)
560{
561 long constructor_delay_ms = LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS;
562
563 if (!got_timeout_env) {
6f626d28 564 str_timeout = lttng_getenv("LTTNG_UST_REGISTER_TIMEOUT");
ff517991
MD
565 got_timeout_env = 1;
566 }
567 if (str_timeout)
568 constructor_delay_ms = strtol(str_timeout, NULL, 10);
5cf81d53
MD
569 /* All negative values are considered as "-1". */
570 if (constructor_delay_ms < -1)
571 constructor_delay_ms = -1;
ff517991
MD
572 return constructor_delay_ms;
573}
574
451d66b2 575/* Timeout for notify socket send and recv. */
ff517991
MD
576static
577long get_notify_sock_timeout(void)
578{
579 return get_timeout();
580}
581
451d66b2
MD
582/* Timeout for connecting to cmd and notify sockets. */
583static
584long get_connect_sock_timeout(void)
585{
586 return get_timeout();
587}
588
ff517991 589/*
28515902 590 * Return values: -1: wait forever. 0: don't wait. 1: timeout wait.
ff517991
MD
591 */
592static
593int get_constructor_timeout(struct timespec *constructor_timeout)
594{
595 long constructor_delay_ms;
596 int ret;
597
598 constructor_delay_ms = get_timeout();
599
600 switch (constructor_delay_ms) {
601 case -1:/* fall-through */
602 case 0:
603 return constructor_delay_ms;
604 default:
605 break;
606 }
607
608 /*
609 * If we are unable to find the current time, don't wait.
610 */
611 ret = clock_gettime(CLOCK_REALTIME, constructor_timeout);
612 if (ret) {
28515902
JG
613 /* Don't wait. */
614 return 0;
ff517991
MD
615 }
616 constructor_timeout->tv_sec += constructor_delay_ms / 1000UL;
617 constructor_timeout->tv_nsec +=
618 (constructor_delay_ms % 1000UL) * 1000000UL;
619 if (constructor_timeout->tv_nsec >= 1000000000UL) {
620 constructor_timeout->tv_sec++;
621 constructor_timeout->tv_nsec -= 1000000000UL;
622 }
28515902 623 /* Timeout wait (constructor_delay_ms). */
ff517991
MD
624 return 1;
625}
626
6f97f9c2 627static
b2c5f61a 628void get_allow_blocking(void)
6f97f9c2 629{
b2c5f61a
MD
630 const char *str_allow_blocking =
631 lttng_getenv("LTTNG_UST_ALLOW_BLOCKING");
632
633 if (str_allow_blocking) {
634 DBG("%s environment variable is set",
635 "LTTNG_UST_ALLOW_BLOCKING");
636 lttng_ust_ringbuffer_set_allow_blocking();
6f97f9c2
MD
637 }
638}
639
2691221a 640static
32ce8569 641int register_to_sessiond(int socket, enum ustctl_socket_type type)
2691221a 642{
32ce8569
MD
643 return ustcomm_send_reg_msg(socket,
644 type,
645 CAA_BITS_PER_LONG,
646 lttng_alignof(uint8_t) * CHAR_BIT,
647 lttng_alignof(uint16_t) * CHAR_BIT,
648 lttng_alignof(uint32_t) * CHAR_BIT,
649 lttng_alignof(uint64_t) * CHAR_BIT,
650 lttng_alignof(unsigned long) * CHAR_BIT);
2691221a
MD
651}
652
d9e99d10 653static
57773204 654int send_reply(int sock, struct ustcomm_ust_reply *lur)
d9e99d10 655{
9eb62b9c 656 ssize_t len;
d3a492d1 657
57773204 658 len = ustcomm_send_unix_sock(sock, lur, sizeof(*lur));
d3a492d1 659 switch (len) {
a4be8962 660 case sizeof(*lur):
d3a492d1
MD
661 DBG("message successfully sent");
662 return 0;
7bc53e94
MD
663 default:
664 if (len == -ECONNRESET) {
665 DBG("remote end closed connection");
d3a492d1
MD
666 return 0;
667 }
7bc53e94
MD
668 if (len < 0)
669 return len;
670 DBG("incorrect message size: %zd", len);
671 return -EINVAL;
d3a492d1
MD
672 }
673}
674
675static
eb0e6022 676void decrement_sem_count(unsigned int count)
11ff9c7d
MD
677{
678 int ret;
679
eb0e6022
GAPG
680 assert(uatomic_read(&sem_count) >= count);
681
56cd7e2f 682 if (uatomic_read(&sem_count) <= 0) {
eb0e6022 683 return;
56cd7e2f 684 }
eb0e6022
GAPG
685
686 ret = uatomic_add_return(&sem_count, -count);
95259bd0
MD
687 if (ret == 0) {
688 ret = sem_post(&constructor_wait);
689 assert(!ret);
690 }
eb0e6022
GAPG
691}
692
693static
694int handle_register_done(struct sock_info *sock_info)
695{
696 if (sock_info->registration_done)
697 return 0;
698 sock_info->registration_done = 1;
699
700 decrement_sem_count(1);
04682184
MD
701 if (!sock_info->statedump_pending) {
702 sock_info->initial_statedump_done = 1;
703 decrement_sem_count(1);
704 }
eb0e6022
GAPG
705
706 return 0;
707}
708
709static
710int handle_register_failed(struct sock_info *sock_info)
711{
712 if (sock_info->registration_done)
713 return 0;
714 sock_info->registration_done = 1;
715 sock_info->initial_statedump_done = 1;
716
717 decrement_sem_count(2);
718
11ff9c7d
MD
719 return 0;
720}
721
37dddb65
MD
722/*
723 * Only execute pending statedump after the constructor semaphore has
eb0e6022
GAPG
724 * been posted by the current listener thread. This means statedump will
725 * only be performed after the "registration done" command is received
726 * from this thread's session daemon.
37dddb65
MD
727 *
728 * This ensures we don't run into deadlock issues with the dynamic
729 * loader mutex, which is held while the constructor is called and
730 * waiting on the constructor semaphore. All operations requiring this
731 * dynamic loader lock need to be postponed using this mechanism.
eb0e6022
GAPG
732 *
733 * In a scenario with two session daemons connected to the application,
734 * it is possible that the first listener thread which receives the
735 * registration done command issues its statedump while the dynamic
736 * loader lock is still held by the application constructor waiting on
737 * the semaphore. It will however be allowed to proceed when the
738 * second session daemon sends the registration done command to the
739 * second listener thread. This situation therefore does not produce
740 * a deadlock.
37dddb65
MD
741 */
742static
743void handle_pending_statedump(struct sock_info *sock_info)
744{
eb0e6022 745 if (sock_info->registration_done && sock_info->statedump_pending) {
37dddb65 746 sock_info->statedump_pending = 0;
2932a87f 747 pthread_mutex_lock(&ust_fork_mutex);
37dddb65 748 lttng_handle_pending_statedump(sock_info);
458d678c 749 pthread_mutex_unlock(&ust_fork_mutex);
eb0e6022
GAPG
750
751 if (!sock_info->initial_statedump_done) {
752 sock_info->initial_statedump_done = 1;
753 decrement_sem_count(1);
754 }
37dddb65
MD
755 }
756}
757
6a6ef048
FD
758static inline
759const char *bytecode_type_str(uint32_t cmd)
760{
761 switch (cmd) {
d37ecb3f
FD
762 case LTTNG_UST_CAPTURE:
763 return "capture";
6a6ef048
FD
764 case LTTNG_UST_FILTER:
765 return "filter";
766 default:
767 abort();
768 }
769}
770
771static
772int handle_bytecode_recv(struct sock_info *sock_info,
773 int sock, struct ustcomm_ust_msg *lum)
774{
775 struct lttng_ust_bytecode_node *bytecode;
776 enum lttng_ust_bytecode_node_type type;
777 const struct lttng_ust_objd_ops *ops;
778 uint32_t data_size, data_size_max, reloc_offset;
779 uint64_t seqnum;
780 ssize_t len;
781 int ret = 0;
782
783 switch (lum->cmd) {
784 case LTTNG_UST_FILTER:
785 type = LTTNG_UST_BYTECODE_NODE_TYPE_FILTER;
786 data_size = lum->u.filter.data_size;
787 data_size_max = FILTER_BYTECODE_MAX_LEN;
788 reloc_offset = lum->u.filter.reloc_offset;
789 seqnum = lum->u.filter.seqnum;
790 break;
d37ecb3f
FD
791 case LTTNG_UST_CAPTURE:
792 type = LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE;
793 data_size = lum->u.capture.data_size;
794 data_size_max = CAPTURE_BYTECODE_MAX_LEN;
795 reloc_offset = lum->u.capture.reloc_offset;
796 seqnum = lum->u.capture.seqnum;
797 break;
6a6ef048
FD
798 default:
799 abort();
800 }
801
802 if (data_size > data_size_max) {
803 ERR("Bytecode %s data size is too large: %u bytes",
804 bytecode_type_str(lum->cmd), data_size);
805 ret = -EINVAL;
806 goto end;
807 }
808
809 if (reloc_offset > data_size) {
810 ERR("Bytecode %s reloc offset %u is not within data",
811 bytecode_type_str(lum->cmd), reloc_offset);
812 ret = -EINVAL;
813 goto end;
814 }
815
816 /* Allocate the structure AND the `data[]` field. */
817 bytecode = zmalloc(sizeof(*bytecode) + data_size);
818 if (!bytecode) {
819 ret = -ENOMEM;
820 goto end;
821 }
822
823 bytecode->bc.len = data_size;
824 bytecode->bc.reloc_offset = reloc_offset;
825 bytecode->bc.seqnum = seqnum;
826 bytecode->type = type;
827
828 len = ustcomm_recv_unix_sock(sock, bytecode->bc.data, bytecode->bc.len);
829 switch (len) {
830 case 0: /* orderly shutdown */
831 ret = 0;
832 goto error_free_bytecode;
833 default:
834 if (len == bytecode->bc.len) {
835 DBG("Bytecode %s data received",
836 bytecode_type_str(lum->cmd));
837 break;
838 } else if (len < 0) {
839 DBG("Receive failed from lttng-sessiond with errno %d",
840 (int) -len);
841 if (len == -ECONNRESET) {
842 ERR("%s remote end closed connection",
843 sock_info->name);
844 ret = len;
845 goto error_free_bytecode;
846 }
847 ret = len;
848 goto error_free_bytecode;
849 } else {
850 DBG("Incorrect %s bytecode data message size: %zd",
851 bytecode_type_str(lum->cmd), len);
852 ret = -EINVAL;
853 goto error_free_bytecode;
854 }
855 }
856
857 ops = objd_ops(lum->handle);
858 if (!ops) {
859 ret = -ENOENT;
860 goto error_free_bytecode;
861 }
862
863 if (ops->cmd) {
864 ret = ops->cmd(lum->handle, lum->cmd,
865 (unsigned long) bytecode,
866 NULL, sock_info);
867 if (ret)
868 goto error_free_bytecode;
869 /* don't free bytecode if everything went fine. */
870 } else {
871 ret = -ENOSYS;
872 goto error_free_bytecode;
873 }
874
875 goto end;
876
877error_free_bytecode:
878 free(bytecode);
879end:
880 return ret;
881}
882
11ff9c7d
MD
883static
884int handle_message(struct sock_info *sock_info,
57773204 885 int sock, struct ustcomm_ust_msg *lum)
d3a492d1 886{
1ea11eab 887 int ret = 0;
b61ce3b2 888 const struct lttng_ust_objd_ops *ops;
57773204 889 struct ustcomm_ust_reply lur;
ef9ff354 890 union ust_args args;
8e696cfa 891 char ctxstr[LTTNG_UST_SYM_NAME_LEN]; /* App context string. */
40003310 892 ssize_t len;
1ea11eab 893
46050b1a
MD
894 memset(&lur, 0, sizeof(lur));
895
3327ac33 896 if (ust_lock()) {
74d81a6c 897 ret = -LTTNG_UST_ERR_EXITING;
0dafcd63 898 goto error;
1ea11eab 899 }
9eb62b9c 900
46050b1a
MD
901 ops = objd_ops(lum->handle);
902 if (!ops) {
903 ret = -ENOENT;
0dafcd63 904 goto error;
1ea11eab 905 }
46050b1a
MD
906
907 switch (lum->cmd) {
11ff9c7d
MD
908 case LTTNG_UST_REGISTER_DONE:
909 if (lum->handle == LTTNG_UST_ROOT_HANDLE)
edaa1431 910 ret = handle_register_done(sock_info);
11ff9c7d
MD
911 else
912 ret = -EINVAL;
913 break;
46050b1a
MD
914 case LTTNG_UST_RELEASE:
915 if (lum->handle == LTTNG_UST_ROOT_HANDLE)
916 ret = -EPERM;
917 else
1849ef7c 918 ret = lttng_ust_objd_unref(lum->handle, 1);
d9e99d10 919 break;
d37ecb3f 920 case LTTNG_UST_CAPTURE:
2d78951a 921 case LTTNG_UST_FILTER:
6a6ef048
FD
922 ret = handle_bytecode_recv(sock_info, sock, lum);
923 if (ret)
2734ca65 924 goto error;
2d78951a 925 break;
86e36163
JI
926 case LTTNG_UST_EXCLUSION:
927 {
928 /* Receive exclusion names */
929 struct lttng_ust_excluder_node *node;
930 unsigned int count;
931
932 count = lum->u.exclusion.count;
933 if (count == 0) {
934 /* There are no names to read */
935 ret = 0;
936 goto error;
937 }
938 node = zmalloc(sizeof(*node) +
939 count * LTTNG_UST_SYM_NAME_LEN);
940 if (!node) {
941 ret = -ENOMEM;
942 goto error;
943 }
944 node->excluder.count = count;
945 len = ustcomm_recv_unix_sock(sock, node->excluder.names,
946 count * LTTNG_UST_SYM_NAME_LEN);
947 switch (len) {
948 case 0: /* orderly shutdown */
949 ret = 0;
950 free(node);
951 goto error;
952 default:
953 if (len == count * LTTNG_UST_SYM_NAME_LEN) {
954 DBG("Exclusion data received");
955 break;
956 } else if (len < 0) {
957 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
958 if (len == -ECONNRESET) {
959 ERR("%s remote end closed connection", sock_info->name);
960 ret = len;
961 free(node);
962 goto error;
963 }
964 ret = len;
965 free(node);
0dafcd63 966 goto error;
86e36163
JI
967 } else {
968 DBG("Incorrect exclusion data message size: %zd", len);
969 ret = -EINVAL;
970 free(node);
0dafcd63 971 goto error;
86e36163
JI
972 }
973 }
974 if (ops->cmd) {
975 ret = ops->cmd(lum->handle, lum->cmd,
976 (unsigned long) node,
977 &args, sock_info);
978 if (ret) {
979 free(node);
980 }
981 /* Don't free exclusion data if everything went fine. */
982 } else {
983 ret = -ENOSYS;
984 free(node);
985 }
986 break;
987 }
d8d2416d
FD
988 case LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE:
989 {
f52e5902 990 int event_notifier_notif_fd, close_ret;
d8d2416d
FD
991
992 len = ustcomm_recv_event_notifier_notif_fd_from_sessiond(sock,
993 &event_notifier_notif_fd);
994 switch (len) {
995 case 0: /* orderly shutdown */
996 ret = 0;
997 goto error;
998 case 1:
999 break;
1000 default:
1001 if (len < 0) {
1002 DBG("Receive failed from lttng-sessiond with errno %d",
1003 (int) -len);
1004 if (len == -ECONNRESET) {
1005 ERR("%s remote end closed connection",
1006 sock_info->name);
1007 ret = len;
1008 goto error;
1009 }
1010 ret = len;
1011 goto error;
1012 } else {
1013 DBG("Incorrect event notifier fd message size: %zd",
1014 len);
1015 ret = -EINVAL;
1016 goto error;
1017 }
1018 }
1019 args.event_notifier_handle.event_notifier_notif_fd =
1020 event_notifier_notif_fd;
1021 if (ops->cmd)
1022 ret = ops->cmd(lum->handle, lum->cmd,
1023 (unsigned long) &lum->u,
1024 &args, sock_info);
1025 else
1026 ret = -ENOSYS;
f52e5902
MD
1027 if (args.event_notifier_handle.event_notifier_notif_fd >= 0) {
1028 lttng_ust_lock_fd_tracker();
1029 close_ret = close(args.event_notifier_handle.event_notifier_notif_fd);
1030 lttng_ust_unlock_fd_tracker();
1031 if (close_ret)
1032 PERROR("close");
1033 }
d8d2416d
FD
1034 break;
1035 }
74d81a6c
MD
1036 case LTTNG_UST_CHANNEL:
1037 {
1038 void *chan_data;
ff0f5728 1039 int wakeup_fd;
74d81a6c
MD
1040
1041 len = ustcomm_recv_channel_from_sessiond(sock,
ff0f5728
MD
1042 &chan_data, lum->u.channel.len,
1043 &wakeup_fd);
74d81a6c
MD
1044 switch (len) {
1045 case 0: /* orderly shutdown */
1046 ret = 0;
1047 goto error;
1048 default:
1049 if (len == lum->u.channel.len) {
1050 DBG("channel data received");
1051 break;
1052 } else if (len < 0) {
1053 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
1054 if (len == -ECONNRESET) {
1055 ERR("%s remote end closed connection", sock_info->name);
1056 ret = len;
1057 goto error;
1058 }
1059 ret = len;
0dafcd63 1060 goto error;
74d81a6c
MD
1061 } else {
1062 DBG("incorrect channel data message size: %zd", len);
1063 ret = -EINVAL;
0dafcd63 1064 goto error;
74d81a6c
MD
1065 }
1066 }
1067 args.channel.chan_data = chan_data;
ff0f5728 1068 args.channel.wakeup_fd = wakeup_fd;
74d81a6c
MD
1069 if (ops->cmd)
1070 ret = ops->cmd(lum->handle, lum->cmd,
1071 (unsigned long) &lum->u,
1072 &args, sock_info);
1073 else
1074 ret = -ENOSYS;
867942fd
MD
1075 if (args.channel.wakeup_fd >= 0) {
1076 int close_ret;
1077
1078 lttng_ust_lock_fd_tracker();
1079 close_ret = close(args.channel.wakeup_fd);
1080 lttng_ust_unlock_fd_tracker();
1081 args.channel.wakeup_fd = -1;
1082 if (close_ret)
1083 PERROR("close");
1084 }
1085 free(args.channel.chan_data);
74d81a6c
MD
1086 break;
1087 }
1088 case LTTNG_UST_STREAM:
1089 {
118c051e
MD
1090 int close_ret;
1091
74d81a6c
MD
1092 /* Receive shm_fd, wakeup_fd */
1093 ret = ustcomm_recv_stream_from_sessiond(sock,
61e520fb 1094 NULL,
74d81a6c
MD
1095 &args.stream.shm_fd,
1096 &args.stream.wakeup_fd);
1097 if (ret) {
0dafcd63 1098 goto error;
74d81a6c 1099 }
973eac63 1100
74d81a6c
MD
1101 if (ops->cmd)
1102 ret = ops->cmd(lum->handle, lum->cmd,
1103 (unsigned long) &lum->u,
1104 &args, sock_info);
1105 else
1106 ret = -ENOSYS;
118c051e
MD
1107 if (args.stream.shm_fd >= 0) {
1108 lttng_ust_lock_fd_tracker();
1109 close_ret = close(args.stream.shm_fd);
1110 lttng_ust_unlock_fd_tracker();
1111 args.stream.shm_fd = -1;
1112 if (close_ret)
1113 PERROR("close");
1114 }
1115 if (args.stream.wakeup_fd >= 0) {
1116 lttng_ust_lock_fd_tracker();
1117 close_ret = close(args.stream.wakeup_fd);
1118 lttng_ust_unlock_fd_tracker();
1119 args.stream.wakeup_fd = -1;
1120 if (close_ret)
1121 PERROR("close");
1122 }
74d81a6c
MD
1123 break;
1124 }
8e696cfa
MD
1125 case LTTNG_UST_CONTEXT:
1126 switch (lum->u.context.ctx) {
1127 case LTTNG_UST_CONTEXT_APP_CONTEXT:
1128 {
1129 char *p;
1130 size_t ctxlen, recvlen;
1131
1132 ctxlen = strlen("$app.") + lum->u.context.u.app_ctx.provider_name_len - 1
1133 + strlen(":") + lum->u.context.u.app_ctx.ctx_name_len;
1134 if (ctxlen >= LTTNG_UST_SYM_NAME_LEN) {
1135 ERR("Application context string length size is too large: %zu bytes",
1136 ctxlen);
1137 ret = -EINVAL;
1138 goto error;
1139 }
1140 strcpy(ctxstr, "$app.");
1141 p = &ctxstr[strlen("$app.")];
1142 recvlen = ctxlen - strlen("$app.");
1143 len = ustcomm_recv_unix_sock(sock, p, recvlen);
1144 switch (len) {
1145 case 0: /* orderly shutdown */
1146 ret = 0;
1147 goto error;
1148 default:
1149 if (len == recvlen) {
1150 DBG("app context data received");
1151 break;
1152 } else if (len < 0) {
1153 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
1154 if (len == -ECONNRESET) {
1155 ERR("%s remote end closed connection", sock_info->name);
1156 ret = len;
1157 goto error;
1158 }
1159 ret = len;
1160 goto error;
1161 } else {
1162 DBG("incorrect app context data message size: %zd", len);
1163 ret = -EINVAL;
1164 goto error;
1165 }
1166 }
1167 /* Put : between provider and ctxname. */
1168 p[lum->u.context.u.app_ctx.provider_name_len - 1] = ':';
1169 args.app_context.ctxname = ctxstr;
1170 break;
1171 }
1172 default:
1173 break;
1174 }
1175 if (ops->cmd) {
1176 ret = ops->cmd(lum->handle, lum->cmd,
1177 (unsigned long) &lum->u,
1178 &args, sock_info);
1179 } else {
1180 ret = -ENOSYS;
1181 }
1182 break;
ebabbf58
MD
1183 case LTTNG_UST_COUNTER:
1184 {
1185 void *counter_data;
1186
1187 len = ustcomm_recv_counter_from_sessiond(sock,
1188 &counter_data, lum->u.counter.len);
1189 switch (len) {
1190 case 0: /* orderly shutdown */
1191 ret = 0;
1192 goto error;
1193 default:
1194 if (len == lum->u.counter.len) {
1195 DBG("counter data received");
1196 break;
1197 } else if (len < 0) {
1198 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
1199 if (len == -ECONNRESET) {
1200 ERR("%s remote end closed connection", sock_info->name);
1201 ret = len;
1202 goto error;
1203 }
1204 ret = len;
1205 goto error;
1206 } else {
1207 DBG("incorrect counter data message size: %zd", len);
1208 ret = -EINVAL;
1209 goto error;
1210 }
1211 }
1212 args.counter.counter_data = counter_data;
1213 if (ops->cmd)
1214 ret = ops->cmd(lum->handle, lum->cmd,
1215 (unsigned long) &lum->u,
1216 &args, sock_info);
1217 else
1218 ret = -ENOSYS;
1219 break;
1220 }
1221 case LTTNG_UST_COUNTER_GLOBAL:
1222 {
1223 /* Receive shm_fd */
1224 ret = ustcomm_recv_counter_shm_from_sessiond(sock,
1225 &args.counter_shm.shm_fd);
1226 if (ret) {
1227 goto error;
1228 }
1229
1230 if (ops->cmd)
1231 ret = ops->cmd(lum->handle, lum->cmd,
1232 (unsigned long) &lum->u,
1233 &args, sock_info);
1234 else
1235 ret = -ENOSYS;
1236 break;
1237 }
1238 case LTTNG_UST_COUNTER_CPU:
1239 {
1240 /* Receive shm_fd */
1241 ret = ustcomm_recv_counter_shm_from_sessiond(sock,
1242 &args.counter_shm.shm_fd);
1243 if (ret) {
1244 goto error;
1245 }
1246
1247 if (ops->cmd)
1248 ret = ops->cmd(lum->handle, lum->cmd,
1249 (unsigned long) &lum->u,
1250 &args, sock_info);
1251 else
1252 ret = -ENOSYS;
1253 break;
1254 }
8406222c
MD
1255 case LTTNG_UST_EVENT_NOTIFIER_CREATE:
1256 {
1257 /* Receive struct lttng_ust_event_notifier */
1258 struct lttng_ust_event_notifier event_notifier;
1259
1260 if (sizeof(event_notifier) != lum->u.event_notifier.len) {
1261 DBG("incorrect event notifier data message size: %u", lum->u.event_notifier.len);
1262 ret = -EINVAL;
1263 goto error;
1264 }
1265 len = ustcomm_recv_unix_sock(sock, &event_notifier, sizeof(event_notifier));
1266 switch (len) {
1267 case 0: /* orderly shutdown */
1268 ret = 0;
1269 goto error;
1270 default:
1271 if (len == sizeof(event_notifier)) {
1272 DBG("event notifier data received");
1273 break;
1274 } else if (len < 0) {
1275 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
1276 if (len == -ECONNRESET) {
1277 ERR("%s remote end closed connection", sock_info->name);
1278 ret = len;
1279 goto error;
1280 }
1281 ret = len;
1282 goto error;
1283 } else {
1284 DBG("incorrect event notifier data message size: %zd", len);
1285 ret = -EINVAL;
1286 goto error;
1287 }
1288 }
1289 if (ops->cmd)
1290 ret = ops->cmd(lum->handle, lum->cmd,
1291 (unsigned long) &event_notifier,
1292 &args, sock_info);
1293 else
1294 ret = -ENOSYS;
1295 break;
1296 }
ebabbf58 1297
d9e99d10 1298 default:
46050b1a
MD
1299 if (ops->cmd)
1300 ret = ops->cmd(lum->handle, lum->cmd,
ef9ff354 1301 (unsigned long) &lum->u,
f59ed768 1302 &args, sock_info);
46050b1a
MD
1303 else
1304 ret = -ENOSYS;
1305 break;
d9e99d10 1306 }
46050b1a 1307
46050b1a
MD
1308 lur.handle = lum->handle;
1309 lur.cmd = lum->cmd;
1310 lur.ret_val = ret;
1311 if (ret >= 0) {
7bc53e94 1312 lur.ret_code = LTTNG_UST_OK;
46050b1a 1313 } else {
7bc53e94
MD
1314 /*
1315 * Use -LTTNG_UST_ERR as wildcard for UST internal
1316 * error that are not caused by the transport, except if
1317 * we already have a more precise error message to
1318 * report.
1319 */
64b2564e
DG
1320 if (ret > -LTTNG_UST_ERR) {
1321 /* Translate code to UST error. */
1322 switch (ret) {
1323 case -EEXIST:
1324 lur.ret_code = -LTTNG_UST_ERR_EXIST;
1325 break;
1326 case -EINVAL:
1327 lur.ret_code = -LTTNG_UST_ERR_INVAL;
1328 break;
1329 case -ENOENT:
1330 lur.ret_code = -LTTNG_UST_ERR_NOENT;
1331 break;
1332 case -EPERM:
1333 lur.ret_code = -LTTNG_UST_ERR_PERM;
1334 break;
1335 case -ENOSYS:
1336 lur.ret_code = -LTTNG_UST_ERR_NOSYS;
1337 break;
1338 default:
1339 lur.ret_code = -LTTNG_UST_ERR;
1340 break;
1341 }
1342 } else {
7bc53e94 1343 lur.ret_code = ret;
64b2564e 1344 }
46050b1a 1345 }
e6ea14c5
MD
1346 if (ret >= 0) {
1347 switch (lum->cmd) {
e6ea14c5
MD
1348 case LTTNG_UST_TRACER_VERSION:
1349 lur.u.version = lum->u.version;
1350 break;
1351 case LTTNG_UST_TRACEPOINT_LIST_GET:
1352 memcpy(&lur.u.tracepoint, &lum->u.tracepoint, sizeof(lur.u.tracepoint));
1353 break;
1354 }
381c0f1e 1355 }
74d81a6c 1356 DBG("Return value: %d", lur.ret_val);
4c62d8d1
MD
1357
1358 ust_unlock();
1359
1360 /*
1361 * Performed delayed statedump operations outside of the UST
1362 * lock. We need to take the dynamic loader lock before we take
1363 * the UST lock internally within handle_pending_statedump().
1364 */
1365 handle_pending_statedump(sock_info);
1366
1367 if (ust_lock()) {
1368 ret = -LTTNG_UST_ERR_EXITING;
1369 goto error;
1370 }
1371
46050b1a 1372 ret = send_reply(sock, &lur);
193183fb 1373 if (ret < 0) {
7bc53e94 1374 DBG("error sending reply");
193183fb
MD
1375 goto error;
1376 }
46050b1a 1377
40003310
MD
1378 /*
1379 * LTTNG_UST_TRACEPOINT_FIELD_LIST_GET needs to send the field
1380 * after the reply.
1381 */
7bc53e94 1382 if (lur.ret_code == LTTNG_UST_OK) {
40003310
MD
1383 switch (lum->cmd) {
1384 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET:
1385 len = ustcomm_send_unix_sock(sock,
1386 &args.field_list.entry,
1387 sizeof(args.field_list.entry));
7bc53e94
MD
1388 if (len < 0) {
1389 ret = len;
1390 goto error;
1391 }
40003310 1392 if (len != sizeof(args.field_list.entry)) {
7bc53e94 1393 ret = -EINVAL;
40003310
MD
1394 goto error;
1395 }
1396 }
1397 }
ef9ff354 1398
381c0f1e 1399error:
17dfb34b 1400 ust_unlock();
d9e99d10 1401
37dddb65 1402 return ret;
246be17e
PW
1403}
1404
46050b1a 1405static
efe0de09 1406void cleanup_sock_info(struct sock_info *sock_info, int exiting)
46050b1a
MD
1407{
1408 int ret;
1409
5b14aab3
MD
1410 if (sock_info->root_handle != -1) {
1411 ret = lttng_ust_objd_unref(sock_info->root_handle, 1);
1412 if (ret) {
1413 ERR("Error unref root handle");
1414 }
1415 sock_info->root_handle = -1;
1416 }
eb0e6022
GAPG
1417 sock_info->registration_done = 0;
1418 sock_info->initial_statedump_done = 0;
5b14aab3
MD
1419
1420 /*
1421 * wait_shm_mmap, socket and notify socket are used by listener
1422 * threads outside of the ust lock, so we cannot tear them down
1423 * ourselves, because we cannot join on these threads. Leave
1424 * responsibility of cleaning up these resources to the OS
1425 * process exit.
1426 */
1427 if (exiting)
1428 return;
1429
46050b1a 1430 if (sock_info->socket != -1) {
e6973a89 1431 ret = ustcomm_close_unix_sock(sock_info->socket);
46050b1a 1432 if (ret) {
32ce8569 1433 ERR("Error closing ust cmd socket");
46050b1a
MD
1434 }
1435 sock_info->socket = -1;
1436 }
32ce8569
MD
1437 if (sock_info->notify_socket != -1) {
1438 ret = ustcomm_close_unix_sock(sock_info->notify_socket);
1439 if (ret) {
1440 ERR("Error closing ust notify socket");
1441 }
1442 sock_info->notify_socket = -1;
1443 }
5b14aab3 1444 if (sock_info->wait_shm_mmap) {
172d6b68
MD
1445 long page_size;
1446
b72687b8 1447 page_size = LTTNG_UST_PAGE_SIZE;
2657d1ba
MD
1448 if (page_size <= 0) {
1449 if (!page_size) {
1450 errno = EINVAL;
1451 }
1452 PERROR("Error in sysconf(_SC_PAGE_SIZE)");
1453 } else {
172d6b68
MD
1454 ret = munmap(sock_info->wait_shm_mmap, page_size);
1455 if (ret) {
1456 ERR("Error unmapping wait shm");
1457 }
7fc90dca
MD
1458 }
1459 sock_info->wait_shm_mmap = NULL;
1460 }
1461}
1462
58d4b2a2 1463/*
33bbeb90
MD
1464 * Using fork to set umask in the child process (not multi-thread safe).
1465 * We deal with the shm_open vs ftruncate race (happening when the
1466 * sessiond owns the shm and does not let everybody modify it, to ensure
1467 * safety against shm_unlink) by simply letting the mmap fail and
1468 * retrying after a few seconds.
1469 * For global shm, everybody has rw access to it until the sessiond
1470 * starts.
58d4b2a2 1471 */
7fc90dca 1472static
58d4b2a2 1473int get_wait_shm(struct sock_info *sock_info, size_t mmap_size)
7fc90dca 1474{
7fc90dca 1475 int wait_shm_fd, ret;
58d4b2a2 1476 pid_t pid;
44e073f5 1477
58d4b2a2 1478 /*
33bbeb90 1479 * Try to open read-only.
58d4b2a2 1480 */
33bbeb90 1481 wait_shm_fd = shm_open(sock_info->wait_shm_path, O_RDONLY, 0);
58d4b2a2 1482 if (wait_shm_fd >= 0) {
7aa76730
MD
1483 int32_t tmp_read;
1484 ssize_t len;
1485 size_t bytes_read = 0;
1486
1487 /*
1488 * Try to read the fd. If unable to do so, try opening
1489 * it in write mode.
1490 */
1491 do {
1492 len = read(wait_shm_fd,
1493 &((char *) &tmp_read)[bytes_read],
1494 sizeof(tmp_read) - bytes_read);
1495 if (len > 0) {
1496 bytes_read += len;
1497 }
1498 } while ((len < 0 && errno == EINTR)
1499 || (len > 0 && bytes_read < sizeof(tmp_read)));
1500 if (bytes_read != sizeof(tmp_read)) {
1501 ret = close(wait_shm_fd);
1502 if (ret) {
1503 ERR("close wait_shm_fd");
1504 }
1505 goto open_write;
1506 }
58d4b2a2
MD
1507 goto end;
1508 } else if (wait_shm_fd < 0 && errno != ENOENT) {
1509 /*
33bbeb90
MD
1510 * Real-only open did not work, and it's not because the
1511 * entry was not present. It's a failure that prohibits
1512 * using shm.
58d4b2a2 1513 */
7fc90dca 1514 ERR("Error opening shm %s", sock_info->wait_shm_path);
58d4b2a2 1515 goto end;
7fc90dca 1516 }
7aa76730
MD
1517
1518open_write:
7fc90dca 1519 /*
7aa76730
MD
1520 * If the open failed because the file did not exist, or because
1521 * the file was not truncated yet, try creating it ourself.
7fc90dca 1522 */
8c90a710 1523 URCU_TLS(lttng_ust_nest_count)++;
58d4b2a2 1524 pid = fork();
8c90a710 1525 URCU_TLS(lttng_ust_nest_count)--;
58d4b2a2
MD
1526 if (pid > 0) {
1527 int status;
1528
1529 /*
1530 * Parent: wait for child to return, in which case the
1531 * shared memory map will have been created.
1532 */
1533 pid = wait(&status);
b7d3cb32 1534 if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
58d4b2a2
MD
1535 wait_shm_fd = -1;
1536 goto end;
7fc90dca 1537 }
58d4b2a2
MD
1538 /*
1539 * Try to open read-only again after creation.
1540 */
33bbeb90 1541 wait_shm_fd = shm_open(sock_info->wait_shm_path, O_RDONLY, 0);
58d4b2a2
MD
1542 if (wait_shm_fd < 0) {
1543 /*
1544 * Real-only open did not work. It's a failure
1545 * that prohibits using shm.
1546 */
1547 ERR("Error opening shm %s", sock_info->wait_shm_path);
1548 goto end;
1549 }
1550 goto end;
1551 } else if (pid == 0) {
1552 int create_mode;
1553
1554 /* Child */
33bbeb90 1555 create_mode = S_IRUSR | S_IWUSR | S_IRGRP;
58d4b2a2 1556 if (sock_info->global)
33bbeb90 1557 create_mode |= S_IROTH | S_IWGRP | S_IWOTH;
58d4b2a2
MD
1558 /*
1559 * We're alone in a child process, so we can modify the
1560 * process-wide umask.
1561 */
33bbeb90 1562 umask(~create_mode);
58d4b2a2 1563 /*
33bbeb90
MD
1564 * Try creating shm (or get rw access).
1565 * We don't do an exclusive open, because we allow other
1566 * processes to create+ftruncate it concurrently.
58d4b2a2
MD
1567 */
1568 wait_shm_fd = shm_open(sock_info->wait_shm_path,
1569 O_RDWR | O_CREAT, create_mode);
1570 if (wait_shm_fd >= 0) {
1571 ret = ftruncate(wait_shm_fd, mmap_size);
1572 if (ret) {
1573 PERROR("ftruncate");
b0c1425d 1574 _exit(EXIT_FAILURE);
58d4b2a2 1575 }
b0c1425d 1576 _exit(EXIT_SUCCESS);
58d4b2a2 1577 }
33bbeb90
MD
1578 /*
1579 * For local shm, we need to have rw access to accept
1580 * opening it: this means the local sessiond will be
1581 * able to wake us up. For global shm, we open it even
1582 * if rw access is not granted, because the root.root
1583 * sessiond will be able to override all rights and wake
1584 * us up.
1585 */
1586 if (!sock_info->global && errno != EACCES) {
58d4b2a2 1587 ERR("Error opening shm %s", sock_info->wait_shm_path);
5d3bc5ed 1588 _exit(EXIT_FAILURE);
58d4b2a2
MD
1589 }
1590 /*
33bbeb90
MD
1591 * The shm exists, but we cannot open it RW. Report
1592 * success.
58d4b2a2 1593 */
5d3bc5ed 1594 _exit(EXIT_SUCCESS);
58d4b2a2
MD
1595 } else {
1596 return -1;
7fc90dca 1597 }
58d4b2a2 1598end:
33bbeb90
MD
1599 if (wait_shm_fd >= 0 && !sock_info->global) {
1600 struct stat statbuf;
1601
1602 /*
1603 * Ensure that our user is the owner of the shm file for
1604 * local shm. If we do not own the file, it means our
1605 * sessiond will not have access to wake us up (there is
1606 * probably a rogue process trying to fake our
1607 * sessiond). Fallback to polling method in this case.
1608 */
1609 ret = fstat(wait_shm_fd, &statbuf);
1610 if (ret) {
1611 PERROR("fstat");
1612 goto error_close;
1613 }
1614 if (statbuf.st_uid != getuid())
1615 goto error_close;
1616 }
58d4b2a2 1617 return wait_shm_fd;
33bbeb90
MD
1618
1619error_close:
1620 ret = close(wait_shm_fd);
1621 if (ret) {
1622 PERROR("Error closing fd");
1623 }
1624 return -1;
58d4b2a2
MD
1625}
1626
1627static
1628char *get_map_shm(struct sock_info *sock_info)
1629{
172d6b68 1630 long page_size;
58d4b2a2
MD
1631 int wait_shm_fd, ret;
1632 char *wait_shm_mmap;
1633
172d6b68 1634 page_size = sysconf(_SC_PAGE_SIZE);
2657d1ba
MD
1635 if (page_size <= 0) {
1636 if (!page_size) {
1637 errno = EINVAL;
1638 }
1639 PERROR("Error in sysconf(_SC_PAGE_SIZE)");
172d6b68
MD
1640 goto error;
1641 }
1642
6548fca4 1643 lttng_ust_lock_fd_tracker();
172d6b68 1644 wait_shm_fd = get_wait_shm(sock_info, page_size);
58d4b2a2 1645 if (wait_shm_fd < 0) {
6548fca4 1646 lttng_ust_unlock_fd_tracker();
58d4b2a2 1647 goto error;
44e073f5 1648 }
f5c453e9
JR
1649
1650 ret = lttng_ust_add_fd_to_tracker(wait_shm_fd);
1651 if (ret < 0) {
1652 ret = close(wait_shm_fd);
1653 if (!ret) {
1654 PERROR("Error closing fd");
1655 }
1656 lttng_ust_unlock_fd_tracker();
1657 goto error;
1658 }
1659
1660 wait_shm_fd = ret;
6548fca4
MD
1661 lttng_ust_unlock_fd_tracker();
1662
172d6b68 1663 wait_shm_mmap = mmap(NULL, page_size, PROT_READ,
7fc90dca 1664 MAP_SHARED, wait_shm_fd, 0);
6548fca4 1665
7fc90dca 1666 /* close shm fd immediately after taking the mmap reference */
6548fca4 1667 lttng_ust_lock_fd_tracker();
7fc90dca 1668 ret = close(wait_shm_fd);
6548fca4
MD
1669 if (!ret) {
1670 lttng_ust_delete_fd_from_tracker(wait_shm_fd);
1671 } else {
33bbeb90
MD
1672 PERROR("Error closing fd");
1673 }
6548fca4
MD
1674 lttng_ust_unlock_fd_tracker();
1675
33bbeb90
MD
1676 if (wait_shm_mmap == MAP_FAILED) {
1677 DBG("mmap error (can be caused by race with sessiond). Fallback to poll mode.");
1678 goto error;
7fc90dca
MD
1679 }
1680 return wait_shm_mmap;
1681
1682error:
1683 return NULL;
1684}
1685
1686static
1687void wait_for_sessiond(struct sock_info *sock_info)
1688{
060577e3 1689 /* Use ust_lock to check if we should quit. */
3327ac33 1690 if (ust_lock()) {
7fc90dca
MD
1691 goto quit;
1692 }
37ed587a
MD
1693 if (wait_poll_fallback) {
1694 goto error;
1695 }
7fc90dca
MD
1696 ust_unlock();
1697
060577e3
JR
1698 assert(sock_info->wait_shm_mmap);
1699
7fc90dca 1700 DBG("Waiting for %s apps sessiond", sock_info->name);
80e2814b 1701 /* Wait for futex wakeup */
ee7fcec8
MD
1702 if (uatomic_read((int32_t *) sock_info->wait_shm_mmap))
1703 goto end_wait;
1704
10544ee8 1705 while (lttng_ust_futex_async((int32_t *) sock_info->wait_shm_mmap,
ee7fcec8
MD
1706 FUTEX_WAIT, 0, NULL, NULL, 0)) {
1707 switch (errno) {
1708 case EWOULDBLOCK:
1709 /* Value already changed. */
1710 goto end_wait;
1711 case EINTR:
1712 /* Retry if interrupted by signal. */
1713 break; /* Get out of switch. */
1714 case EFAULT:
1715 wait_poll_fallback = 1;
1716 DBG(
37ed587a
MD
1717"Linux kernels 2.6.33 to 3.0 (with the exception of stable versions) "
1718"do not support FUTEX_WAKE on read-only memory mappings correctly. "
1719"Please upgrade your kernel "
1720"(fix is commit 9ea71503a8ed9184d2d0b8ccc4d269d05f7940ae in Linux kernel "
1721"mainline). LTTng-UST will use polling mode fallback.");
ee7fcec8
MD
1722 if (ust_debug())
1723 PERROR("futex");
1724 goto end_wait;
80e2814b
MD
1725 }
1726 }
ee7fcec8 1727end_wait:
7fc90dca
MD
1728 return;
1729
1730quit:
1731 ust_unlock();
1732 return;
1733
1734error:
1735 ust_unlock();
7fc90dca 1736 return;
46050b1a
MD
1737}
1738
1ea11eab
MD
1739/*
1740 * This thread does not allocate any resource, except within
1741 * handle_message, within mutex protection. This mutex protects against
1742 * fork and exit.
98bf993f 1743 * The other moment it allocates resources is at socket connection, which
1ea11eab
MD
1744 * is also protected by the mutex.
1745 */
d9e99d10
MD
1746static
1747void *ust_listener_thread(void *arg)
1748{
1ea11eab 1749 struct sock_info *sock_info = arg;
f5c453e9 1750 int sock, ret, prev_connect_failed = 0, has_waited = 0, fd;
ff517991 1751 long timeout;
d9e99d10 1752
c362addf 1753 lttng_ust_fixup_tls();
01f0e40c
RB
1754 /*
1755 * If available, add '-ust' to the end of this thread's
1756 * process name
1757 */
1758 ret = lttng_ust_setustprocname();
1759 if (ret) {
1760 ERR("Unable to set UST process name");
1761 }
1762
9eb62b9c
MD
1763 /* Restart trying to connect to the session daemon */
1764restart:
c0eedf81
MD
1765 if (prev_connect_failed) {
1766 /* Wait for sessiond availability with pipe */
1767 wait_for_sessiond(sock_info);
1768 if (has_waited) {
1769 has_waited = 0;
1770 /*
1771 * Sleep for 5 seconds before retrying after a
1772 * sequence of failure / wait / failure. This
1773 * deals with a killed or broken session daemon.
1774 */
1775 sleep(5);
eacc4aa4
MD
1776 } else {
1777 has_waited = 1;
c0eedf81 1778 }
c0eedf81
MD
1779 prev_connect_failed = 0;
1780 }
9eb62b9c 1781
101dace0
JR
1782 if (ust_lock()) {
1783 goto quit;
1784 }
1785
1ea11eab 1786 if (sock_info->socket != -1) {
6548fca4 1787 /* FD tracker is updated by ustcomm_close_unix_sock() */
e6973a89 1788 ret = ustcomm_close_unix_sock(sock_info->socket);
1ea11eab 1789 if (ret) {
32ce8569
MD
1790 ERR("Error closing %s ust cmd socket",
1791 sock_info->name);
1ea11eab
MD
1792 }
1793 sock_info->socket = -1;
1794 }
32ce8569 1795 if (sock_info->notify_socket != -1) {
6548fca4 1796 /* FD tracker is updated by ustcomm_close_unix_sock() */
32ce8569
MD
1797 ret = ustcomm_close_unix_sock(sock_info->notify_socket);
1798 if (ret) {
1799 ERR("Error closing %s ust notify socket",
1800 sock_info->name);
1801 }
1802 sock_info->notify_socket = -1;
1803 }
46050b1a 1804
6548fca4 1805
321f2351
MD
1806 /*
1807 * Register. We need to perform both connect and sending
1808 * registration message before doing the next connect otherwise
1809 * we may reach unix socket connect queue max limits and block
1810 * on the 2nd connect while the session daemon is awaiting the
1811 * first connect registration message.
1812 */
1813 /* Connect cmd socket */
6548fca4 1814 lttng_ust_lock_fd_tracker();
451d66b2
MD
1815 ret = ustcomm_connect_unix_sock(sock_info->sock_path,
1816 get_connect_sock_timeout());
321f2351 1817 if (ret < 0) {
6548fca4 1818 lttng_ust_unlock_fd_tracker();
321f2351
MD
1819 DBG("Info: sessiond not accepting connections to %s apps socket", sock_info->name);
1820 prev_connect_failed = 1;
5b14aab3 1821
e3426ddc 1822 /*
321f2351
MD
1823 * If we cannot find the sessiond daemon, don't delay
1824 * constructor execution.
e3426ddc 1825 */
eb0e6022 1826 ret = handle_register_failed(sock_info);
321f2351
MD
1827 assert(!ret);
1828 ust_unlock();
1829 goto restart;
27fe9f21 1830 }
f5c453e9
JR
1831 fd = ret;
1832 ret = lttng_ust_add_fd_to_tracker(fd);
1833 if (ret < 0) {
1834 ret = close(fd);
1835 if (ret) {
1836 PERROR("close on sock_info->socket");
1837 }
1838 ret = -1;
1839 lttng_ust_unlock_fd_tracker();
1840 ust_unlock();
1841 goto quit;
1842 }
1843
321f2351 1844 sock_info->socket = ret;
f5c453e9 1845 lttng_ust_unlock_fd_tracker();
27fe9f21 1846
6548fca4
MD
1847 ust_unlock();
1848 /*
1849 * Unlock/relock ust lock because connect is blocking (with
1850 * timeout). Don't delay constructors on the ust lock for too
1851 * long.
1852 */
3327ac33 1853 if (ust_lock()) {
5b14aab3
MD
1854 goto quit;
1855 }
1856
46050b1a
MD
1857 /*
1858 * Create only one root handle per listener thread for the whole
f59ed768
MD
1859 * process lifetime, so we ensure we get ID which is statically
1860 * assigned to the root handle.
46050b1a
MD
1861 */
1862 if (sock_info->root_handle == -1) {
1863 ret = lttng_abi_create_root_handle();
a51070bb 1864 if (ret < 0) {
46050b1a 1865 ERR("Error creating root handle");
46050b1a
MD
1866 goto quit;
1867 }
1868 sock_info->root_handle = ret;
9eb62b9c 1869 }
1ea11eab 1870
32ce8569 1871 ret = register_to_sessiond(sock_info->socket, USTCTL_SOCKET_CMD);
9eb62b9c 1872 if (ret < 0) {
32ce8569
MD
1873 ERR("Error registering to %s ust cmd socket",
1874 sock_info->name);
c0eedf81 1875 prev_connect_failed = 1;
11ff9c7d
MD
1876 /*
1877 * If we cannot register to the sessiond daemon, don't
1878 * delay constructor execution.
1879 */
eb0e6022 1880 ret = handle_register_failed(sock_info);
11ff9c7d 1881 assert(!ret);
17dfb34b 1882 ust_unlock();
9eb62b9c
MD
1883 goto restart;
1884 }
321f2351
MD
1885
1886 ust_unlock();
6548fca4
MD
1887 /*
1888 * Unlock/relock ust lock because connect is blocking (with
1889 * timeout). Don't delay constructors on the ust lock for too
1890 * long.
1891 */
1892 if (ust_lock()) {
1893 goto quit;
1894 }
321f2351
MD
1895
1896 /* Connect notify socket */
6548fca4 1897 lttng_ust_lock_fd_tracker();
451d66b2
MD
1898 ret = ustcomm_connect_unix_sock(sock_info->sock_path,
1899 get_connect_sock_timeout());
321f2351 1900 if (ret < 0) {
6548fca4 1901 lttng_ust_unlock_fd_tracker();
321f2351
MD
1902 DBG("Info: sessiond not accepting connections to %s apps socket", sock_info->name);
1903 prev_connect_failed = 1;
1904
321f2351
MD
1905 /*
1906 * If we cannot find the sessiond daemon, don't delay
1907 * constructor execution.
1908 */
eb0e6022 1909 ret = handle_register_failed(sock_info);
321f2351
MD
1910 assert(!ret);
1911 ust_unlock();
1912 goto restart;
1913 }
f5c453e9
JR
1914
1915 fd = ret;
1916 ret = lttng_ust_add_fd_to_tracker(fd);
1917 if (ret < 0) {
1918 ret = close(fd);
1919 if (ret) {
1920 PERROR("close on sock_info->notify_socket");
1921 }
1922 ret = -1;
1923 lttng_ust_unlock_fd_tracker();
1924 ust_unlock();
1925 goto quit;
1926 }
1927
321f2351 1928 sock_info->notify_socket = ret;
f5c453e9 1929 lttng_ust_unlock_fd_tracker();
321f2351 1930
6548fca4
MD
1931 ust_unlock();
1932 /*
1933 * Unlock/relock ust lock because connect is blocking (with
1934 * timeout). Don't delay constructors on the ust lock for too
1935 * long.
1936 */
1937 if (ust_lock()) {
1938 goto quit;
1939 }
1940
321f2351
MD
1941 timeout = get_notify_sock_timeout();
1942 if (timeout >= 0) {
1943 /*
1944 * Give at least 10ms to sessiond to reply to
1945 * notifications.
1946 */
1947 if (timeout < 10)
1948 timeout = 10;
1949 ret = ustcomm_setsockopt_rcv_timeout(sock_info->notify_socket,
1950 timeout);
1951 if (ret < 0) {
1952 WARN("Error setting socket receive timeout");
1953 }
1954 ret = ustcomm_setsockopt_snd_timeout(sock_info->notify_socket,
1955 timeout);
1956 if (ret < 0) {
1957 WARN("Error setting socket send timeout");
1958 }
1959 } else if (timeout < -1) {
1960 WARN("Unsupported timeout value %ld", timeout);
1961 }
1962
32ce8569
MD
1963 ret = register_to_sessiond(sock_info->notify_socket,
1964 USTCTL_SOCKET_NOTIFY);
1965 if (ret < 0) {
1966 ERR("Error registering to %s ust notify socket",
1967 sock_info->name);
1968 prev_connect_failed = 1;
1969 /*
1970 * If we cannot register to the sessiond daemon, don't
1971 * delay constructor execution.
1972 */
eb0e6022 1973 ret = handle_register_failed(sock_info);
32ce8569
MD
1974 assert(!ret);
1975 ust_unlock();
1976 goto restart;
1977 }
1978 sock = sock_info->socket;
1979
17dfb34b 1980 ust_unlock();
46050b1a 1981
d9e99d10
MD
1982 for (;;) {
1983 ssize_t len;
57773204 1984 struct ustcomm_ust_msg lum;
d9e99d10 1985
57773204 1986 len = ustcomm_recv_unix_sock(sock, &lum, sizeof(lum));
d9e99d10
MD
1987 switch (len) {
1988 case 0: /* orderly shutdown */
7dd08bec 1989 DBG("%s lttng-sessiond has performed an orderly shutdown", sock_info->name);
3327ac33 1990 if (ust_lock()) {
d5e1fea6
MD
1991 goto quit;
1992 }
8236ba10
MD
1993 /*
1994 * Either sessiond has shutdown or refused us by closing the socket.
1995 * In either case, we don't want to delay construction execution,
1996 * and we need to wait before retry.
1997 */
1998 prev_connect_failed = 1;
1999 /*
2000 * If we cannot register to the sessiond daemon, don't
2001 * delay constructor execution.
2002 */
eb0e6022 2003 ret = handle_register_failed(sock_info);
8236ba10
MD
2004 assert(!ret);
2005 ust_unlock();
d9e99d10 2006 goto end;
e7723462 2007 case sizeof(lum):
74d81a6c 2008 print_cmd(lum.cmd, lum.handle);
11ff9c7d 2009 ret = handle_message(sock_info, sock, &lum);
7bc53e94 2010 if (ret) {
0dafcd63
MD
2011 ERR("Error handling message for %s socket",
2012 sock_info->name);
2013 /*
2014 * Close socket if protocol error is
2015 * detected.
2016 */
2017 goto end;
d9e99d10
MD
2018 }
2019 continue;
7bc53e94
MD
2020 default:
2021 if (len < 0) {
2022 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len);
2023 } else {
2024 DBG("incorrect message size (%s socket): %zd", sock_info->name, len);
2025 }
2026 if (len == -ECONNRESET) {
2027 DBG("%s remote end closed connection", sock_info->name);
d9e99d10
MD
2028 goto end;
2029 }
2030 goto end;
d9e99d10
MD
2031 }
2032
2033 }
2034end:
3327ac33 2035 if (ust_lock()) {
d5e1fea6
MD
2036 goto quit;
2037 }
f59ed768
MD
2038 /* Cleanup socket handles before trying to reconnect */
2039 lttng_ust_objd_table_owner_cleanup(sock_info);
2040 ust_unlock();
9eb62b9c 2041 goto restart; /* try to reconnect */
e33f3265 2042
1ea11eab 2043quit:
e33f3265 2044 ust_unlock();
3327ac33
MD
2045
2046 pthread_mutex_lock(&ust_exit_mutex);
2047 sock_info->thread_active = 0;
2048 pthread_mutex_unlock(&ust_exit_mutex);
d9e99d10
MD
2049 return NULL;
2050}
2051
2594a5b4
MD
2052/*
2053 * Weak symbol to call when the ust malloc wrapper is not loaded.
2054 */
2055__attribute__((weak))
2056void lttng_ust_malloc_wrapper_init(void)
2057{
2058}
2059
2691221a
MD
2060/*
2061 * sessiond monitoring thread: monitor presence of global and per-user
2062 * sessiond by polling the application common named pipe.
2063 */
edaa1431 2064void __attribute__((constructor)) lttng_ust_init(void)
2691221a 2065{
11ff9c7d 2066 struct timespec constructor_timeout;
ae6a58bf 2067 sigset_t sig_all_blocked, orig_parent_mask;
1879f67f 2068 pthread_attr_t thread_attr;
cf12a773 2069 int timeout_mode;
2691221a 2070 int ret;
b2292d85 2071 void *handle;
2691221a 2072
edaa1431
MD
2073 if (uatomic_xchg(&initialized, 1) == 1)
2074 return;
2075
eddd8d5d
MD
2076 /*
2077 * Fixup interdependency between TLS fixup mutex (which happens
2078 * to be the dynamic linker mutex) and ust_lock, taken within
2079 * the ust lock.
2080 */
c362addf 2081 lttng_ust_fixup_tls();
eddd8d5d 2082
07b57e5e
MD
2083 lttng_ust_loaded = 1;
2084
b2292d85
FD
2085 /*
2086 * We need to ensure that the liblttng-ust library is not unloaded to avoid
2087 * the unloading of code used by the ust_listener_threads as we can not
2088 * reliably know when they exited. To do that, manually load
2089 * liblttng-ust.so to increment the dynamic loader's internal refcount for
2090 * this library so it never becomes zero, thus never gets unloaded from the
2091 * address space of the process. Since we are already running in the
2092 * constructor of the LTTNG_UST_LIB_SO_NAME library, calling dlopen will
2093 * simply increment the refcount and no additionnal work is needed by the
2094 * dynamic loader as the shared library is already loaded in the address
2095 * space. As a safe guard, we use the RTLD_NODELETE flag to prevent
2096 * unloading of the UST library if its refcount becomes zero (which should
2097 * never happen). Do the return value check but discard the handle at the
2098 * end of the function as it's not needed.
2099 */
2100 handle = dlopen(LTTNG_UST_LIB_SO_NAME, RTLD_LAZY | RTLD_NODELETE);
2101 if (!handle) {
2102 ERR("dlopen of liblttng-ust shared library (%s).", LTTNG_UST_LIB_SO_NAME);
2103 }
2104
edaa1431
MD
2105 /*
2106 * We want precise control over the order in which we construct
2107 * our sub-libraries vs starting to receive commands from
2108 * sessiond (otherwise leading to errors when trying to create
2109 * sessiond before the init functions are completed).
2110 */
2691221a 2111 init_usterr();
6f626d28 2112 lttng_ust_getenv_init(); /* Needs init_usterr() to be completed. */
edaa1431 2113 init_tracepoint();
6548fca4 2114 lttng_ust_init_fd_tracker();
f9364363 2115 lttng_ust_clock_init();
5e1b7b8b 2116 lttng_ust_getcpu_init();
cf73e0fe 2117 lttng_ust_statedump_init();
7dd08bec
MD
2118 lttng_ring_buffer_metadata_client_init();
2119 lttng_ring_buffer_client_overwrite_init();
34a91bdb 2120 lttng_ring_buffer_client_overwrite_rt_init();
7dd08bec 2121 lttng_ring_buffer_client_discard_init();
34a91bdb 2122 lttng_ring_buffer_client_discard_rt_init();
ebabbf58
MD
2123 lttng_counter_client_percpu_32_modular_init();
2124 lttng_counter_client_percpu_64_modular_init();
d58d1454 2125 lttng_perf_counter_init();
2594a5b4
MD
2126 /*
2127 * Invoke ust malloc wrapper init before starting other threads.
2128 */
2129 lttng_ust_malloc_wrapper_init();
2691221a 2130
ff517991 2131 timeout_mode = get_constructor_timeout(&constructor_timeout);
11ff9c7d 2132
b2c5f61a 2133 get_allow_blocking();
6f97f9c2 2134
95259bd0 2135 ret = sem_init(&constructor_wait, 0, 0);
8aadb54a
MD
2136 if (ret) {
2137 PERROR("sem_init");
2138 }
11ff9c7d 2139
060577e3
JR
2140 ret = setup_global_apps();
2141 if (ret) {
2142 assert(global_apps.allowed == 0);
2143 DBG("global apps setup returned %d", ret);
2144 }
2145
8d20bf54 2146 ret = setup_local_apps();
2691221a 2147 if (ret) {
060577e3 2148 assert(local_apps.allowed == 0);
9ec6895c 2149 DBG("local apps setup returned %d", ret);
2691221a 2150 }
ae6a58bf
WP
2151
2152 /* A new thread created by pthread_create inherits the signal mask
2153 * from the parent. To avoid any signal being received by the
2154 * listener thread, we block all signals temporarily in the parent,
2155 * while we create the listener thread.
2156 */
2157 sigfillset(&sig_all_blocked);
2158 ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_parent_mask);
2159 if (ret) {
d94d802c 2160 ERR("pthread_sigmask: %s", strerror(ret));
ae6a58bf
WP
2161 }
2162
1879f67f
MG
2163 ret = pthread_attr_init(&thread_attr);
2164 if (ret) {
2165 ERR("pthread_attr_init: %s", strerror(ret));
2166 }
2167 ret = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
2168 if (ret) {
2169 ERR("pthread_attr_setdetachstate: %s", strerror(ret));
2170 }
2171
060577e3
JR
2172 if (global_apps.allowed) {
2173 pthread_mutex_lock(&ust_exit_mutex);
2174 ret = pthread_create(&global_apps.ust_listener, &thread_attr,
2175 ust_listener_thread, &global_apps);
2176 if (ret) {
2177 ERR("pthread_create global: %s", strerror(ret));
2178 }
2179 global_apps.thread_active = 1;
2180 pthread_mutex_unlock(&ust_exit_mutex);
2181 } else {
2182 handle_register_done(&global_apps);
d94d802c 2183 }
e33f3265 2184
8d20bf54 2185 if (local_apps.allowed) {
c0bbbd5a 2186 pthread_mutex_lock(&ust_exit_mutex);
1879f67f 2187 ret = pthread_create(&local_apps.ust_listener, &thread_attr,
dde70ea0 2188 ust_listener_thread, &local_apps);
d94d802c
MD
2189 if (ret) {
2190 ERR("pthread_create local: %s", strerror(ret));
2191 }
e33f3265 2192 local_apps.thread_active = 1;
c0bbbd5a 2193 pthread_mutex_unlock(&ust_exit_mutex);
8d20bf54
MD
2194 } else {
2195 handle_register_done(&local_apps);
2196 }
1879f67f
MG
2197 ret = pthread_attr_destroy(&thread_attr);
2198 if (ret) {
2199 ERR("pthread_attr_destroy: %s", strerror(ret));
2200 }
8d20bf54 2201
ae6a58bf
WP
2202 /* Restore original signal mask in parent */
2203 ret = pthread_sigmask(SIG_SETMASK, &orig_parent_mask, NULL);
2204 if (ret) {
d94d802c 2205 ERR("pthread_sigmask: %s", strerror(ret));
ae6a58bf
WP
2206 }
2207
cf12a773
MD
2208 switch (timeout_mode) {
2209 case 1: /* timeout wait */
95259bd0
MD
2210 do {
2211 ret = sem_timedwait(&constructor_wait,
2212 &constructor_timeout);
2213 } while (ret < 0 && errno == EINTR);
8aadb54a
MD
2214 if (ret < 0) {
2215 switch (errno) {
2216 case ETIMEDOUT:
2217 ERR("Timed out waiting for lttng-sessiond");
2218 break;
2219 case EINVAL:
2220 PERROR("sem_timedwait");
2221 break;
2222 default:
2223 ERR("Unexpected error \"%s\" returned by sem_timedwait",
2224 strerror(errno));
2225 }
cf12a773
MD
2226 }
2227 break;
7b766b16 2228 case -1:/* wait forever */
95259bd0
MD
2229 do {
2230 ret = sem_wait(&constructor_wait);
2231 } while (ret < 0 && errno == EINTR);
8aadb54a
MD
2232 if (ret < 0) {
2233 switch (errno) {
2234 case EINVAL:
2235 PERROR("sem_wait");
2236 break;
2237 default:
2238 ERR("Unexpected error \"%s\" returned by sem_wait",
2239 strerror(errno));
2240 }
2241 }
cf12a773 2242 break;
7b766b16 2243 case 0: /* no timeout */
cf12a773 2244 break;
11ff9c7d 2245 }
2691221a
MD
2246}
2247
17dfb34b
MD
2248static
2249void lttng_ust_cleanup(int exiting)
2250{
efe0de09 2251 cleanup_sock_info(&global_apps, exiting);
932cfadb 2252 cleanup_sock_info(&local_apps, exiting);
74f98bc9 2253 local_apps.allowed = 0;
060577e3 2254 global_apps.allowed = 0;
efe0de09
MD
2255 /*
2256 * The teardown in this function all affect data structures
2257 * accessed under the UST lock by the listener thread. This
2258 * lock, along with the lttng_ust_comm_should_quit flag, ensure
2259 * that none of these threads are accessing this data at this
2260 * point.
2261 */
17dfb34b 2262 lttng_ust_abi_exit();
003fedf4 2263 lttng_ust_events_exit();
d58d1454 2264 lttng_perf_counter_exit();
34a91bdb 2265 lttng_ring_buffer_client_discard_rt_exit();
7dd08bec 2266 lttng_ring_buffer_client_discard_exit();
34a91bdb 2267 lttng_ring_buffer_client_overwrite_rt_exit();
7dd08bec
MD
2268 lttng_ring_buffer_client_overwrite_exit();
2269 lttng_ring_buffer_metadata_client_exit();
ebabbf58
MD
2270 lttng_counter_client_percpu_32_modular_exit();
2271 lttng_counter_client_percpu_64_modular_exit();
cf73e0fe 2272 lttng_ust_statedump_destroy();
17dfb34b
MD
2273 exit_tracepoint();
2274 if (!exiting) {
2275 /* Reinitialize values for fork */
eb0e6022 2276 sem_count = sem_count_initial_value;
17dfb34b
MD
2277 lttng_ust_comm_should_quit = 0;
2278 initialized = 0;
2279 }
2280}
2281
edaa1431 2282void __attribute__((destructor)) lttng_ust_exit(void)
2691221a
MD
2283{
2284 int ret;
2285
9eb62b9c
MD
2286 /*
2287 * Using pthread_cancel here because:
2288 * A) we don't want to hang application teardown.
2289 * B) the thread is not allocating any resource.
2290 */
1ea11eab
MD
2291
2292 /*
2293 * Require the communication thread to quit. Synchronize with
2294 * mutexes to ensure it is not in a mutex critical section when
2295 * pthread_cancel is later called.
2296 */
3327ac33 2297 ust_lock_nocheck();
1ea11eab 2298 lttng_ust_comm_should_quit = 1;
3327ac33 2299 ust_unlock();
1ea11eab 2300
3327ac33 2301 pthread_mutex_lock(&ust_exit_mutex);
f5f94532 2302 /* cancel threads */
e33f3265
MD
2303 if (global_apps.thread_active) {
2304 ret = pthread_cancel(global_apps.ust_listener);
2305 if (ret) {
2306 ERR("Error cancelling global ust listener thread: %s",
2307 strerror(ret));
2308 } else {
2309 global_apps.thread_active = 0;
2310 }
2691221a 2311 }
e33f3265 2312 if (local_apps.thread_active) {
8d20bf54
MD
2313 ret = pthread_cancel(local_apps.ust_listener);
2314 if (ret) {
d94d802c
MD
2315 ERR("Error cancelling local ust listener thread: %s",
2316 strerror(ret));
e33f3265
MD
2317 } else {
2318 local_apps.thread_active = 0;
8d20bf54 2319 }
8d20bf54 2320 }
3327ac33 2321 pthread_mutex_unlock(&ust_exit_mutex);
e33f3265 2322
efe0de09
MD
2323 /*
2324 * Do NOT join threads: use of sys_futex makes it impossible to
2325 * join the threads without using async-cancel, but async-cancel
2326 * is delivered by a signal, which could hit the target thread
2327 * anywhere in its code path, including while the ust_lock() is
2328 * held, causing a deadlock for the other thread. Let the OS
2329 * cleanup the threads if there are stalled in a syscall.
2330 */
17dfb34b 2331 lttng_ust_cleanup(1);
2691221a 2332}
e822f505 2333
735bef47
MJ
2334static
2335void ust_context_ns_reset(void)
2336{
2337 lttng_context_pid_ns_reset();
2338 lttng_context_cgroup_ns_reset();
2339 lttng_context_ipc_ns_reset();
2340 lttng_context_mnt_ns_reset();
2341 lttng_context_net_ns_reset();
2342 lttng_context_user_ns_reset();
cefef7a7 2343 lttng_context_time_ns_reset();
735bef47
MJ
2344 lttng_context_uts_ns_reset();
2345}
2346
fca2f191
MJ
2347static
2348void ust_context_vuids_reset(void)
2349{
2350 lttng_context_vuid_reset();
2351 lttng_context_veuid_reset();
2352 lttng_context_vsuid_reset();
2353}
2354
2355static
2356void ust_context_vgids_reset(void)
2357{
2358 lttng_context_vgid_reset();
2359 lttng_context_vegid_reset();
2360 lttng_context_vsgid_reset();
2361}
2362
e822f505
MD
2363/*
2364 * We exclude the worker threads across fork and clone (except
2365 * CLONE_VM), because these system calls only keep the forking thread
2366 * running in the child. Therefore, we don't want to call fork or clone
2367 * in the middle of an tracepoint or ust tracing state modification.
2368 * Holding this mutex protects these structures across fork and clone.
2369 */
b728d87e 2370void ust_before_fork(sigset_t *save_sigset)
e822f505
MD
2371{
2372 /*
2373 * Disable signals. This is to avoid that the child intervenes
2374 * before it is properly setup for tracing. It is safer to
2375 * disable all signals, because then we know we are not breaking
2376 * anything by restoring the original mask.
2377 */
2378 sigset_t all_sigs;
2379 int ret;
2380
c362addf
MD
2381 /* Fixup lttng-ust TLS. */
2382 lttng_ust_fixup_tls();
2383
8c90a710 2384 if (URCU_TLS(lttng_ust_nest_count))
e8508a49 2385 return;
e822f505
MD
2386 /* Disable signals */
2387 sigfillset(&all_sigs);
b728d87e 2388 ret = sigprocmask(SIG_BLOCK, &all_sigs, save_sigset);
e822f505
MD
2389 if (ret == -1) {
2390 PERROR("sigprocmask");
2391 }
458d678c
PW
2392
2393 pthread_mutex_lock(&ust_fork_mutex);
2394
3327ac33 2395 ust_lock_nocheck();
10544ee8
MD
2396 lttng_ust_urcu_before_fork();
2397 if (lttng_ust_liburcu_bp_before_fork)
2398 lttng_ust_liburcu_bp_before_fork();
c1be081a 2399 lttng_ust_lock_fd_tracker();
20142124 2400 lttng_perf_lock();
e822f505
MD
2401}
2402
b728d87e 2403static void ust_after_fork_common(sigset_t *restore_sigset)
e822f505
MD
2404{
2405 int ret;
2406
17dfb34b 2407 DBG("process %d", getpid());
20142124 2408 lttng_perf_unlock();
c1be081a 2409 lttng_ust_unlock_fd_tracker();
17dfb34b 2410 ust_unlock();
458d678c
PW
2411
2412 pthread_mutex_unlock(&ust_fork_mutex);
2413
e822f505 2414 /* Restore signals */
23c8854a 2415 ret = sigprocmask(SIG_SETMASK, restore_sigset, NULL);
e822f505
MD
2416 if (ret == -1) {
2417 PERROR("sigprocmask");
2418 }
2419}
2420
b728d87e 2421void ust_after_fork_parent(sigset_t *restore_sigset)
e822f505 2422{
8c90a710 2423 if (URCU_TLS(lttng_ust_nest_count))
e8508a49 2424 return;
17dfb34b 2425 DBG("process %d", getpid());
10544ee8
MD
2426 lttng_ust_urcu_after_fork_parent();
2427 if (lttng_ust_liburcu_bp_after_fork_parent)
2428 lttng_ust_liburcu_bp_after_fork_parent();
e822f505 2429 /* Release mutexes and reenable signals */
b728d87e 2430 ust_after_fork_common(restore_sigset);
e822f505
MD
2431}
2432
17dfb34b
MD
2433/*
2434 * After fork, in the child, we need to cleanup all the leftover state,
2435 * except the worker thread which already magically disappeared thanks
2436 * to the weird Linux fork semantics. After tyding up, we call
2437 * lttng_ust_init() again to start over as a new PID.
2438 *
2439 * This is meant for forks() that have tracing in the child between the
2440 * fork and following exec call (if there is any).
2441 */
b728d87e 2442void ust_after_fork_child(sigset_t *restore_sigset)
e822f505 2443{
8c90a710 2444 if (URCU_TLS(lttng_ust_nest_count))
e8508a49 2445 return;
06b16a0b 2446 lttng_context_vpid_reset();
8478887d 2447 lttng_context_vtid_reset();
46228a6f 2448 lttng_context_procname_reset();
735bef47 2449 ust_context_ns_reset();
fca2f191
MJ
2450 ust_context_vuids_reset();
2451 ust_context_vgids_reset();
17dfb34b 2452 DBG("process %d", getpid());
e822f505 2453 /* Release urcu mutexes */
10544ee8
MD
2454 lttng_ust_urcu_after_fork_child();
2455 if (lttng_ust_liburcu_bp_after_fork_child)
2456 lttng_ust_liburcu_bp_after_fork_child();
17dfb34b 2457 lttng_ust_cleanup(0);
e822f505 2458 /* Release mutexes and reenable signals */
b728d87e 2459 ust_after_fork_common(restore_sigset);
318dfea9 2460 lttng_ust_init();
e822f505 2461}
95c25348 2462
735bef47
MJ
2463void ust_after_setns(void)
2464{
2465 ust_context_ns_reset();
fca2f191
MJ
2466 ust_context_vuids_reset();
2467 ust_context_vgids_reset();
735bef47
MJ
2468}
2469
2470void ust_after_unshare(void)
2471{
2472 ust_context_ns_reset();
fca2f191
MJ
2473 ust_context_vuids_reset();
2474 ust_context_vgids_reset();
2475}
2476
2477void ust_after_setuid(void)
2478{
2479 ust_context_vuids_reset();
2480}
2481
2482void ust_after_seteuid(void)
2483{
2484 ust_context_vuids_reset();
2485}
2486
2487void ust_after_setreuid(void)
2488{
2489 ust_context_vuids_reset();
2490}
2491
2492void ust_after_setresuid(void)
2493{
2494 ust_context_vuids_reset();
2495}
2496
2497void ust_after_setgid(void)
2498{
2499 ust_context_vgids_reset();
2500}
2501
2502void ust_after_setegid(void)
2503{
2504 ust_context_vgids_reset();
2505}
2506
2507void ust_after_setregid(void)
2508{
2509 ust_context_vgids_reset();
2510}
2511
2512void ust_after_setresgid(void)
2513{
2514 ust_context_vgids_reset();
735bef47
MJ
2515}
2516
246be17e 2517void lttng_ust_sockinfo_session_enabled(void *owner)
95c25348
PW
2518{
2519 struct sock_info *sock_info = owner;
37dddb65 2520 sock_info->statedump_pending = 1;
95c25348 2521}
This page took 0.169859 seconds and 4 git commands to generate.