Docs: add comment to cmd_add_context()
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index dfc8b31d0848ef2366ec5b66ef88b03b32ef31c9..8e06ce6913875dd85e0a17e0eeafb929ba93d425 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License, version 2 only, as
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <assert.h>
-#include <string.h>
 #include <inttypes.h>
 #include <urcu/list.h>
 #include <urcu/uatomic.h>
@@ -28,6 +27,7 @@
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/relayd/relayd.h>
 #include <common/utils.h>
+#include <common/compat/string.h>
 
 #include "channel.h"
 #include "consumer.h"
@@ -1048,7 +1048,7 @@ int cmd_enable_channel(struct ltt_session *session,
        assert(attr);
        assert(domain);
 
-       len = strnlen(attr->name, sizeof(attr->name));
+       len = lttng_strnlen(attr->name, sizeof(attr->name));
 
        /* Validate channel name */
        if (attr->name[0] == '.' ||
@@ -1225,28 +1225,18 @@ int cmd_disable_event(struct ltt_session *session,
 
                switch (event->type) {
                case LTTNG_EVENT_ALL:
-                       ret = event_kernel_disable_event_all(kchan);
-                       if (ret != LTTNG_OK) {
-                               goto error_unlock;
-                       }
-                       break;
-               case LTTNG_EVENT_TRACEPOINT:    /* fall-through */
+               case LTTNG_EVENT_TRACEPOINT:
                case LTTNG_EVENT_SYSCALL:
-                       if (!strcmp(event_name, "*")) {
-                               ret = event_kernel_disable_event_type(kchan,
-                                       event->type);
+               case LTTNG_EVENT_PROBE:
+               case LTTNG_EVENT_FUNCTION:
+               case LTTNG_EVENT_FUNCTION_ENTRY:/* fall-through */
+                       if (event_name[0] == '\0') {
+                               ret = event_kernel_disable_event(kchan,
+                                       NULL, event->type);
                        } else {
                                ret = event_kernel_disable_event(kchan,
-                                       event_name);
-                       }
-                       if (ret != LTTNG_OK) {
-                               goto error_unlock;
+                                       event_name, event->type);
                        }
-                       break;
-               case LTTNG_EVENT_PROBE:
-               case LTTNG_EVENT_FUNCTION:
-               case LTTNG_EVENT_FUNCTION_ENTRY:
-                       ret = event_kernel_disable_event(kchan, event_name);
                        if (ret != LTTNG_OK) {
                                goto error_unlock;
                        }
@@ -1273,7 +1263,7 @@ int cmd_disable_event(struct ltt_session *session,
 
                /*
                 * If a non-default channel has been created in the
-                * session, explicitely require that -c chan_name needs
+                * session, explicitly require that -c chan_name needs
                 * to be provided.
                 */
                if (usess->has_non_default_channel && channel_name[0] == '\0') {
@@ -1290,7 +1280,16 @@ int cmd_disable_event(struct ltt_session *session,
 
                switch (event->type) {
                case LTTNG_EVENT_ALL:
-                       ret = event_ust_disable_tracepoint(usess, uchan, event_name);
+                       /*
+                        * An empty event name means that everything
+                        * should be disabled.
+                        */
+                       if (event->name[0] == '\0') {
+                               ret = event_ust_disable_all_tracepoints(usess, uchan);
+                       } else {
+                               ret = event_ust_disable_tracepoint(usess, uchan,
+                                               event_name);
+                       }
                        if (ret != LTTNG_OK) {
                                goto error_unlock;
                        }
@@ -1326,8 +1325,11 @@ int cmd_disable_event(struct ltt_session *session,
                        ret = -LTTNG_ERR_UST_EVENT_NOT_FOUND;
                        goto error_unlock;
                }
-               /* The wild card * means that everything should be disabled. */
-               if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
+               /*
+                * An empty event name means that everything
+                * should be disabled.
+                */
+               if (event->name[0] == '\0') {
                        ret = event_agent_disable_all(usess, agt);
                } else {
                        ret = event_agent_disable(usess, agt, event_name);
@@ -1358,6 +1360,12 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                char *channel_name, struct lttng_event_context *ctx, int kwpipe)
 {
        int ret, chan_kern_created = 0, chan_ust_created = 0;
+       char *app_ctx_provider_name = NULL, *app_ctx_name = NULL;
+
+       if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
+               app_ctx_provider_name = ctx->u.app_ctx.provider_name;
+               app_ctx_name = ctx->u.app_ctx.ctx_name;
+       }
 
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
@@ -1377,6 +1385,29 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                        goto error;
                }
                break;
+       case LTTNG_DOMAIN_JUL:
+       case LTTNG_DOMAIN_LOG4J:
+       {
+               /*
+                * Validate channel name.
+                * If no channel name is given and the domain is JUL or LOG4J,
+                * set it to the appropriate domain-specific channel name. If
+                * a name is provided but does not match the expexted channel
+                * name, return an error.
+                */
+               if (domain == LTTNG_DOMAIN_JUL && *channel_name &&
+                               strcmp(channel_name,
+                               DEFAULT_JUL_CHANNEL_NAME)) {
+                       ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+                       goto error;
+               } else if (domain == LTTNG_DOMAIN_LOG4J && *channel_name &&
+                               strcmp(channel_name,
+                               DEFAULT_LOG4J_CHANNEL_NAME)) {
+                       ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+                       goto error;
+               }
+               /* break is _not_ missing here. */
+       }
        case LTTNG_DOMAIN_UST:
        {
                struct ltt_ust_session *usess = session->ust_session;
@@ -1404,6 +1435,10 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                }
 
                ret = context_ust_add(usess, domain, ctx, channel_name);
+               free(app_ctx_provider_name);
+               free(app_ctx_name);
+               app_ctx_name = NULL;
+               app_ctx_provider_name = NULL;
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1414,7 +1449,8 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                goto error;
        }
 
-       return LTTNG_OK;
+       ret = LTTNG_OK;
+       goto end;
 
 error:
        if (chan_kern_created) {
@@ -1438,6 +1474,9 @@ error:
                                uchan);
                trace_ust_destroy_channel(uchan);
        }
+end:
+       free(app_ctx_provider_name);
+       free(app_ctx_name);
        return ret;
 }
 
@@ -1752,7 +1791,7 @@ static int _cmd_enable_event(struct ltt_session *session,
                filter_expression = NULL;
                filter = NULL;
                exclusion = NULL;
-               if (ret != LTTNG_OK) {
+               if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
                        goto error;
                }
                break;
@@ -2757,7 +2796,11 @@ ssize_t cmd_list_events(enum lttng_domain_type domain,
                        rcu_read_lock();
                        cds_lfht_for_each_entry(session->ust_session->agents->ht,
                                        &iter.iter, agt, node.node) {
-                               nb_event = list_lttng_agent_events(agt, events);
+                               if (agt->domain == domain) {
+                                       nb_event = list_lttng_agent_events(
+                                                       agt, events);
+                                       break;
+                               }
                        }
                        rcu_read_unlock();
                }
This page took 0.025508 seconds and 4 git commands to generate.