python: log exception details when agent thread cannot start
[lttng-ust.git] / src / python-lttngust / lttngust / agent.py
index 8658372819c5e5cd60e6412ac2e26db3a62e6a56..0cb31618a6534b65fb0777e2357ec4617a5c456b 100644 (file)
@@ -96,7 +96,7 @@ class _TcpClient(object):
             except (Exception) as e:
                 # Whatever happens here, we have to close the socket and
                 # retry to connect to the session daemon since either
-                # the socket was closed, a network timeout occured, or
+                # the socket was closed, a network timeout occurred, or
                 # invalid data was received.
                 dbg._pdebug(self._debug('got exception: {}'.format(e)))
                 self._cleanup_socket()
@@ -266,6 +266,14 @@ def _get_port_from_file(path):
 
     return port
 
+def _get_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
@@ -298,15 +306,26 @@ def _init_threads():
     'lttng'.encode().decode()
 
     _initialized = True
-    sys_port = _get_port_from_file('/var/run/lttng/agent.port')
-    user_port_file = os.path.join(_get_user_home_path(), '.lttng', 'agent.port')
-    user_port = _get_port_from_file(user_port_file)
+
+    # The LTTNG_UST_APP_PATH environment variables disables connections
+    # to the global and per-user session daemons.
+    if _get_ust_app_path() is not None:
+        ust_app_port_file = os.path.join(_get_ust_app_path(), 'agent.port')
+        ust_app_port = _get_port_from_file(ust_app_port_file)
+        sys_port = None
+        user_port = None
+        dbg._pdebug('ust_app session daemon port: {}'.format(ust_app_port))
+    else:
+        ust_app_port = None
+        sys_port = _get_port_from_file('/var/run/lttng/agent.port')
+        user_port_file = os.path.join(_get_user_home_path(), '.lttng', 'agent.port')
+        user_port = _get_port_from_file(user_port_file)
+        dbg._pdebug('system session daemon port: {}'.format(sys_port))
+        dbg._pdebug('user session daemon port: {}'.format(user_port))
+
     reg_queue = queue.Queue()
     reg_expecting = 0
 
-    dbg._pdebug('system session daemon port: {}'.format(sys_port))
-    dbg._pdebug('user session daemon port: {}'.format(user_port))
-
     if sys_port == user_port and sys_port is not None:
         # The two session daemon ports are the same. This is not normal.
         # Connect to only one.
@@ -314,6 +333,16 @@ def _init_threads():
         sys_port = None
 
     try:
+        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))
+            t.name = 'ust_app'
+            t.daemon = True
+            t.start()
+            dbg._pdebug('created and started ust_app client thread')
+            reg_expecting += 1
+
         if sys_port is not None:
             dbg._pdebug('creating system client thread')
             t = threading.Thread(target=_client_thread_target,
@@ -333,9 +362,9 @@ def _init_threads():
             t.start()
             dbg._pdebug('created and started user client thread')
             reg_expecting += 1
-    except:
+    except Exception as e:
         # cannot create threads for some reason; stop this initialization
-        dbg._pwarning('cannot create client threads')
+        dbg._pwarning('cannot create client threads: {}'.format(e))
         return
 
     if reg_expecting == 0:
This page took 0.024572 seconds and 4 git commands to generate.