Fix: failure to launch agent thread is not reported
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 23 Apr 2018 23:03:16 +0000 (19:03 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 24 Apr 2018 20:33:55 +0000 (16:33 -0400)
A session daemon may fail to launch its agent thread. In such
a case, the tracing of agent domains fails silently as events
never get enabled through the agent.

The problem that was reported was caused by a second session
daemon being already bound on the agent TCP socket port, which
prevented the launch of the agent thread.

While in this situation tracing is still not possible, the user
will at least get an error indicating as such when enabling
an event in those domains.

Reported-by: Deborah Barnard <starfallprojects@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/agent-thread.c
src/bin/lttng-sessiond/agent-thread.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/main.c
src/common/error.c

index 36602448de7288c13b5ee1931d707811198de06e..3c72aeeec58525b3ff5711765f0391a56d831ec8 100644 (file)
@@ -159,6 +159,7 @@ enum lttng_error_code {
        LTTNG_ERR_ROTATION_WRONG_VERSION   = 136, /* Session rotation not supported by this kernel tracer version */
        LTTNG_ERR_NO_SESSION_OUTPUT        = 137, /* Session has no output configured. */
        LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY     = 138, /* Rotate feature not available on the relay. */
        LTTNG_ERR_ROTATION_WRONG_VERSION   = 136, /* Session rotation not supported by this kernel tracer version */
        LTTNG_ERR_NO_SESSION_OUTPUT        = 137, /* Session has no output configured. */
        LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY     = 138, /* Rotate feature not available on the relay. */
+       LTTNG_ERR_AGENT_TRACING_DISABLED = 139, /* Agent tracing disabled. */
 
        /* MUST be last element */
        LTTNG_ERR_NR,                           /* Last element */
 
        /* MUST be last element */
        LTTNG_ERR_NR,                           /* Last element */
index ddc6c7e62aeab3c5e058b0ddd0225eb76ffc1d1d..d53e0b1c749e9c8291e5b6630ec4f55dde718257 100644 (file)
@@ -32,6 +32,8 @@
 #include "session.h"
 #include "utils.h"
 
 #include "session.h"
 #include "utils.h"
 
+static int agent_tracing_enabled = -1;
+
 /*
  * Note that there is not port here. It's set after this URI is parsed so we
  * can let the user define a custom one. However, localhost is ALWAYS the
 /*
  * Note that there is not port here. It's set after this URI is parsed so we
  * can let the user define a custom one. However, localhost is ALWAYS the
@@ -223,6 +225,15 @@ error:
        return ret;
 }
 
        return ret;
 }
 
+bool agent_tracing_is_enabled(void)
+{
+       int enabled;
+
+       enabled = uatomic_read(&agent_tracing_enabled);
+       assert(enabled != -1);
+       return enabled == 1;
+}
+
 /*
  * This thread manage application notify communication.
  */
 /*
  * This thread manage application notify communication.
  */
@@ -248,6 +259,12 @@ void *agent_thread_manage_registration(void *data)
        }
 
        reg_sock = init_tcp_socket();
        }
 
        reg_sock = init_tcp_socket();
+       uatomic_set(&agent_tracing_enabled, !!reg_sock);
+
+       /*
+        * Signal that the agent thread is ready. The command thread
+        * may start to query whether or not agent tracing is enabled.
+        */
        sessiond_notify_ready();
        if (!reg_sock) {
                goto error_tcp_socket;
        sessiond_notify_ready();
        if (!reg_sock) {
                goto error_tcp_socket;
@@ -348,6 +365,7 @@ restart:
        }
 
 exit:
        }
 
 exit:
+       uatomic_set(&agent_tracing_enabled, 0);
        /* Whatever happens, try to delete it and exit. */
        (void) lttng_poll_del(&events, reg_sock->fd);
 error:
        /* Whatever happens, try to delete it and exit. */
        (void) lttng_poll_del(&events, reg_sock->fd);
 error:
index 0a0b3682fecf327f037f12fb176a3333e3111e45..6bdfdcd5ea274041a1bf0e243aadc04077b7e6ab 100644 (file)
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include <stdbool.h>
+
 #ifndef LTTNG_SESSIOND_AGENT_THREAD_H
 #define LTTNG_SESSIOND_AGENT_THREAD_H
 
 #ifdef HAVE_LIBLTTNG_UST_CTL
 
 void *agent_thread_manage_registration(void *data);
 #ifndef LTTNG_SESSIOND_AGENT_THREAD_H
 #define LTTNG_SESSIOND_AGENT_THREAD_H
 
 #ifdef HAVE_LIBLTTNG_UST_CTL
 
 void *agent_thread_manage_registration(void *data);
+bool agent_tracing_is_enabled(void);
 
 #else /* HAVE_LIBLTTNG_UST_CTL */
 
 
 #else /* HAVE_LIBLTTNG_UST_CTL */
 
@@ -29,6 +32,11 @@ void *agent_thread_manage_registration(void *data)
 {
        return NULL;
 }
 {
        return NULL;
 }
+static inline
+bool agent_tracing_is_enabled(void)
+{
+       return false;
+}
 
 #endif /* HAVE_LIBLTTNG_UST_CTL */
 
 
 #endif /* HAVE_LIBLTTNG_UST_CTL */
 
