4 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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
24 #include <sys/types.h>
25 #include <sys/socket.h>
28 #include <sys/types.h>
34 #include <semaphore.h>
38 #include <urcu/uatomic.h>
39 #include <urcu/futex.h>
40 #include <urcu/compiler.h>
42 #include <lttng/ust-events.h>
43 #include <lttng/ust-abi.h>
44 #include <lttng/ust.h>
45 #include <lttng/ust-error.h>
46 #include <lttng/ust-ctl.h>
47 #include <urcu/tls-compat.h>
50 #include <usterr-signal-safe.h>
52 #include "tracepoint-internal.h"
53 #include "lttng-tracer-core.h"
55 #include "../libringbuffer/tlsfixup.h"
56 #include "lttng-ust-statedump.h"
58 #include "../libringbuffer/getcpu.h"
62 * Has lttng ust comm constructor been called ?
64 static int initialized
;
67 * The ust_lock/ust_unlock lock is used as a communication thread mutex.
68 * Held when handling a command, also held by fork() to deal with
69 * removal of threads, and by exit path.
71 * The UST lock is the centralized mutex across UST tracing control and
74 * ust_exit_mutex must never nest in ust_mutex.
76 * ust_fork_mutex must never nest in ust_mutex.
78 * ust_mutex_nest is a per-thread nesting counter, allowing the perf
79 * counter lazy initialization called by events within the statedump,
80 * which traces while the ust_mutex is held.
82 * ust_lock nests within the dynamic loader lock (within glibc) because
83 * it is taken within the library constructor.
85 static pthread_mutex_t ust_mutex
= PTHREAD_MUTEX_INITIALIZER
;
87 /* Allow nesting the ust_mutex within the same thread. */
88 static DEFINE_URCU_TLS(int, ust_mutex_nest
);
91 * ust_exit_mutex protects thread_active variable wrt thread exit. It
92 * cannot be done by ust_mutex because pthread_cancel(), which takes an
93 * internal libc lock, cannot nest within ust_mutex.
95 * It never nests within a ust_mutex.
97 static pthread_mutex_t ust_exit_mutex
= PTHREAD_MUTEX_INITIALIZER
;
100 * ust_fork_mutex protects base address statedump tracing against forks. It
101 * prevents the dynamic loader lock to be taken (by base address statedump
102 * tracing) while a fork is happening, thus preventing deadlock issues with
103 * the dynamic loader lock.
105 static pthread_mutex_t ust_fork_mutex
= PTHREAD_MUTEX_INITIALIZER
;
107 /* Should the ust comm thread quit ? */
108 static int lttng_ust_comm_should_quit
;
111 * This variable can be tested by applications to check whether
112 * lttng-ust is loaded. They simply have to define their own
113 * "lttng_ust_loaded" weak symbol, and test it. It is set to 1 by the
114 * library constructor.
116 int lttng_ust_loaded
__attribute__((weak
));
119 * Return 0 on success, -1 if should quit.
120 * The lock is taken in both cases.
125 sigset_t sig_all_blocked
, orig_mask
;
128 ret
= pthread_setcancelstate(PTHREAD_CANCEL_DISABLE
, &oldstate
);
130 ERR("pthread_setcancelstate: %s", strerror(ret
));
132 if (oldstate
!= PTHREAD_CANCEL_ENABLE
) {
133 ERR("pthread_setcancelstate: unexpected oldstate");
135 sigfillset(&sig_all_blocked
);
136 ret
= pthread_sigmask(SIG_SETMASK
, &sig_all_blocked
, &orig_mask
);
138 ERR("pthread_sigmask: %s", strerror(ret
));
140 if (!URCU_TLS(ust_mutex_nest
)++)
141 pthread_mutex_lock(&ust_mutex
);
142 ret
= pthread_sigmask(SIG_SETMASK
, &orig_mask
, NULL
);
144 ERR("pthread_sigmask: %s", strerror(ret
));
146 if (lttng_ust_comm_should_quit
) {
154 * ust_lock_nocheck() can be used in constructors/destructors, because
155 * they are already nested within the dynamic loader lock, and therefore
156 * have exclusive access against execution of liblttng-ust destructor.
159 void ust_lock_nocheck(void)
161 sigset_t sig_all_blocked
, orig_mask
;
164 ret
= pthread_setcancelstate(PTHREAD_CANCEL_DISABLE
, &oldstate
);
166 ERR("pthread_setcancelstate: %s", strerror(ret
));
168 if (oldstate
!= PTHREAD_CANCEL_ENABLE
) {
169 ERR("pthread_setcancelstate: unexpected oldstate");
171 sigfillset(&sig_all_blocked
);
172 ret
= pthread_sigmask(SIG_SETMASK
, &sig_all_blocked
, &orig_mask
);
174 ERR("pthread_sigmask: %s", strerror(ret
));
176 if (!URCU_TLS(ust_mutex_nest
)++)
177 pthread_mutex_lock(&ust_mutex
);
178 ret
= pthread_sigmask(SIG_SETMASK
, &orig_mask
, NULL
);
180 ERR("pthread_sigmask: %s", strerror(ret
));
187 void ust_unlock(void)
189 sigset_t sig_all_blocked
, orig_mask
;
192 sigfillset(&sig_all_blocked
);
193 ret
= pthread_sigmask(SIG_SETMASK
, &sig_all_blocked
, &orig_mask
);
195 ERR("pthread_sigmask: %s", strerror(ret
));
197 if (!--URCU_TLS(ust_mutex_nest
))
198 pthread_mutex_unlock(&ust_mutex
);
199 ret
= pthread_sigmask(SIG_SETMASK
, &orig_mask
, NULL
);
201 ERR("pthread_sigmask: %s", strerror(ret
));
203 ret
= pthread_setcancelstate(PTHREAD_CANCEL_ENABLE
, &oldstate
);
205 ERR("pthread_setcancelstate: %s", strerror(ret
));
207 if (oldstate
!= PTHREAD_CANCEL_DISABLE
) {
208 ERR("pthread_setcancelstate: unexpected oldstate");
213 * Wait for either of these before continuing to the main
215 * - the register_done message from sessiond daemon
216 * (will let the sessiond daemon enable sessions before main
218 * - sessiond daemon is not reachable.
219 * - timeout (ensuring applications are resilient to session
222 static sem_t constructor_wait
;
224 * Doing this for both the global and local sessiond.
226 static int sem_count
= { 2 };
229 * Counting nesting within lttng-ust. Used to ensure that calling fork()
230 * from liblttng-ust does not execute the pre/post fork handlers.
232 static DEFINE_URCU_TLS(int, lttng_ust_nest_count
);
235 * Info about socket and associated listener thread.
239 pthread_t ust_listener
; /* listener thread */
241 int constructor_sem_posted
;
246 char sock_path
[PATH_MAX
];
250 char wait_shm_path
[PATH_MAX
];
252 /* Keep track of lazy state dump not performed yet. */
253 int statedump_pending
;
256 /* Socket from app (connect) to session daemon (listen) for communication */
257 struct sock_info global_apps
= {
265 .sock_path
= LTTNG_DEFAULT_RUNDIR
"/" LTTNG_UST_SOCK_FILENAME
,
269 .wait_shm_path
= "/" LTTNG_UST_WAIT_FILENAME
,
271 .statedump_pending
= 0,
274 /* TODO: allow global_apps_sock_path override */
276 struct sock_info local_apps
= {
280 .allowed
= 0, /* Check setuid bit first */
286 .statedump_pending
= 0,
289 static int wait_poll_fallback
;
291 static const char *cmd_name_mapping
[] = {
292 [ LTTNG_UST_RELEASE
] = "Release",
293 [ LTTNG_UST_SESSION
] = "Create Session",
294 [ LTTNG_UST_TRACER_VERSION
] = "Get Tracer Version",
296 [ LTTNG_UST_TRACEPOINT_LIST
] = "Create Tracepoint List",
297 [ LTTNG_UST_WAIT_QUIESCENT
] = "Wait for Quiescent State",
298 [ LTTNG_UST_REGISTER_DONE
] = "Registration Done",
299 [ LTTNG_UST_TRACEPOINT_FIELD_LIST
] = "Create Tracepoint Field List",
301 /* Session FD commands */
302 [ LTTNG_UST_CHANNEL
] = "Create Channel",
303 [ LTTNG_UST_SESSION_START
] = "Start Session",
304 [ LTTNG_UST_SESSION_STOP
] = "Stop Session",
306 /* Channel FD commands */
307 [ LTTNG_UST_STREAM
] = "Create Stream",
308 [ LTTNG_UST_EVENT
] = "Create Event",
310 /* Event and Channel FD commands */
311 [ LTTNG_UST_CONTEXT
] = "Create Context",
312 [ LTTNG_UST_FLUSH_BUFFER
] = "Flush Buffer",
314 /* Event, Channel and Session commands */
315 [ LTTNG_UST_ENABLE
] = "Enable",
316 [ LTTNG_UST_DISABLE
] = "Disable",
318 /* Tracepoint list commands */
319 [ LTTNG_UST_TRACEPOINT_LIST_GET
] = "List Next Tracepoint",
320 [ LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
] = "List Next Tracepoint Field",
322 /* Event FD commands */
323 [ LTTNG_UST_FILTER
] = "Create Filter",
324 [ LTTNG_UST_EXCLUSION
] = "Add exclusions to event",
327 static const char *str_timeout
;
328 static int got_timeout_env
;
330 extern void lttng_ring_buffer_client_overwrite_init(void);
331 extern void lttng_ring_buffer_client_overwrite_rt_init(void);
332 extern void lttng_ring_buffer_client_discard_init(void);
333 extern void lttng_ring_buffer_client_discard_rt_init(void);
334 extern void lttng_ring_buffer_metadata_client_init(void);
335 extern void lttng_ring_buffer_client_overwrite_exit(void);
336 extern void lttng_ring_buffer_client_overwrite_rt_exit(void);
337 extern void lttng_ring_buffer_client_discard_exit(void);
338 extern void lttng_ring_buffer_client_discard_rt_exit(void);
339 extern void lttng_ring_buffer_metadata_client_exit(void);
341 ssize_t
lttng_ust_read(int fd
, void *buf
, size_t len
)
344 size_t copied
= 0, to_copy
= len
;
347 ret
= read(fd
, buf
+ copied
, to_copy
);
352 } while ((ret
> 0 && to_copy
> 0)
353 || (ret
< 0 && errno
== EINTR
));
360 * Returns the HOME directory path. Caller MUST NOT free(3) the returned
364 const char *get_lttng_home_dir(void)
368 val
= (const char *) lttng_getenv("LTTNG_HOME");
372 return (const char *) lttng_getenv("HOME");
376 * Force a read (imply TLS fixup for dlopen) of TLS variables.
379 void lttng_fixup_nest_count_tls(void)
381 asm volatile ("" : : "m" (URCU_TLS(lttng_ust_nest_count
)));
385 void lttng_fixup_ust_mutex_nest_tls(void)
387 asm volatile ("" : : "m" (URCU_TLS(ust_mutex_nest
)));
394 void lttng_fixup_urcu_bp_tls(void)
400 void lttng_ust_fixup_tls(void)
402 lttng_fixup_urcu_bp_tls();
403 lttng_fixup_ringbuffer_tls();
404 lttng_fixup_vtid_tls();
405 lttng_fixup_nest_count_tls();
406 lttng_fixup_procname_tls();
407 lttng_fixup_ust_mutex_nest_tls();
408 lttng_ust_fixup_fd_tracker_tls();
411 int lttng_get_notify_socket(void *owner
)
413 struct sock_info
*info
= owner
;
415 return info
->notify_socket
;
419 void print_cmd(int cmd
, int handle
)
421 const char *cmd_name
= "Unknown";
423 if (cmd
>= 0 && cmd
< LTTNG_ARRAY_SIZE(cmd_name_mapping
)
424 && cmd_name_mapping
[cmd
]) {
425 cmd_name
= cmd_name_mapping
[cmd
];
427 DBG("Message Received \"%s\" (%d), Handle \"%s\" (%d)",
429 lttng_ust_obj_get_name(handle
), handle
);
433 int setup_local_apps(void)
435 const char *home_dir
;
440 * Disallow per-user tracing for setuid binaries.
442 if (uid
!= geteuid()) {
443 assert(local_apps
.allowed
== 0);
446 home_dir
= get_lttng_home_dir();
448 WARN("HOME environment variable not set. Disabling LTTng-UST per-user tracing.");
449 assert(local_apps
.allowed
== 0);
452 local_apps
.allowed
= 1;
453 snprintf(local_apps
.sock_path
, PATH_MAX
, "%s/%s/%s",
455 LTTNG_DEFAULT_HOME_RUNDIR
,
456 LTTNG_UST_SOCK_FILENAME
);
457 snprintf(local_apps
.wait_shm_path
, PATH_MAX
, "/%s-%u",
458 LTTNG_UST_WAIT_FILENAME
,
464 * Get socket timeout, in ms.
465 * -1: wait forever. 0: don't wait. >0: timeout, in ms.
468 long get_timeout(void)
470 long constructor_delay_ms
= LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS
;
472 if (!got_timeout_env
) {
473 str_timeout
= lttng_getenv("LTTNG_UST_REGISTER_TIMEOUT");
477 constructor_delay_ms
= strtol(str_timeout
, NULL
, 10);
478 /* All negative values are considered as "-1". */
479 if (constructor_delay_ms
< -1)
480 constructor_delay_ms
= -1;
481 return constructor_delay_ms
;
484 /* Timeout for notify socket send and recv. */
486 long get_notify_sock_timeout(void)
488 return get_timeout();
491 /* Timeout for connecting to cmd and notify sockets. */
493 long get_connect_sock_timeout(void)
495 return get_timeout();
499 * Return values: -1: wait forever. 0: don't wait. 1: timeout wait.
502 int get_constructor_timeout(struct timespec
*constructor_timeout
)
504 long constructor_delay_ms
;
507 constructor_delay_ms
= get_timeout();
509 switch (constructor_delay_ms
) {
510 case -1:/* fall-through */
512 return constructor_delay_ms
;
518 * If we are unable to find the current time, don't wait.
520 ret
= clock_gettime(CLOCK_REALTIME
, constructor_timeout
);
525 constructor_timeout
->tv_sec
+= constructor_delay_ms
/ 1000UL;
526 constructor_timeout
->tv_nsec
+=
527 (constructor_delay_ms
% 1000UL) * 1000000UL;
528 if (constructor_timeout
->tv_nsec
>= 1000000000UL) {
529 constructor_timeout
->tv_sec
++;
530 constructor_timeout
->tv_nsec
-= 1000000000UL;
532 /* Timeout wait (constructor_delay_ms). */
537 int register_to_sessiond(int socket
, enum ustctl_socket_type type
)
539 return ustcomm_send_reg_msg(socket
,
542 lttng_alignof(uint8_t) * CHAR_BIT
,
543 lttng_alignof(uint16_t) * CHAR_BIT
,
544 lttng_alignof(uint32_t) * CHAR_BIT
,
545 lttng_alignof(uint64_t) * CHAR_BIT
,
546 lttng_alignof(unsigned long) * CHAR_BIT
);
550 int send_reply(int sock
, struct ustcomm_ust_reply
*lur
)
554 len
= ustcomm_send_unix_sock(sock
, lur
, sizeof(*lur
));
557 DBG("message successfully sent");
560 if (len
== -ECONNRESET
) {
561 DBG("remote end closed connection");
566 DBG("incorrect message size: %zd", len
);
572 int handle_register_done(struct sock_info
*sock_info
)
576 if (sock_info
->constructor_sem_posted
)
578 sock_info
->constructor_sem_posted
= 1;
579 if (uatomic_read(&sem_count
) <= 0) {
582 ret
= uatomic_add_return(&sem_count
, -1);
584 ret
= sem_post(&constructor_wait
);
591 * Only execute pending statedump after the constructor semaphore has
592 * been posted by each listener thread. This means statedump will only
593 * be performed after the "registration done" command is received from
594 * each session daemon the application is connected to.
596 * This ensures we don't run into deadlock issues with the dynamic
597 * loader mutex, which is held while the constructor is called and
598 * waiting on the constructor semaphore. All operations requiring this
599 * dynamic loader lock need to be postponed using this mechanism.
602 void handle_pending_statedump(struct sock_info
*sock_info
)
604 int ctor_passed
= sock_info
->constructor_sem_posted
;
606 if (ctor_passed
&& sock_info
->statedump_pending
) {
607 sock_info
->statedump_pending
= 0;
608 pthread_mutex_lock(&ust_fork_mutex
);
609 lttng_handle_pending_statedump(sock_info
);
610 pthread_mutex_unlock(&ust_fork_mutex
);
615 int handle_message(struct sock_info
*sock_info
,
616 int sock
, struct ustcomm_ust_msg
*lum
)
619 const struct lttng_ust_objd_ops
*ops
;
620 struct ustcomm_ust_reply lur
;
622 char ctxstr
[LTTNG_UST_SYM_NAME_LEN
]; /* App context string. */
625 memset(&lur
, 0, sizeof(lur
));
628 ret
= -LTTNG_UST_ERR_EXITING
;
632 ops
= objd_ops(lum
->handle
);
639 case LTTNG_UST_REGISTER_DONE
:
640 if (lum
->handle
== LTTNG_UST_ROOT_HANDLE
)
641 ret
= handle_register_done(sock_info
);
645 case LTTNG_UST_RELEASE
:
646 if (lum
->handle
== LTTNG_UST_ROOT_HANDLE
)
649 ret
= lttng_ust_objd_unref(lum
->handle
, 1);
651 case LTTNG_UST_FILTER
:
653 /* Receive filter data */
654 struct lttng_ust_filter_bytecode_node
*bytecode
;
656 if (lum
->u
.filter
.data_size
> FILTER_BYTECODE_MAX_LEN
) {
657 ERR("Filter data size is too large: %u bytes",
658 lum
->u
.filter
.data_size
);
663 if (lum
->u
.filter
.reloc_offset
> lum
->u
.filter
.data_size
) {
664 ERR("Filter reloc offset %u is not within data",
665 lum
->u
.filter
.reloc_offset
);
670 bytecode
= zmalloc(sizeof(*bytecode
) + lum
->u
.filter
.data_size
);
675 len
= ustcomm_recv_unix_sock(sock
, bytecode
->bc
.data
,
676 lum
->u
.filter
.data_size
);
678 case 0: /* orderly shutdown */
683 if (len
== lum
->u
.filter
.data_size
) {
684 DBG("filter data received");
686 } else if (len
< 0) {
687 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len
);
688 if (len
== -ECONNRESET
) {
689 ERR("%s remote end closed connection", sock_info
->name
);
698 DBG("incorrect filter data message size: %zd", len
);
704 bytecode
->bc
.len
= lum
->u
.filter
.data_size
;
705 bytecode
->bc
.reloc_offset
= lum
->u
.filter
.reloc_offset
;
706 bytecode
->bc
.seqnum
= lum
->u
.filter
.seqnum
;
708 ret
= ops
->cmd(lum
->handle
, lum
->cmd
,
709 (unsigned long) bytecode
,
714 /* don't free bytecode if everything went fine. */
721 case LTTNG_UST_EXCLUSION
:
723 /* Receive exclusion names */
724 struct lttng_ust_excluder_node
*node
;
727 count
= lum
->u
.exclusion
.count
;
729 /* There are no names to read */
733 node
= zmalloc(sizeof(*node
) +
734 count
* LTTNG_UST_SYM_NAME_LEN
);
739 node
->excluder
.count
= count
;
740 len
= ustcomm_recv_unix_sock(sock
, node
->excluder
.names
,
741 count
* LTTNG_UST_SYM_NAME_LEN
);
743 case 0: /* orderly shutdown */
748 if (len
== count
* LTTNG_UST_SYM_NAME_LEN
) {
749 DBG("Exclusion data received");
751 } else if (len
< 0) {
752 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len
);
753 if (len
== -ECONNRESET
) {
754 ERR("%s remote end closed connection", sock_info
->name
);
763 DBG("Incorrect exclusion data message size: %zd", len
);
770 ret
= ops
->cmd(lum
->handle
, lum
->cmd
,
771 (unsigned long) node
,
776 /* Don't free exclusion data if everything went fine. */
783 case LTTNG_UST_CHANNEL
:
788 len
= ustcomm_recv_channel_from_sessiond(sock
,
789 &chan_data
, lum
->u
.channel
.len
,
792 case 0: /* orderly shutdown */
796 if (len
== lum
->u
.channel
.len
) {
797 DBG("channel data received");
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
);
809 DBG("incorrect channel data message size: %zd", len
);
814 args
.channel
.chan_data
= chan_data
;
815 args
.channel
.wakeup_fd
= wakeup_fd
;
817 ret
= ops
->cmd(lum
->handle
, lum
->cmd
,
818 (unsigned long) &lum
->u
,
824 case LTTNG_UST_STREAM
:
826 /* Receive shm_fd, wakeup_fd */
827 ret
= ustcomm_recv_stream_from_sessiond(sock
,
830 &args
.stream
.wakeup_fd
);
835 ret
= ops
->cmd(lum
->handle
, lum
->cmd
,
836 (unsigned long) &lum
->u
,
842 case LTTNG_UST_CONTEXT
:
843 switch (lum
->u
.context
.ctx
) {
844 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
847 size_t ctxlen
, recvlen
;
849 ctxlen
= strlen("$app.") + lum
->u
.context
.u
.app_ctx
.provider_name_len
- 1
850 + strlen(":") + lum
->u
.context
.u
.app_ctx
.ctx_name_len
;
851 if (ctxlen
>= LTTNG_UST_SYM_NAME_LEN
) {
852 ERR("Application context string length size is too large: %zu bytes",
857 strcpy(ctxstr
, "$app.");
858 p
= &ctxstr
[strlen("$app.")];
859 recvlen
= ctxlen
- strlen("$app.");
860 len
= ustcomm_recv_unix_sock(sock
, p
, recvlen
);
862 case 0: /* orderly shutdown */
866 if (len
== recvlen
) {
867 DBG("app context data received");
869 } else if (len
< 0) {
870 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len
);
871 if (len
== -ECONNRESET
) {
872 ERR("%s remote end closed connection", sock_info
->name
);
879 DBG("incorrect app context data message size: %zd", len
);
884 /* Put : between provider and ctxname. */
885 p
[lum
->u
.context
.u
.app_ctx
.provider_name_len
- 1] = ':';
886 args
.app_context
.ctxname
= ctxstr
;
893 ret
= ops
->cmd(lum
->handle
, lum
->cmd
,
894 (unsigned long) &lum
->u
,
902 ret
= ops
->cmd(lum
->handle
, lum
->cmd
,
903 (unsigned long) &lum
->u
,
910 lur
.handle
= lum
->handle
;
914 lur
.ret_code
= LTTNG_UST_OK
;
917 * Use -LTTNG_UST_ERR as wildcard for UST internal
918 * error that are not caused by the transport, except if
919 * we already have a more precise error message to
922 if (ret
> -LTTNG_UST_ERR
) {
923 /* Translate code to UST error. */
926 lur
.ret_code
= -LTTNG_UST_ERR_EXIST
;
929 lur
.ret_code
= -LTTNG_UST_ERR_INVAL
;
932 lur
.ret_code
= -LTTNG_UST_ERR_NOENT
;
935 lur
.ret_code
= -LTTNG_UST_ERR_PERM
;
938 lur
.ret_code
= -LTTNG_UST_ERR_NOSYS
;
941 lur
.ret_code
= -LTTNG_UST_ERR
;
950 case LTTNG_UST_TRACER_VERSION
:
951 lur
.u
.version
= lum
->u
.version
;
953 case LTTNG_UST_TRACEPOINT_LIST_GET
:
954 memcpy(&lur
.u
.tracepoint
, &lum
->u
.tracepoint
, sizeof(lur
.u
.tracepoint
));
958 DBG("Return value: %d", lur
.ret_val
);
963 * Performed delayed statedump operations outside of the UST
964 * lock. We need to take the dynamic loader lock before we take
965 * the UST lock internally within handle_pending_statedump().
967 handle_pending_statedump(sock_info
);
970 ret
= -LTTNG_UST_ERR_EXITING
;
974 ret
= send_reply(sock
, &lur
);
976 DBG("error sending reply");
981 * LTTNG_UST_TRACEPOINT_FIELD_LIST_GET needs to send the field
984 if (lur
.ret_code
== LTTNG_UST_OK
) {
986 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
987 len
= ustcomm_send_unix_sock(sock
,
988 &args
.field_list
.entry
,
989 sizeof(args
.field_list
.entry
));
994 if (len
!= sizeof(args
.field_list
.entry
)) {
1008 void cleanup_sock_info(struct sock_info
*sock_info
, int exiting
)
1012 if (sock_info
->root_handle
!= -1) {
1013 ret
= lttng_ust_objd_unref(sock_info
->root_handle
, 1);
1015 ERR("Error unref root handle");
1017 sock_info
->root_handle
= -1;
1019 sock_info
->constructor_sem_posted
= 0;
1022 * wait_shm_mmap, socket and notify socket are used by listener
1023 * threads outside of the ust lock, so we cannot tear them down
1024 * ourselves, because we cannot join on these threads. Leave
1025 * responsibility of cleaning up these resources to the OS
1031 if (sock_info
->socket
!= -1) {
1032 ret
= ustcomm_close_unix_sock(sock_info
->socket
);
1034 ERR("Error closing ust cmd socket");
1036 sock_info
->socket
= -1;
1038 if (sock_info
->notify_socket
!= -1) {
1039 ret
= ustcomm_close_unix_sock(sock_info
->notify_socket
);
1041 ERR("Error closing ust notify socket");
1043 sock_info
->notify_socket
= -1;
1045 if (sock_info
->wait_shm_mmap
) {
1048 page_size
= sysconf(_SC_PAGE_SIZE
);
1049 if (page_size
<= 0) {
1053 PERROR("Error in sysconf(_SC_PAGE_SIZE)");
1055 ret
= munmap(sock_info
->wait_shm_mmap
, page_size
);
1057 ERR("Error unmapping wait shm");
1060 sock_info
->wait_shm_mmap
= NULL
;
1065 * Using fork to set umask in the child process (not multi-thread safe).
1066 * We deal with the shm_open vs ftruncate race (happening when the
1067 * sessiond owns the shm and does not let everybody modify it, to ensure
1068 * safety against shm_unlink) by simply letting the mmap fail and
1069 * retrying after a few seconds.
1070 * For global shm, everybody has rw access to it until the sessiond
1074 int get_wait_shm(struct sock_info
*sock_info
, size_t mmap_size
)
1076 int wait_shm_fd
, ret
;
1080 * Try to open read-only.
1082 wait_shm_fd
= shm_open(sock_info
->wait_shm_path
, O_RDONLY
, 0);
1083 if (wait_shm_fd
>= 0) {
1086 size_t bytes_read
= 0;
1089 * Try to read the fd. If unable to do so, try opening
1093 len
= read(wait_shm_fd
,
1094 &((char *) &tmp_read
)[bytes_read
],
1095 sizeof(tmp_read
) - bytes_read
);
1099 } while ((len
< 0 && errno
== EINTR
)
1100 || (len
> 0 && bytes_read
< sizeof(tmp_read
)));
1101 if (bytes_read
!= sizeof(tmp_read
)) {
1102 ret
= close(wait_shm_fd
);
1104 ERR("close wait_shm_fd");
1109 } else if (wait_shm_fd
< 0 && errno
!= ENOENT
) {
1111 * Real-only open did not work, and it's not because the
1112 * entry was not present. It's a failure that prohibits
1115 ERR("Error opening shm %s", sock_info
->wait_shm_path
);
1121 * If the open failed because the file did not exist, or because
1122 * the file was not truncated yet, try creating it ourself.
1124 URCU_TLS(lttng_ust_nest_count
)++;
1126 URCU_TLS(lttng_ust_nest_count
)--;
1131 * Parent: wait for child to return, in which case the
1132 * shared memory map will have been created.
1134 pid
= wait(&status
);
1135 if (pid
< 0 || !WIFEXITED(status
) || WEXITSTATUS(status
) != 0) {
1140 * Try to open read-only again after creation.
1142 wait_shm_fd
= shm_open(sock_info
->wait_shm_path
, O_RDONLY
, 0);
1143 if (wait_shm_fd
< 0) {
1145 * Real-only open did not work. It's a failure
1146 * that prohibits using shm.
1148 ERR("Error opening shm %s", sock_info
->wait_shm_path
);
1152 } else if (pid
== 0) {
1156 create_mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
;
1157 if (sock_info
->global
)
1158 create_mode
|= S_IROTH
| S_IWGRP
| S_IWOTH
;
1160 * We're alone in a child process, so we can modify the
1161 * process-wide umask.
1163 umask(~create_mode
);
1165 * Try creating shm (or get rw access).
1166 * We don't do an exclusive open, because we allow other
1167 * processes to create+ftruncate it concurrently.
1169 wait_shm_fd
= shm_open(sock_info
->wait_shm_path
,
1170 O_RDWR
| O_CREAT
, create_mode
);
1171 if (wait_shm_fd
>= 0) {
1172 ret
= ftruncate(wait_shm_fd
, mmap_size
);
1174 PERROR("ftruncate");
1175 _exit(EXIT_FAILURE
);
1177 _exit(EXIT_SUCCESS
);
1180 * For local shm, we need to have rw access to accept
1181 * opening it: this means the local sessiond will be
1182 * able to wake us up. For global shm, we open it even
1183 * if rw access is not granted, because the root.root
1184 * sessiond will be able to override all rights and wake
1187 if (!sock_info
->global
&& errno
!= EACCES
) {
1188 ERR("Error opening shm %s", sock_info
->wait_shm_path
);
1189 _exit(EXIT_FAILURE
);
1192 * The shm exists, but we cannot open it RW. Report
1195 _exit(EXIT_SUCCESS
);
1200 if (wait_shm_fd
>= 0 && !sock_info
->global
) {
1201 struct stat statbuf
;
1204 * Ensure that our user is the owner of the shm file for
1205 * local shm. If we do not own the file, it means our
1206 * sessiond will not have access to wake us up (there is
1207 * probably a rogue process trying to fake our
1208 * sessiond). Fallback to polling method in this case.
1210 ret
= fstat(wait_shm_fd
, &statbuf
);
1215 if (statbuf
.st_uid
!= getuid())
1221 ret
= close(wait_shm_fd
);
1223 PERROR("Error closing fd");
1229 char *get_map_shm(struct sock_info
*sock_info
)
1232 int wait_shm_fd
, ret
;
1233 char *wait_shm_mmap
;
1235 page_size
= sysconf(_SC_PAGE_SIZE
);
1236 if (page_size
<= 0) {
1240 PERROR("Error in sysconf(_SC_PAGE_SIZE)");
1244 lttng_ust_lock_fd_tracker();
1245 wait_shm_fd
= get_wait_shm(sock_info
, page_size
);
1246 if (wait_shm_fd
< 0) {
1247 lttng_ust_unlock_fd_tracker();
1251 ret
= lttng_ust_add_fd_to_tracker(wait_shm_fd
);
1253 ret
= close(wait_shm_fd
);
1255 PERROR("Error closing fd");
1257 lttng_ust_unlock_fd_tracker();
1262 lttng_ust_unlock_fd_tracker();
1264 wait_shm_mmap
= mmap(NULL
, page_size
, PROT_READ
,
1265 MAP_SHARED
, wait_shm_fd
, 0);
1267 /* close shm fd immediately after taking the mmap reference */
1268 lttng_ust_lock_fd_tracker();
1269 ret
= close(wait_shm_fd
);
1271 lttng_ust_delete_fd_from_tracker(wait_shm_fd
);
1273 PERROR("Error closing fd");
1275 lttng_ust_unlock_fd_tracker();
1277 if (wait_shm_mmap
== MAP_FAILED
) {
1278 DBG("mmap error (can be caused by race with sessiond). Fallback to poll mode.");
1281 return wait_shm_mmap
;
1288 void wait_for_sessiond(struct sock_info
*sock_info
)
1293 if (wait_poll_fallback
) {
1296 if (!sock_info
->wait_shm_mmap
) {
1297 sock_info
->wait_shm_mmap
= get_map_shm(sock_info
);
1298 if (!sock_info
->wait_shm_mmap
)
1303 DBG("Waiting for %s apps sessiond", sock_info
->name
);
1304 /* Wait for futex wakeup */
1305 if (uatomic_read((int32_t *) sock_info
->wait_shm_mmap
))
1308 while (futex_async((int32_t *) sock_info
->wait_shm_mmap
,
1309 FUTEX_WAIT
, 0, NULL
, NULL
, 0)) {
1312 /* Value already changed. */
1315 /* Retry if interrupted by signal. */
1316 break; /* Get out of switch. */
1318 wait_poll_fallback
= 1;
1320 "Linux kernels 2.6.33 to 3.0 (with the exception of stable versions) "
1321 "do not support FUTEX_WAKE on read-only memory mappings correctly. "
1322 "Please upgrade your kernel "
1323 "(fix is commit 9ea71503a8ed9184d2d0b8ccc4d269d05f7940ae in Linux kernel "
1324 "mainline). LTTng-UST will use polling mode fallback.");
1343 * This thread does not allocate any resource, except within
1344 * handle_message, within mutex protection. This mutex protects against
1346 * The other moment it allocates resources is at socket connection, which
1347 * is also protected by the mutex.
1350 void *ust_listener_thread(void *arg
)
1352 struct sock_info
*sock_info
= arg
;
1353 int sock
, ret
, prev_connect_failed
= 0, has_waited
= 0, fd
;
1356 lttng_ust_fixup_tls();
1358 * If available, add '-ust' to the end of this thread's
1361 ret
= lttng_ust_setustprocname();
1363 ERR("Unable to set UST process name");
1366 /* Restart trying to connect to the session daemon */
1368 if (prev_connect_failed
) {
1369 /* Wait for sessiond availability with pipe */
1370 wait_for_sessiond(sock_info
);
1374 * Sleep for 5 seconds before retrying after a
1375 * sequence of failure / wait / failure. This
1376 * deals with a killed or broken session daemon.
1382 prev_connect_failed
= 0;
1385 if (sock_info
->socket
!= -1) {
1386 /* FD tracker is updated by ustcomm_close_unix_sock() */
1387 ret
= ustcomm_close_unix_sock(sock_info
->socket
);
1389 ERR("Error closing %s ust cmd socket",
1392 sock_info
->socket
= -1;
1394 if (sock_info
->notify_socket
!= -1) {
1395 /* FD tracker is updated by ustcomm_close_unix_sock() */
1396 ret
= ustcomm_close_unix_sock(sock_info
->notify_socket
);
1398 ERR("Error closing %s ust notify socket",
1401 sock_info
->notify_socket
= -1;
1409 * Register. We need to perform both connect and sending
1410 * registration message before doing the next connect otherwise
1411 * we may reach unix socket connect queue max limits and block
1412 * on the 2nd connect while the session daemon is awaiting the
1413 * first connect registration message.
1415 /* Connect cmd socket */
1416 lttng_ust_lock_fd_tracker();
1417 ret
= ustcomm_connect_unix_sock(sock_info
->sock_path
,
1418 get_connect_sock_timeout());
1420 lttng_ust_unlock_fd_tracker();
1421 DBG("Info: sessiond not accepting connections to %s apps socket", sock_info
->name
);
1422 prev_connect_failed
= 1;
1425 * If we cannot find the sessiond daemon, don't delay
1426 * constructor execution.
1428 ret
= handle_register_done(sock_info
);
1434 ret
= lttng_ust_add_fd_to_tracker(fd
);
1438 PERROR("close on sock_info->socket");
1441 lttng_ust_unlock_fd_tracker();
1446 sock_info
->socket
= ret
;
1447 lttng_ust_unlock_fd_tracker();
1451 * Unlock/relock ust lock because connect is blocking (with
1452 * timeout). Don't delay constructors on the ust lock for too
1460 * Create only one root handle per listener thread for the whole
1461 * process lifetime, so we ensure we get ID which is statically
1462 * assigned to the root handle.
1464 if (sock_info
->root_handle
== -1) {
1465 ret
= lttng_abi_create_root_handle();
1467 ERR("Error creating root handle");
1470 sock_info
->root_handle
= ret
;
1473 ret
= register_to_sessiond(sock_info
->socket
, USTCTL_SOCKET_CMD
);
1475 ERR("Error registering to %s ust cmd socket",
1477 prev_connect_failed
= 1;
1479 * If we cannot register to the sessiond daemon, don't
1480 * delay constructor execution.
1482 ret
= handle_register_done(sock_info
);
1490 * Unlock/relock ust lock because connect is blocking (with
1491 * timeout). Don't delay constructors on the ust lock for too
1498 /* Connect notify socket */
1499 lttng_ust_lock_fd_tracker();
1500 ret
= ustcomm_connect_unix_sock(sock_info
->sock_path
,
1501 get_connect_sock_timeout());
1503 lttng_ust_unlock_fd_tracker();
1504 DBG("Info: sessiond not accepting connections to %s apps socket", sock_info
->name
);
1505 prev_connect_failed
= 1;
1508 * If we cannot find the sessiond daemon, don't delay
1509 * constructor execution.
1511 ret
= handle_register_done(sock_info
);
1518 ret
= lttng_ust_add_fd_to_tracker(fd
);
1522 PERROR("close on sock_info->notify_socket");
1525 lttng_ust_unlock_fd_tracker();
1530 sock_info
->notify_socket
= ret
;
1531 lttng_ust_unlock_fd_tracker();
1535 * Unlock/relock ust lock because connect is blocking (with
1536 * timeout). Don't delay constructors on the ust lock for too
1543 timeout
= get_notify_sock_timeout();
1546 * Give at least 10ms to sessiond to reply to
1551 ret
= ustcomm_setsockopt_rcv_timeout(sock_info
->notify_socket
,
1554 WARN("Error setting socket receive timeout");
1556 ret
= ustcomm_setsockopt_snd_timeout(sock_info
->notify_socket
,
1559 WARN("Error setting socket send timeout");
1561 } else if (timeout
< -1) {
1562 WARN("Unsupported timeout value %ld", timeout
);
1565 ret
= register_to_sessiond(sock_info
->notify_socket
,
1566 USTCTL_SOCKET_NOTIFY
);
1568 ERR("Error registering to %s ust notify socket",
1570 prev_connect_failed
= 1;
1572 * If we cannot register to the sessiond daemon, don't
1573 * delay constructor execution.
1575 ret
= handle_register_done(sock_info
);
1580 sock
= sock_info
->socket
;
1586 struct ustcomm_ust_msg lum
;
1588 len
= ustcomm_recv_unix_sock(sock
, &lum
, sizeof(lum
));
1590 case 0: /* orderly shutdown */
1591 DBG("%s lttng-sessiond has performed an orderly shutdown", sock_info
->name
);
1596 * Either sessiond has shutdown or refused us by closing the socket.
1597 * In either case, we don't want to delay construction execution,
1598 * and we need to wait before retry.
1600 prev_connect_failed
= 1;
1602 * If we cannot register to the sessiond daemon, don't
1603 * delay constructor execution.
1605 ret
= handle_register_done(sock_info
);
1610 print_cmd(lum
.cmd
, lum
.handle
);
1611 ret
= handle_message(sock_info
, sock
, &lum
);
1613 ERR("Error handling message for %s socket",
1616 * Close socket if protocol error is
1624 DBG("Receive failed from lttng-sessiond with errno %d", (int) -len
);
1626 DBG("incorrect message size (%s socket): %zd", sock_info
->name
, len
);
1628 if (len
== -ECONNRESET
) {
1629 DBG("%s remote end closed connection", sock_info
->name
);
1640 /* Cleanup socket handles before trying to reconnect */
1641 lttng_ust_objd_table_owner_cleanup(sock_info
);
1643 goto restart
; /* try to reconnect */
1648 pthread_mutex_lock(&ust_exit_mutex
);
1649 sock_info
->thread_active
= 0;
1650 pthread_mutex_unlock(&ust_exit_mutex
);
1655 * Weak symbol to call when the ust malloc wrapper is not loaded.
1657 __attribute__((weak
))
1658 void lttng_ust_malloc_wrapper_init(void)
1663 * sessiond monitoring thread: monitor presence of global and per-user
1664 * sessiond by polling the application common named pipe.
1666 void __attribute__((constructor
)) lttng_ust_init(void)
1668 struct timespec constructor_timeout
;
1669 sigset_t sig_all_blocked
, orig_parent_mask
;
1670 pthread_attr_t thread_attr
;
1674 if (uatomic_xchg(&initialized
, 1) == 1)
1678 * Fixup interdependency between TLS fixup mutex (which happens
1679 * to be the dynamic linker mutex) and ust_lock, taken within
1682 lttng_ust_fixup_tls();
1684 lttng_ust_loaded
= 1;
1687 * We want precise control over the order in which we construct
1688 * our sub-libraries vs starting to receive commands from
1689 * sessiond (otherwise leading to errors when trying to create
1690 * sessiond before the init functions are completed).
1693 lttng_ust_getenv_init(); /* Needs init_usterr() to be completed. */
1695 lttng_ust_init_fd_tracker();
1696 lttng_ust_clock_init();
1697 lttng_ust_getcpu_init();
1698 lttng_ust_statedump_init();
1699 lttng_ring_buffer_metadata_client_init();
1700 lttng_ring_buffer_client_overwrite_init();
1701 lttng_ring_buffer_client_overwrite_rt_init();
1702 lttng_ring_buffer_client_discard_init();
1703 lttng_ring_buffer_client_discard_rt_init();
1704 lttng_perf_counter_init();
1706 * Invoke ust malloc wrapper init before starting other threads.
1708 lttng_ust_malloc_wrapper_init();
1710 timeout_mode
= get_constructor_timeout(&constructor_timeout
);
1712 ret
= sem_init(&constructor_wait
, 0, 0);
1717 ret
= setup_local_apps();
1719 DBG("local apps setup returned %d", ret
);
1722 /* A new thread created by pthread_create inherits the signal mask
1723 * from the parent. To avoid any signal being received by the
1724 * listener thread, we block all signals temporarily in the parent,
1725 * while we create the listener thread.
1727 sigfillset(&sig_all_blocked
);
1728 ret
= pthread_sigmask(SIG_SETMASK
, &sig_all_blocked
, &orig_parent_mask
);
1730 ERR("pthread_sigmask: %s", strerror(ret
));
1733 ret
= pthread_attr_init(&thread_attr
);
1735 ERR("pthread_attr_init: %s", strerror(ret
));
1737 ret
= pthread_attr_setdetachstate(&thread_attr
, PTHREAD_CREATE_DETACHED
);
1739 ERR("pthread_attr_setdetachstate: %s", strerror(ret
));
1742 pthread_mutex_lock(&ust_exit_mutex
);
1743 ret
= pthread_create(&global_apps
.ust_listener
, &thread_attr
,
1744 ust_listener_thread
, &global_apps
);
1746 ERR("pthread_create global: %s", strerror(ret
));
1748 global_apps
.thread_active
= 1;
1749 pthread_mutex_unlock(&ust_exit_mutex
);
1751 if (local_apps
.allowed
) {
1752 pthread_mutex_lock(&ust_exit_mutex
);
1753 ret
= pthread_create(&local_apps
.ust_listener
, &thread_attr
,
1754 ust_listener_thread
, &local_apps
);
1756 ERR("pthread_create local: %s", strerror(ret
));
1758 local_apps
.thread_active
= 1;
1759 pthread_mutex_unlock(&ust_exit_mutex
);
1761 handle_register_done(&local_apps
);
1763 ret
= pthread_attr_destroy(&thread_attr
);
1765 ERR("pthread_attr_destroy: %s", strerror(ret
));
1768 /* Restore original signal mask in parent */
1769 ret
= pthread_sigmask(SIG_SETMASK
, &orig_parent_mask
, NULL
);
1771 ERR("pthread_sigmask: %s", strerror(ret
));
1774 switch (timeout_mode
) {
1775 case 1: /* timeout wait */
1777 ret
= sem_timedwait(&constructor_wait
,
1778 &constructor_timeout
);
1779 } while (ret
< 0 && errno
== EINTR
);
1783 ERR("Timed out waiting for lttng-sessiond");
1786 PERROR("sem_timedwait");
1789 ERR("Unexpected error \"%s\" returned by sem_timedwait",
1794 case -1:/* wait forever */
1796 ret
= sem_wait(&constructor_wait
);
1797 } while (ret
< 0 && errno
== EINTR
);
1804 ERR("Unexpected error \"%s\" returned by sem_wait",
1809 case 0: /* no timeout */
1815 void lttng_ust_cleanup(int exiting
)
1817 cleanup_sock_info(&global_apps
, exiting
);
1818 cleanup_sock_info(&local_apps
, exiting
);
1819 local_apps
.allowed
= 0;
1821 * The teardown in this function all affect data structures
1822 * accessed under the UST lock by the listener thread. This
1823 * lock, along with the lttng_ust_comm_should_quit flag, ensure
1824 * that none of these threads are accessing this data at this
1827 lttng_ust_abi_exit();
1828 lttng_ust_events_exit();
1829 lttng_perf_counter_exit();
1830 lttng_ring_buffer_client_discard_rt_exit();
1831 lttng_ring_buffer_client_discard_exit();
1832 lttng_ring_buffer_client_overwrite_rt_exit();
1833 lttng_ring_buffer_client_overwrite_exit();
1834 lttng_ring_buffer_metadata_client_exit();
1835 lttng_ust_statedump_destroy();
1838 /* Reinitialize values for fork */
1840 lttng_ust_comm_should_quit
= 0;
1845 void __attribute__((destructor
)) lttng_ust_exit(void)
1850 * Using pthread_cancel here because:
1851 * A) we don't want to hang application teardown.
1852 * B) the thread is not allocating any resource.
1856 * Require the communication thread to quit. Synchronize with
1857 * mutexes to ensure it is not in a mutex critical section when
1858 * pthread_cancel is later called.
1861 lttng_ust_comm_should_quit
= 1;
1864 pthread_mutex_lock(&ust_exit_mutex
);
1865 /* cancel threads */
1866 if (global_apps
.thread_active
) {
1867 ret
= pthread_cancel(global_apps
.ust_listener
);
1869 ERR("Error cancelling global ust listener thread: %s",
1872 global_apps
.thread_active
= 0;
1875 if (local_apps
.thread_active
) {
1876 ret
= pthread_cancel(local_apps
.ust_listener
);
1878 ERR("Error cancelling local ust listener thread: %s",
1881 local_apps
.thread_active
= 0;
1884 pthread_mutex_unlock(&ust_exit_mutex
);
1887 * Do NOT join threads: use of sys_futex makes it impossible to
1888 * join the threads without using async-cancel, but async-cancel
1889 * is delivered by a signal, which could hit the target thread
1890 * anywhere in its code path, including while the ust_lock() is
1891 * held, causing a deadlock for the other thread. Let the OS
1892 * cleanup the threads if there are stalled in a syscall.
1894 lttng_ust_cleanup(1);
1898 * We exclude the worker threads across fork and clone (except
1899 * CLONE_VM), because these system calls only keep the forking thread
1900 * running in the child. Therefore, we don't want to call fork or clone
1901 * in the middle of an tracepoint or ust tracing state modification.
1902 * Holding this mutex protects these structures across fork and clone.
1904 void ust_before_fork(sigset_t
*save_sigset
)
1907 * Disable signals. This is to avoid that the child intervenes
1908 * before it is properly setup for tracing. It is safer to
1909 * disable all signals, because then we know we are not breaking
1910 * anything by restoring the original mask.
1915 /* Fixup lttng-ust TLS. */
1916 lttng_ust_fixup_tls();
1918 if (URCU_TLS(lttng_ust_nest_count
))
1920 /* Disable signals */
1921 sigfillset(&all_sigs
);
1922 ret
= sigprocmask(SIG_BLOCK
, &all_sigs
, save_sigset
);
1924 PERROR("sigprocmask");
1927 pthread_mutex_lock(&ust_fork_mutex
);
1930 rcu_bp_before_fork();
1933 static void ust_after_fork_common(sigset_t
*restore_sigset
)
1937 DBG("process %d", getpid());
1940 pthread_mutex_unlock(&ust_fork_mutex
);
1942 /* Restore signals */
1943 ret
= sigprocmask(SIG_SETMASK
, restore_sigset
, NULL
);
1945 PERROR("sigprocmask");
1949 void ust_after_fork_parent(sigset_t
*restore_sigset
)
1951 if (URCU_TLS(lttng_ust_nest_count
))
1953 DBG("process %d", getpid());
1954 rcu_bp_after_fork_parent();
1955 /* Release mutexes and reenable signals */
1956 ust_after_fork_common(restore_sigset
);
1960 * After fork, in the child, we need to cleanup all the leftover state,
1961 * except the worker thread which already magically disappeared thanks
1962 * to the weird Linux fork semantics. After tyding up, we call
1963 * lttng_ust_init() again to start over as a new PID.
1965 * This is meant for forks() that have tracing in the child between the
1966 * fork and following exec call (if there is any).
1968 void ust_after_fork_child(sigset_t
*restore_sigset
)
1970 if (URCU_TLS(lttng_ust_nest_count
))
1972 lttng_context_vtid_reset();
1973 DBG("process %d", getpid());
1974 /* Release urcu mutexes */
1975 rcu_bp_after_fork_child();
1976 lttng_ust_cleanup(0);
1977 /* Release mutexes and reenable signals */
1978 ust_after_fork_common(restore_sigset
);
1982 void lttng_ust_sockinfo_session_enabled(void *owner
)
1984 struct sock_info
*sock_info
= owner
;
1985 sock_info
->statedump_pending
= 1;