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");
xmlNodePtr context_child_node = xmlFirstElementChild(context_node);
assert(handle);
- assert(channel_name);
if (!context_child_node) {
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
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;
+}
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 */