index a1eb961ee544331f961202ee2b69d36ffbe87868..2e2ae6006023c13b8457b30071e1332fdf24ef14 100644 (file)
@@ -55,6 +55,7 @@
 #include "rotate.h"
 #include "rotation-thread.h"
 #include "sessiond-timer.h"
 #include "rotate.h"
 #include "rotation-thread.h"
 #include "sessiond-timer.h"
+#include "agent-thread.h"
 
 #include "cmd.h"
 
 
 #include "cmd.h"
 
@@ -1384,9 +1385,15 @@ int cmd_enable_channel(struct ltt_session *session,
                break;
        }
        case LTTNG_DOMAIN_UST:
                break;
        }
        case LTTNG_DOMAIN_UST:
+               break;
        case LTTNG_DOMAIN_JUL:
        case LTTNG_DOMAIN_LOG4J:
        case LTTNG_DOMAIN_PYTHON:
        case LTTNG_DOMAIN_JUL:
        case LTTNG_DOMAIN_LOG4J:
        case LTTNG_DOMAIN_PYTHON:
+               if (!agent_tracing_is_enabled()) {
+                       DBG("Attempted to enable a channel in an agent domain but the agent thread is not running");
+                       ret = LTTNG_ERR_AGENT_TRACING_DISABLED;
+                       goto error;
+               }
                break;
        default:
                ret = LTTNG_ERR_UNKNOWN_DOMAIN;
                break;
        default:
                ret = LTTNG_ERR_UNKNOWN_DOMAIN;
@@ -2094,6 +2101,12 @@ static int _cmd_enable_event(struct ltt_session *session,
 
                assert(usess);
 
 
                assert(usess);
 
+               if (!agent_tracing_is_enabled()) {
+                       DBG("Attempted to enable an event in an agent domain but the agent thread is not running");
+                       ret = LTTNG_ERR_AGENT_TRACING_DISABLED;
+                       goto error;
+               }
+
                agt = trace_ust_find_agent(usess, domain->type);
                if (!agt) {
                        agt = agent_create(domain->type);
                agt = trace_ust_find_agent(usess, domain->type);
                if (!agt) {
                        agt = agent_create(domain->type);
index 0620c7e70f83b3d33ae9cf5ea64dd15316784657..cec8e835e04881c20c65787c19a560bc19756c58 100644 (file)
@@ -4496,12 +4496,41 @@ static void *thread_manage_clients(void *data)
        }
 
        sessiond_notify_ready();
        }
 
        sessiond_notify_ready();
+
        ret = sem_post(&load_info->message_thread_ready);
        if (ret) {
                PERROR("sem_post message_thread_ready");
                goto error;
        }
 
        ret = sem_post(&load_info->message_thread_ready);
        if (ret) {
                PERROR("sem_post message_thread_ready");
                goto error;
        }
 
+       /*
+        * Wait until all support threads are initialized before accepting
+        * commands.
+        */
+       while (uatomic_read(&lttng_sessiond_ready) != 0) {
+               fd_set read_fds;
+               struct timeval timeout;
+
+               FD_ZERO(&read_fds);
+               FD_SET(thread_quit_pipe[0], &read_fds);
+               memset(&timeout, 0, sizeof(timeout));
+               timeout.tv_usec = 1000;
+
+               /*
+                * If a support thread failed to launch, it may signal that
+                * we must exit and the sessiond would never be marked as
+                * "ready".
+                *
+                * The timeout is set to 1ms, which serves as a way to
+                * pace down this check.
+                */
+               ret = select(thread_quit_pipe[0] + 1, &read_fds, NULL, NULL,
+                               &timeout);
+               if (ret > 0 || (ret < 0 && errno != EINTR)) {
+                       goto exit;
+               }
+       }
+
        /* This testpoint is after we signal readiness to the parent. */
        if (testpoint(sessiond_thread_manage_clients)) {
                goto error;
        /* This testpoint is after we signal readiness to the parent. */
        if (testpoint(sessiond_thread_manage_clients)) {
                goto error;
index a8256ff101ba3ed9d8fc8be5d56651c02c484af2..aebcaa91529268268cf06f787febc407a05a488c 100644 (file)
@@ -200,6 +200,7 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_ROTATION_WRONG_VERSION) ] = "Session rotation is not supported by this kernel tracer version",
        [ ERROR_INDEX(LTTNG_ERR_NO_SESSION_OUTPUT) ] = "Session has no output",
        [ ERROR_INDEX(LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY) ] = "Rotation feature not available on the relay",
        [ ERROR_INDEX(LTTNG_ERR_ROTATION_WRONG_VERSION) ] = "Session rotation is not supported by this kernel tracer version",
        [ ERROR_INDEX(LTTNG_ERR_NO_SESSION_OUTPUT) ] = "Session has no output",
        [ ERROR_INDEX(LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY) ] = "Rotation feature not available on the relay",
+       [ ERROR_INDEX(LTTNG_ERR_AGENT_TRACING_DISABLED) ] = "Session daemon agent tracing is disabled",
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
This page took 0.030512 seconds and 4 git commands to generate.