From da6c3a50492fd90c5dec03183ce504228292bb3b Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 9 Sep 2014 11:22:50 -0400 Subject: [PATCH] Add log4j default event and channel name handling Signed-off-by: David Goulet --- src/bin/lttng-sessiond/cmd.c | 65 +++++++++------------------------- src/bin/lttng-sessiond/event.c | 40 +++++++++++++++++---- src/bin/lttng-sessiond/event.h | 2 ++ src/bin/lttng-sessiond/save.c | 3 +- src/common/defaults.h | 7 ++++ 5 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 628fb1061..d2673a901 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1485,6 +1485,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: { + const char *default_event_name, *default_chan_name; struct agent *agt; struct lttng_event uevent; struct lttng_domain tmp_dom; @@ -1506,13 +1507,12 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, memset(&uevent, 0, sizeof(uevent)); uevent.type = LTTNG_EVENT_TRACEPOINT; uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - if (is_root) { - strncpy(uevent.name, DEFAULT_SYS_JUL_EVENT_NAME, - sizeof(uevent.name)); - } else { - strncpy(uevent.name, DEFAULT_USER_JUL_EVENT_NAME, - sizeof(uevent.name)); + default_event_name = event_get_default_agent_ust_name(domain->type); + if (!default_event_name) { + ret = -LTTNG_ERR_FATAL; + goto error; } + strncpy(uevent.name, default_event_name, sizeof(uevent.name)); uevent.name[sizeof(uevent.name) - 1] = '\0'; /* @@ -1523,7 +1523,13 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, memcpy(&tmp_dom, domain, sizeof(tmp_dom)); tmp_dom.type = LTTNG_DOMAIN_UST; - ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME, + if (domain->type == LTTNG_DOMAIN_LOG4J) { + default_chan_name = DEFAULT_LOG4J_CHANNEL_NAME; + } else { + default_chan_name = DEFAULT_JUL_CHANNEL_NAME; + } + + ret = cmd_enable_event(session, &tmp_dom, (char *) default_chan_name, &uevent, filter_expression, filter, NULL, wpipe); if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) { goto error; @@ -1718,56 +1724,19 @@ int cmd_enable_event_all(struct ltt_session *session, case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_JUL: { - struct agent *agt; - struct lttng_event uevent, event; - struct lttng_domain tmp_dom; + struct lttng_event event; struct ltt_ust_session *usess = session->ust_session; assert(usess); - agt = trace_ust_find_agent(usess, domain->type); - if (!agt) { - agt = agent_create(domain->type); - if (!agt) { - ret = -LTTNG_ERR_NOMEM; - goto error; - } - agent_add(agt, usess->agents); - } - - /* Create the default tracepoint. */ - uevent.type = LTTNG_EVENT_TRACEPOINT; - uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - if (is_root) { - strncpy(uevent.name, DEFAULT_SYS_JUL_EVENT_NAME, - sizeof(uevent.name)); - } else { - strncpy(uevent.name, DEFAULT_USER_JUL_EVENT_NAME, - sizeof(uevent.name)); - } - uevent.name[sizeof(uevent.name) - 1] = '\0'; - - /* - * The domain type is changed because we are about to enable the - * default channel and event for the JUL domain that are hardcoded. - * This happens in the UST domain. - */ - memcpy(&tmp_dom, domain, sizeof(tmp_dom)); - tmp_dom.type = LTTNG_DOMAIN_UST; - - ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME, - &uevent, NULL, NULL, NULL, wpipe); - if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) { - goto error; - } - event.loglevel = LTTNG_LOGLEVEL_JUL_ALL; event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; strncpy(event.name, "*", sizeof(event.name)); event.name[sizeof(event.name) - 1] = '\0'; - ret = event_agent_enable_all(usess, agt, &event, filter); - if (ret != LTTNG_OK) { + ret = cmd_enable_event(session, domain, NULL, &event, + filter_expression, filter, NULL, wpipe); + if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) { goto error; } diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 7c42a928a..59b591de9 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -710,6 +710,34 @@ error: return ret; } +/* + * Return the agent default event name to use by testing if the process is root + * or not. Return NULL on error. + */ +const char *event_get_default_agent_ust_name(enum lttng_domain_type domain) +{ + const char *default_event_name = NULL; + + if (domain == LTTNG_DOMAIN_JUL) { + if (is_root) { + default_event_name = DEFAULT_SYS_JUL_EVENT_NAME; + } else { + default_event_name = DEFAULT_USER_JUL_EVENT_NAME; + } + } else if (domain == LTTNG_DOMAIN_LOG4J) { + if (is_root) { + default_event_name = DEFAULT_SYS_LOG4J_EVENT_NAME; + } else { + default_event_name = DEFAULT_USER_LOG4J_EVENT_NAME; + } + } else { + assert(0); + } + + return default_event_name; +} + + /* * Disable a single agent event for a given UST session. * @@ -722,7 +750,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, struct agent_event *aevent; struct ltt_ust_event *uevent = NULL; struct ltt_ust_channel *uchan = NULL; - char *ust_event_name; + const char *ust_event_name; assert(agt); assert(usess); @@ -752,10 +780,10 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, goto error; } - if (is_root) { - ust_event_name = DEFAULT_SYS_JUL_EVENT_NAME; - } else { - ust_event_name = DEFAULT_USER_JUL_EVENT_NAME; + ust_event_name = event_get_default_agent_ust_name(agt->domain); + if (!ust_event_name) { + ret = LTTNG_ERR_FATAL; + goto error; } /* @@ -763,7 +791,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, * with the loglevel type to ALL thus the loglevel stays 0. The event's * filter is the one handling the loglevel for agent. */ - uevent = trace_ust_find_event(uchan->events, ust_event_name, + uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name, aevent->filter, 0, NULL); /* If the agent event exists, it must be available on the UST side. */ assert(uevent); diff --git a/src/bin/lttng-sessiond/event.h b/src/bin/lttng-sessiond/event.h index c14c00595..a82a3bbb8 100644 --- a/src/bin/lttng-sessiond/event.h +++ b/src/bin/lttng-sessiond/event.h @@ -59,4 +59,6 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, char *event_name); int event_agent_disable_all(struct ltt_ust_session *usess, struct agent *agt); +const char *event_get_default_agent_ust_name(enum lttng_domain_type domain); + #endif /* _LTT_EVENT_H */ diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index e2c93b4bb..2c38df972 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1056,7 +1056,8 @@ int save_ust_session(struct config_writer *writer, int agent_channel; ust_chan = caa_container_of(node, struct ltt_ust_channel, node); - agent_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name); + agent_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name) || + !strcmp(DEFAULT_LOG4J_CHANNEL_NAME, ust_chan->name); if (!(save_agent ^ agent_channel)) { ret = save_ust_channel(writer, ust_chan, session->ust_session); if (ret) { diff --git a/src/common/defaults.h b/src/common/defaults.h index 1beb516aa..88f7fe83a 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -165,6 +165,13 @@ /* Default JUL tracepoint name. This is a wildcard for the JUL domain. */ #define DEFAULT_SYS_JUL_EVENT_NAME "lttng_jul:sys*" #define DEFAULT_USER_JUL_EVENT_NAME "lttng_jul:user*" + +/* Default log4j domain channel name. */ +#define DEFAULT_LOG4J_CHANNEL_NAME "lttng_log4j_channel" +/* Default log4j tracepoint name. This is a wildcard for the log4j domain. */ +#define DEFAULT_SYS_LOG4J_EVENT_NAME "lttng_log4j:sys*" +#define DEFAULT_USER_LOG4J_EVENT_NAME "lttng_log4j:user*" + /* JUL default channel name. */ #define DEFAULT_CHANNEL_OVERWRITE 0 #define DEFAULT_CHANNEL_TRACEFILE_SIZE 0 -- 2.34.1