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