From 3287f48be61ef3491aff0a80b7185ac57b3d8a5d Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Mon, 27 Nov 2023 12:02:40 -0500 Subject: [PATCH] Add initial support for the multiple LTTNG_UST_APP_PATHs The `$LTTNG_UST_APP_PATH` is split using ':' as a separator. There is no provision for escaping the ':' separator. Paths after the first path will be ignored for the moment and a warning emitted. Change-Id: I619a3578e00fd3c758d616b99b443fc15a1477df Signed-off-by: Kienan Stewart Signed-off-by: Mathieu Desnoyers --- .../agent/client/LttngTcpSessiondClient.java | 12 +++++- src/lib/lttng-ust/lttng-ust-comm.c | 41 +++++++++++++++++-- src/python-lttngust/lttngust/agent.py | 10 ++++- 3 files changed, 56 insertions(+), 7 deletions(-) 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 82f2c2f0..ccffb9d3 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 @@ -208,8 +208,16 @@ public class LttngTcpSessiondClient implements Runnable { this.outToSessiond = new DataOutputStream(sessiondSock.getOutputStream()); } - private static String getUstAppPath() { - return System.getenv("LTTNG_UST_APP_PATH"); + private String getUstAppPath() { + String ustAppPath = System.getenv("LTTNG_UST_APP_PATH"); + if (ustAppPath != null) { + String[] paths = ustAppPath.split(":"); + if (paths.length > 1) { + log("':' separator in LTTNG_UST_APP_PATH, only the first path will be used"); + } + return paths[0]; + } + return ustAppPath; } private static String getHomePath() { diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index 229e457a..9745c182 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -411,10 +411,43 @@ const char *get_lttng_home_dir(void) return (const char *) lttng_ust_getenv("HOME"); } +/* + * Returns the LTTNG_UST_APP_PATH path. If environment variable exists + * and contains a ':', the first path before the ':' separator is returned. + * The return value should be freed by the caller if it is not NULL. + */ static -const char *get_lttng_ust_app_path(void) +char *get_lttng_ust_app_path(void) { - return (const char *) lttng_ust_getenv("LTTNG_UST_APP_PATH"); + const char *env_val = lttng_ust_getenv("LTTNG_UST_APP_PATH"); + char *val = NULL; + char *sep = NULL; + if (env_val == NULL) + goto error; + sep = strchr((char*)env_val, ':'); + if (sep) { + /* + * Split into multiple paths using ':' as a separator. + * There is no escaping of the ':' separator. + */ + WARN("':' separator in LTTNG_UST_APP_PATH, only the first path will be used."); + val = zmalloc(sep - env_val + 1); + if (!val) { + PERROR("zmalloc get_lttng_ust_app_path"); + goto error; + } + memcpy(val, env_val, sep - env_val); + val[sep - env_val] = '\0'; + } else { + val = strdup(env_val); + if (!val) { + PERROR("strdup"); + goto error; + } + } + +error: + return val; } /* @@ -517,7 +550,7 @@ void print_cmd(int cmd, int handle) static int setup_ust_apps(void) { - const char *ust_app_path; + char *ust_app_path = NULL; int ret = 0; uid_t uid; @@ -562,6 +595,8 @@ int setup_ust_apps(void) lttng_pthread_getname_np(ust_app.procname, LTTNG_UST_CONTEXT_PROCNAME_LEN); end: + if (ust_app_path) + free(ust_app_path); return ret; } diff --git a/src/python-lttngust/lttngust/agent.py b/src/python-lttngust/lttngust/agent.py index 69caad69..58845b56 100644 --- a/src/python-lttngust/lttngust/agent.py +++ b/src/python-lttngust/lttngust/agent.py @@ -267,7 +267,13 @@ def _get_port_from_file(path): return port def _get_ust_app_path(): - return os.getenv('LTTNG_UST_APP_PATH') + paths = os.getenv('LTTNG_UST_APP_PATH') + if paths is None: + return paths + paths = paths.split(':') + if len(paths) > 1: + dbg._pwarning("':' separator in LTTNG_UST_APP_PATH, only the first path will be used") + return paths[0] def _get_user_home_path(): # $LTTNG_HOME overrides $HOME if it exists @@ -326,7 +332,7 @@ def _init_threads(): sys_port = None try: - if ust_app_port is not None: + if ust_app_port is not None: dbg._pdebug('creating ust_app client thread') t = threading.Thread(target=_client_thread_target, args=('ust_app', ust_app_port, reg_queue)) -- 2.34.1