X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust-jul%2Forg%2Flttng%2Fust%2Fjul%2FLTTngAgent.java;h=2485be2deb1781c05451eafaddd0a284ad89ec3b;hb=f1fa0535d79f31fdbaeb3dc12b1edc7928daa8b1;hp=72e60d235574fa1d3fa188ff405adbfaafcfbaee;hpb=9aabed2d5ae3621ff0989cdcec8a726970e04ea6;p=lttng-ust.git diff --git a/liblttng-ust-jul/org/lttng/ust/jul/LTTngAgent.java b/liblttng-ust-jul/org/lttng/ust/jul/LTTngAgent.java index 72e60d23..2485be2d 100644 --- a/liblttng-ust-jul/org/lttng/ust/jul/LTTngAgent.java +++ b/liblttng-ust-jul/org/lttng/ust/jul/LTTngAgent.java @@ -18,11 +18,11 @@ package org.lttng.ust.jul; import java.io.IOException; -import java.io.FileNotFoundException; import java.io.InputStream; import java.io.BufferedReader; import java.io.FileReader; import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; import java.util.logging.FileHandler; import java.util.logging.Handler; import java.util.logging.Level; @@ -48,12 +48,13 @@ public class LTTngAgent { private static boolean initialized = false; private static Semaphore registerSem; + private final static int semTimeout = 3; /* Seconds */ + /* + * Default value to connect to session daemon. Port number is dynamically + * fetched from the port file that is created by a running session daemon. + */ private static final String sessiondAddr = "127.0.0.1"; - private static final int sessiondPort = 5345; - - private static final String rootPortFile = "/var/run/lttng/jul.port"; - private static final String userPortFile = "/.lttng/jul.port"; /* * Constructor is private. This is a singleton and a reference should be @@ -100,29 +101,6 @@ public class LTTngAgent { return uid; } - private String getHomePath() { - return System.getProperty("user.home"); - } - - private int getPortFromFile(String path) throws IOException { - int port; - BufferedReader br; - - try { - br = new BufferedReader(new FileReader(path)); - String line = br.readLine(); - port = Integer.parseInt(line, 10); - if (port < 0 || port > 65535) { - port = sessiondPort; - } - br.close(); - } catch (FileNotFoundException e) { - port = sessiondPort; - } - - return port; - } - /* * Public getter to acquire a reference to this singleton object. */ @@ -140,42 +118,32 @@ public class LTTngAgent { * returned by the logManager. */ private synchronized void init() throws SecurityException, IOException { - int user_port, root_port; int nr_acquires = 0; if (this.initialized) { return; } - root_port = getPortFromFile(rootPortFile); - if (getUID() == 0) { - user_port = root_port; - } else { - user_port = getPortFromFile(getHomePath() + userPortFile); - } - /* Handle user session daemon if any. */ - this.lttngThreadUser = new LTTngThread(this.sessiondAddr, user_port, + this.lttngThreadUser = new LTTngThread(this.sessiondAddr, this.lttngHandlerUser, this.registerSem); this.sessiondThUser = new Thread(lttngThreadUser); this.sessiondThUser.start(); /* Wait for registration done of per-user sessiond */ nr_acquires++; - /* Having two different ports, we have to try both. */ - if (root_port != user_port) { - /* Handle root session daemon. */ - this.lttngThreadRoot = new LTTngThread(this.sessiondAddr, - root_port, this.lttngHandlerRoot, this.registerSem); - this.sessiondThRoot = new Thread(lttngThreadRoot); - this.sessiondThRoot.start(); - /* Wait for registration done of system-wide sessiond */ - nr_acquires++; - } + /* Handle root session daemon. */ + this.lttngThreadRoot = new LTTngThread(this.sessiondAddr, + this.lttngHandlerRoot, this.registerSem); + this.sessiondThRoot = new Thread(lttngThreadRoot); + this.sessiondThRoot.start(); + /* Wait for registration done of system-wide sessiond */ + nr_acquires++; /* Wait for each registration to end. */ try { - this.registerSem.acquire(nr_acquires); + this.registerSem.tryAcquire(nr_acquires, semTimeout, + TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); }