Docs: add comment to cmd_add_context()
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index b866f73a6b53535557502ae00fee548bfc07e539..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] == '.' ||
@@ -1280,10 +1280,12 @@ int cmd_disable_event(struct ltt_session *session,
 
                switch (event->type) {
                case LTTNG_EVENT_ALL:
-                       if (strlen(event->name) == 1 &&
-                                       !strncmp(event->name, "*", 1)) {
-                               ret = event_ust_disable_all_tracepoints(usess,
-                                               uchan);
+                       /*
+                        * 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);
@@ -1323,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);
@@ -1355,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:
@@ -1374,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;
@@ -1401,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;
                }
@@ -1411,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) {
@@ -1435,6 +1474,9 @@ error:
                                uchan);
                trace_ust_destroy_channel(uchan);
        }
+end:
+       free(app_ctx_provider_name);
+       free(app_ctx_name);
        return ret;
 }
 
@@ -1749,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;
This page took 0.025594 seconds and 4 git commands to generate.