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