From: Mathieu Desnoyers Date: Tue, 12 Jul 2016 19:11:06 +0000 (-0400) Subject: Introduce LTTNG_UST_LOADED environment variable X-Git-Tag: v2.9.0-rc1~35 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2315088b93f925c5cccee865ccb8f6bc542e52dc;p=lttng-ust.git Introduce LTTNG_UST_LOADED environment variable Set internally by liblttng-ust's constructor. Can be used by applications to detect if lttng-ust is loaded, even if liblttng-ust is not directly linked by the application. 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). Note that this environment variable is passed to children of a traced process, and through exec calls. Therefore, an application might think that lttng-ust is loaded even though it's not loaded in its own address space if it was loaded by one of its parent processes. Signed-off-by: Mathieu Desnoyers --- diff --git a/doc/man/lttng-ust.3.txt b/doc/man/lttng-ust.3.txt index 7a23943d..a1d4f204 100644 --- a/doc/man/lttng-ust.3.txt +++ b/doc/man/lttng-ust.3.txt @@ -1113,6 +1113,15 @@ are located in a specific directory under `$LTTNG_HOME` (or `$HOME` if documentation under https://github.com/lttng/lttng-ust/tree/master/doc/examples/getcpu-override[`examples/getcpu-override`]. +`LTTNG_UST_LOADED`:: + Set internally by `liblttng-ust`'s constructor. Can be used by + applications to detect if lttng-ust is loaded, even if liblttng-ust + is not directly linked by the application. This environment + variable stays set across fork and exec, so an application could + observe this environment variable being set if a parent process had + lttng-ust loaded when issuing fork, even if this application does + not have lttng-ust in its address space. + `LTTNG_UST_REGISTER_TIMEOUT`:: Waiting time for the _registration done_ session daemon command before proceeding to execute the main program (milliseconds). diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 6105403a..cc9b6b5e 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -1547,6 +1547,13 @@ void lttng_ust_malloc_wrapper_init(void) { } +static +void init_ust_env(void) +{ + if (putenv("LTTNG_UST_LOADED=1")) + DBG("Error setting LTTNG_UST_LOADED environment variable"); +} + /* * sessiond monitoring thread: monitor presence of global and per-user * sessiond by polling the application common named pipe. @@ -1574,6 +1581,8 @@ void __attribute__((constructor)) lttng_ust_init(void) lttng_fixup_procname_tls(); lttng_fixup_ust_mutex_nest_tls(); + init_ust_env(); + /* * We want precise control over the order in which we construct * our sub-libraries vs starting to receive commands from