From: Mathieu Desnoyers Date: Tue, 12 Jul 2016 20:28:45 +0000 (-0400) Subject: Introduce lttng_ust_loaded weak symbol X-Git-Tag: v2.9.0-rc1~33 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=07b57e5eb9db5d4219cab7cb3ad61edbc32eb9e5;p=lttng-ust.git Introduce lttng_ust_loaded weak symbol This variable can be tested by applications to check whether lttng-ust is loaded. They simply have to define their own "lttng_ust_loaded" weak symbol, and test it. It is set to 1 by the library constructor. The main use-case is to allow applications to detect that they should not try to close file descriptors that do not belong to them (e.g. BSD closefrom). This is a common pattern with applications invoking daemon(3). Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 6105403a..3959568b 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -106,6 +106,14 @@ static pthread_mutex_t ust_fork_mutex = PTHREAD_MUTEX_INITIALIZER; /* Should the ust comm thread quit ? */ static int lttng_ust_comm_should_quit; +/* + * This variable can be tested by applications to check whether + * lttng-ust is loaded. They simply have to define their own + * "lttng_ust_loaded" weak symbol, and test it. It is set to 1 by the + * library constructor. + */ +int lttng_ust_loaded __attribute__((weak)); + /* * Return 0 on success, -1 if should quit. * The lock is taken in both cases. @@ -1574,6 +1582,8 @@ void __attribute__((constructor)) lttng_ust_init(void) lttng_fixup_procname_tls(); lttng_fixup_ust_mutex_nest_tls(); + lttng_ust_loaded = 1; + /* * We want precise control over the order in which we construct * our sub-libraries vs starting to receive commands from