Add log4j default event and channel name handling
authorDavid Goulet <dgoulet@efficios.com>
Tue, 9 Sep 2014 15:22:50 +0000 (11:22 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 11 Sep 2014 16:04:13 +0000 (12:04 -0400)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/event.c
src/bin/lttng-sessiond/event.h
src/bin/lttng-sessiond/save.c
src/common/defaults.h

index 628fb1061da0492089dff7f332df15b7a4bc6906..d2673a9019044a40af39341795c42f566d3ce03f 100644 (file)
@@ -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;
                }
 
index 7c42a928abf8dfc56bd1fe8115e063076c7acdd5..59b591de9d5e454add9567a8f07636c123f0d6ca 100644 (file)
@@ -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);
index c14c00595a9311b402816d25955dc88bb05a35b0..a82a3bbb8df0150aab4eb1ac9ed7f52bca14a606 100644 (file)
@@ -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 */
index e2c93b4bba1663d139e4257f8659c2ea070ff667..2c38df97292fd34fc3619d0c8bdc20d15a1ac1d6 100644 (file)
@@ -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) {
index 1beb516aa09980fd39c750cda2b70df2efef96e2..88f7fe83a9a91598a9edb1f56136061ffab592d8 100644 (file)
 /* 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
This page took 0.031617 seconds and 4 git commands to generate.