From: Jérémie Galarneau Date: Mon, 23 Apr 2018 23:03:16 +0000 (-0400) Subject: Fix: failure to launch agent thread is not reported X-Git-Tag: v2.9.9~2 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=09a88287202e1cb7bcc984f65237bee33e6c5b93;p=lttng-tools.git Fix: failure to launch agent thread is not reported 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 Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index db6fe73c2..69fecaac4 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -145,6 +145,7 @@ enum lttng_error_code { LTTNG_ERR_REGEN_STATEDUMP_FAIL = 122, /* Failed to regenerate the state dump */ LTTNG_ERR_REGEN_STATEDUMP_NOMEM = 123, /* Failed to regenerate the state dump, not enough memory */ LTTNG_ERR_NOT_SNAPSHOT_SESSION = 124, /* Session is not in snapshot mode. */ + LTTNG_ERR_AGENT_TRACING_DISABLED = 139, /* Agent tracing disabled. */ /* MUST be last element */ LTTNG_ERR_NR, /* Last element */ diff --git a/src/bin/lttng-sessiond/agent-thread.c b/src/bin/lttng-sessiond/agent-thread.c index 4d53d6e09..bc1fac699 100644 --- a/src/bin/lttng-sessiond/agent-thread.c +++ b/src/bin/lttng-sessiond/agent-thread.c @@ -32,6 +32,8 @@ #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 @@ -223,6 +225,15 @@ error: 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. */ @@ -248,6 +259,12 @@ void *agent_thread_manage_registration(void *data) } 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; @@ -348,6 +365,7 @@ restart: } exit: + uatomic_set(&agent_tracing_enabled, 0); /* Whatever happens, try to delete it and exit. */ (void) lttng_poll_del(&events, reg_sock->fd); error: diff --git a/src/bin/lttng-sessiond/agent-thread.h b/src/bin/lttng-sessiond/agent-thread.h index 0a0b3682f..6bdfdcd5e 100644 --- a/src/bin/lttng-sessiond/agent-thread.h +++ b/src/bin/lttng-sessiond/agent-thread.h @@ -15,12 +15,15 @@ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + #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 */ @@ -29,6 +32,11 @@ void *agent_thread_manage_registration(void *data) { return NULL; } +static inline +bool agent_tracing_is_enabled(void) +{ + return false; +} #endif /* HAVE_LIBLTTNG_UST_CTL */ diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index bb46093e2..cf30b8ebf 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -41,6 +41,7 @@ #include "syscall.h" #include "agent.h" #include "buffer-registry.h" +#include "agent-thread.h" #include "cmd.h" @@ -1344,6 +1345,21 @@ int cmd_enable_channel(struct ltt_session *session, attr->attr.switch_timer_interval = 0; } + /* Check for feature support */ + switch (domain->type) { + 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: + break; + } + switch (domain->type) { case LTTNG_DOMAIN_KERNEL: { @@ -2077,6 +2093,12 @@ static int _cmd_enable_event(struct ltt_session *session, 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); diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index b4d82f3bf..cd2f07b60 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -4376,12 +4376,41 @@ static void *thread_manage_clients(void *data) } sessiond_notify_ready(); + 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(<tng_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; diff --git a/src/common/error.c b/src/common/error.c index ba50d2760..b6d2ff42f 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -186,6 +186,7 @@ static const char *error_string_array[] = { [ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_FAIL) ] = "Failed to regenerate the state dump", [ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_NOMEM) ] = "Failed to regenerate the state dump, not enough memory", [ ERROR_INDEX(LTTNG_ERR_NOT_SNAPSHOT_SESSION) ] = "Snapshot command can't be applied to a non-snapshot session", + [ ERROR_INDEX(LTTNG_ERR_AGENT_TRACING_DISABLED) ] = "Session daemon agent tracing is disabled", /* Last element */ [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"