private static final String SESSION_HOST = "127.0.0.1";
private static final String ROOT_PORT_FILE = "/var/run/lttng/agent.port";
private static final String USER_PORT_FILE = "/.lttng/agent.port";
+ private static final String APP_PATH_PORT_FILE = "/agent.port";
private static final Charset PORT_FILE_ENCODING = Charset.forName("UTF-8");
private static final int PROTOCOL_MAJOR_VERSION = 2;
}
private void connectToSessiond() throws IOException {
- int rootPort = getPortFromFile(ROOT_PORT_FILE);
- int userPort = getPortFromFile(getHomePath() + USER_PORT_FILE);
+ int portToUse;
/*
- * Check for the edge case of both files existing but pointing to the
- * same port. In this case, let the root client handle it.
+ * The environment variable LTTNG_UST_APP_PATH disables
+ * connection to per-user and root session daemons.
*/
- if ((rootPort != 0) && (rootPort == userPort) && (!isRoot)) {
- log("User and root config files both point to port " + rootPort +
- ". Letting the root client handle it.");
- throw new IOException();
- }
+ String lttngUstAppPath = getUstAppPath();
+
+ if (lttngUstAppPath != null) {
+ portToUse = getPortFromFile(lttngUstAppPath + APP_PATH_PORT_FILE);
+ } else {
+ int rootPort = getPortFromFile(ROOT_PORT_FILE);
+ int userPort = getPortFromFile(getHomePath() + USER_PORT_FILE);
+
+ /*
+ * Check for the edge case of both files existing but pointing to the
+ * same port. In this case, let the root client handle it.
+ */
+ if ((rootPort != 0) && (rootPort == userPort) && (!isRoot)) {
+ log("User and root config files both point to port " + rootPort +
+ ". Letting the root client handle it.");
+ throw new IOException();
+ }
- int portToUse = (isRoot ? rootPort : userPort);
+ portToUse = (isRoot ? rootPort : userPort);
+ }
if (portToUse == 0) {
/* No session daemon available. Stop and retry later. */
this.outToSessiond = new DataOutputStream(sessiondSock.getOutputStream());
}
+ 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() {
/*
- * The environment variable LTTNG_UST_HOME overrides LTTNG_HOME
- * if present.
* The environment variable LTTNG_HOME overrides HOME if
- * defined.
+ * set.
*/
- 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 (lttngHomePath != null) {
- /* LTTNG_HOME has priority over user home directory. */
return lttngHomePath;
}
-
- /* Default to the user home directory. */
return System.getProperty("user.home");
}