Add support for context in enable-event template
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 27 Jun 2016 19:11:20 +0000 (15:11 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 11 Jul 2016 15:20:33 +0000 (11:20 -0400)
src/bin/lttng/commands/enable_events.c
src/common/config/session-config.c
src/common/config/session-config.h

index 9bd3e84ee0283e5f40c2b914593024d41e699eff..592857c8820c17fa8c95b7bff006267d9f899fab 100644 (file)
@@ -1415,6 +1415,32 @@ static int enable_event_template_per_domain(const struct config_document *docume
        assert(config);
 
 
+       /* Fetch contexts element */
+       printed_bytes = asprintf(&query, "//sessions/session/domains/domain[./type = '%s']/channels/channel/contexts", config_get_domain_str(config->domain_type));
+       if (printed_bytes <= 0) {
+               ERR("Asprintf template events query");
+               ret = -1;
+               goto end;
+       }
+
+       config_document_get_element_array(document, query, &element_array, &element_array_size);
+       if (element_array) {
+               if (element_array_size != 1) {
+                       ERR("Invalid document");
+                       goto end;
+               }
+               ret = config_process_contexts_element(element_array[0], session_name, config->domain_type, config->channel_name);
+               if (ret) {
+                       ERR("Contexts processing for domain %s channel %s : %s", config_get_domain_str(config->domain_type), config->channel_name, lttng_strerror(ret));
+                       goto end;
+               }
+               config_element_free_array(element_array, element_array_size);
+               element_array = NULL;
+               element_array_size = 0;
+       }
+
+
+       /* Fetch event element */
        printed_bytes = asprintf(&query, "//sessions/session/domains/domain[./type = '%s']/channels/channel/events/event[./enabled = 'true']", config_get_domain_str(config->domain_type));
        if (printed_bytes <= 0) {
                ERR("Asprintf template events query");
index 739627ab1757af30884a762f93da61252f54e725..ddb586f8e8f2c83681aef6d67a0a287adece3713 100644 (file)
@@ -2162,7 +2162,6 @@ int process_context_node(xmlNodePtr context_node,
        xmlNodePtr context_child_node = xmlFirstElementChild(context_node);
 
        assert(handle);
-       assert(channel_name);
 
        if (!context_child_node) {
                ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
@@ -4203,3 +4202,55 @@ error:
        free(handle);
        return ret;
 }
+
+LTTNG_HIDDEN
+int config_process_contexts_element(const struct config_element *element, const char *session_name, int domain_type, const char *channel_name) {
+       int ret = 0;
+       xmlNodePtr node;
+       struct lttng_domain domain;
+       struct lttng_handle *handle;
+
+       assert(element);
+       assert(element->element);
+
+       memset(&domain, 0, sizeof(struct lttng_domain));
+
+       /* Create handle */
+       domain.type = domain_type;
+       switch (domain.type) {
+               case LTTNG_DOMAIN_KERNEL:
+                       domain.buf_type = LTTNG_BUFFER_GLOBAL;
+                       break;
+               case LTTNG_DOMAIN_UST:
+               case LTTNG_DOMAIN_JUL:
+               case LTTNG_DOMAIN_LOG4J:
+               case LTTNG_DOMAIN_PYTHON:
+                       domain.buf_type = LTTNG_BUFFER_PER_UID;
+                       break;
+               case LTTNG_DOMAIN_NONE:
+               default:
+                       assert(0);
+       }
+
+       handle = lttng_create_handle(session_name, &domain);
+       if (!handle) {
+               ret = -LTTNG_ERR_HANDLE_CREATION;
+               goto error;
+       }
+
+
+       node = element->element;
+       /* Check if element is really a context list node (contexts) */
+       if (xmlStrcmp(BAD_CAST config_element_contexts, node->name)) {
+               ret = -LTTNG_ERR_CONFIG_INVALID_ELEMENT;
+               goto error;
+       }
+
+       ret = process_contexts_node(node, handle, channel_name);
+       if (ret) {
+               goto error;
+       }
+error:
+       free(handle);
+       return ret;
+}
index b441f4a33021998202743f9317103a06ae1c5fe1..e3fc1702d14c7cab9c73b7b9d3bd4e4dab12da38 100644 (file)
@@ -482,4 +482,19 @@ char *config_element_get_element_value(const struct config_element *element, con
 LTTNG_HIDDEN
 int config_process_event_element(const struct config_element *element, const char* session_name, int domain_type, const char *channel_name);
 
+/*
+ * Process an element matching a contexts configuration and try to apply it.
+ *
+ * element The element to process
+ * session_name The session name.
+ * domain_type The domain type.
+ * channel_name The channel name.
+ *              A NULL channel name will default to the default domain
+ *              channel.
+ *
+ * Returns zero if the contexts could be applied successfully. Returns
+ * a negative LTTNG_ERR code on error.
+ */
+int config_process_contexts_element(const struct config_element *element, const char *session_name, int domain_type, const char *channel_name);
+
 #endif /* _CONFIG_H */
This page took 0.031583 seconds and 5 git commands to generate.