From 90d125c709f566f3663bf84677f100134cc618e0 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 28 Sep 2021 17:47:31 -0400 Subject: [PATCH] Add support for LTTNG_UST_HOME Namespacing the LTTNG_HOME env variable facilitates the work carried to have a way to trace the tracer (lttng-sessiond). This also fits with the work done lately to namespace lttng-ust. The LTTNG_HOME environment variable is used by lttng-sessiond to setup the whole tracing environment for the application to be traced. When lttng-ust is loaded by the lttng-sessiond to be traced, the fact that it reuse the `LTTNG_HOME` set for the lttng-sessiond prevent us from specifying an external lttng-sessiond home. Albeit it could be possible for the lttng-sessiond to "trace" itself (self tracing), it make more sense, in our testing environment, to have a supplementary lttng-sessiond handling the tracing of the lttng-sessiond under testing. Note that some work will be carried to limit the use of LTTNG_HOME to setup the tracing environment by lttng-sessiond and liblttng-ctl APIs but it will be a long effort. Providing `LTTNG_UST_HOME` allows us to start dogfooding today. `LTTNG_HOME` is still used as a fallback to `LTTNG_UST_HOME` to preserve backward compatibility. Signed-off-by: Jonathan Rajotte Signed-off-by: Mathieu Desnoyers Change-Id: I6aed21fd70d1b79b6768d237f59cc80612938d65 --- README.md | 1 + doc/man/lttng-ust.3.txt | 9 +++++--- src/common/getenv.c | 1 + .../agent/client/LttngTcpSessiondClient.java | 22 +++++++++++++++---- src/lib/lttng-ust/lttng-ust-comm.c | 10 +++++++++ src/python-lttngust/lttngust/agent.py | 6 +++-- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 286703ba..d53f8bb5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +Useless change LTTng-UST ========= diff --git a/doc/man/lttng-ust.3.txt b/doc/man/lttng-ust.3.txt index 0924a4de..76b5c37a 100644 --- a/doc/man/lttng-ust.3.txt +++ b/doc/man/lttng-ust.3.txt @@ -1479,15 +1479,18 @@ int main(int argc, char* argv[]) ENVIRONMENT VARIABLES --------------------- -`LTTNG_HOME`:: +`LTTNG_UST_HOME`:: Alternative user's home directory. This variable is useful when the user running the instrumented application has a non-writable home directory. + Unix sockets used for the communication between `liblttng-ust` and the LTTng session and consumer daemons (part of the LTTng-tools project) -are located in a specific directory under `$LTTNG_HOME` (or `$HOME` if -`$LTTNG_HOME` is not set). +are located in a specific directory under `$LTTNG_UST_HOME` (or `$HOME` if +`$LTTNG_UST_HOME` is not set). + +NOTE: `$LTTNG_HOME` is also supported as a fallback of `$LTTNG_UST_HOME` for +backward compatibility reason. `LTTNG_UST_ALLOW_BLOCKING`:: If set, allow the application to retry event tracing when there's diff --git a/src/common/getenv.c b/src/common/getenv.c index 55e6ad7c..1b5717c7 100644 --- a/src/common/getenv.c +++ b/src/common/getenv.c @@ -49,6 +49,7 @@ static struct lttng_env lttng_env[] = { { "LTTNG_UST_ALLOW_BLOCKING", LTTNG_ENV_SECURE, NULL, }, { "HOME", LTTNG_ENV_SECURE, NULL, }, { "LTTNG_HOME", LTTNG_ENV_SECURE, NULL, }, + { "LTTNG_UST_HOME", LTTNG_ENV_SECURE, NULL, }, }; static diff --git a/src/lib/lttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java b/src/lib/lttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java index cb84087a..2c44a0df 100644 --- a/src/lib/lttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java +++ b/src/lib/lttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java @@ -197,15 +197,29 @@ public class LttngTcpSessiondClient implements Runnable { private static String getHomePath() { /* + * The environment variable LTTNG_UST_HOME overrides LTTNG_HOME + * if present. * The environment variable LTTNG_HOME overrides HOME if * defined. */ - String homePath = System.getenv("LTTNG_HOME"); + String lttngUstHomePath = System.getenv("LTTNG_UST_HOME"); + String lttngHomePath = System.getenv("LTTNG_HOME"); + + if (lttngUstHomePath != null) { + /* + * LTTNG_UST_HOME has priority over LTTNG_HOME and user + * home directory. + */ + return lttngUstHomePath; + } - if (homePath == null) { - homePath = System.getProperty("user.home"); + if (lttngHomePath != null) { + /* LTTNG_HOME has priority over user home directory. */ + return lttngHomePath; } - return homePath; + + /* Default to the user home directory. */ + return System.getProperty("user.home"); } /** diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index e57caa12..e206456f 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -370,16 +370,26 @@ static char *get_map_shm(struct sock_info *sock_info); /* * Returns the HOME directory path. Caller MUST NOT free(3) the returned * pointer. + * The following env are checked in order of priority: + * 1 - LTTNG_UST_HOME + * 2 - LTTNG_HOME + * 3 - HOME */ static const char *get_lttng_home_dir(void) { const char *val; + val = (const char *) lttng_ust_getenv("LTTNG_UST_HOME"); + if (val != NULL) { + return val; + } + val = (const char *) lttng_ust_getenv("LTTNG_HOME"); if (val != NULL) { return val; } + return (const char *) lttng_ust_getenv("HOME"); } diff --git a/src/python-lttngust/lttngust/agent.py b/src/python-lttngust/lttngust/agent.py index 66dbbd5e..b9929342 100644 --- a/src/python-lttngust/lttngust/agent.py +++ b/src/python-lttngust/lttngust/agent.py @@ -268,8 +268,10 @@ def _get_port_from_file(path): def _get_user_home_path(): - # $LTTNG_HOME overrides $HOME if it exists - return os.getenv('LTTNG_HOME', os.path.expanduser('~')) + # $LTTNG_UST_HOME overrides $LTTNG_HOME if it exist. + # In turn, $LTTNG_HOME overrides $HOME if it exists + return os.getenv('LTTNG_UST_HOME', os.getenv('LTTNG_HOME', + os.path.expanduser('~'))) _initialized = False -- 2.34.1