From e0988a8ce724d4b6232e46fbdc180ed33b26a64f Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Mon, 4 Jul 2016 15:29:56 -0400 Subject: [PATCH] Fix: generate a full output configuration node The lttng save --omit-output does not remove the destination node but the full output node. Make sure to create a full one. --- src/bin/lttng/commands/create.c | 97 ++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 8 deletions(-) diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index c8027133d..7581624ad 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -765,6 +765,59 @@ static int create_session_from_template(struct config_document *template, config_element_free(temp_element_child); temp_element_child = NULL; + /* Construct the output/consumer_output/ node*/ + temp_element_child = temp_element; + temp_element = config_element_create("consumer_output", NULL); + if (!temp_element) { + ERR("Could not create consumer_output node configuration"); + ret = CMD_ERROR; + goto error; + } + + ret = config_element_add_child(temp_element, temp_element_child); + if (ret) { + ERR("Could not append output data to the consumer_output node configuration"); + ret = CMD_ERROR; + goto error; + } + + config_element_free(temp_element_child); + temp_element_child = config_element_create("enabled", "true"); + if (!temp_element_child) { + ERR("Could not create enbaled node configuration"); + ret = CMD_ERROR; + goto error; + } + + ret = config_element_add_child(temp_element, temp_element_child); + if (ret) { + ERR("Could not append node to the consumer_output node configuration"); + ret = CMD_ERROR; + goto error; + } + + config_element_free(temp_element_child); + temp_element_child = NULL; + + + temp_element_child = temp_element; + temp_element = config_element_create("output", NULL); + if (!temp_element) { + ERR("Could not create output node configuration"); + ret = CMD_ERROR; + goto error; + } + + ret = config_element_add_child(temp_element, temp_element_child); + if (ret) { + ERR("Could not append output data to the output node configuration"); + ret = CMD_ERROR; + goto error; + } + + config_element_free(temp_element_child); + temp_element_child = NULL; + /* * validate and replace the destination node for each session type @@ -774,22 +827,44 @@ static int create_session_from_template(struct config_document *template, switch (session_type) { case SESSION_NORMAL: case SESSION_LIVE: - if (!config_document_element_exist(template, "/sessions/session/output/consumer_output/destination")) { - ERR("Invalid template no destination node configuration present"); + break; + case SESSION_SNAPSHOT: + /* construct the output/snapshots_outputs/ */ + temp_element_child = temp_element; + temp_element = config_element_create("snapshot_outputs", NULL); + if (!temp_element) { + ERR("Could not create snapshot_outputs node configuration"); ret = CMD_ERROR; goto error; } - ret = config_document_replace_element(template, "/sessions/session/output/consumer_output/destination", temp_element); - break; - case SESSION_SNAPSHOT: - if (!config_document_element_exist(template, "/sessions/session/output/snapshot_outputs/output/consumer_output/destination")) { - ERR("Invalid template no destination node configuration present"); + ret = config_element_add_child(temp_element, temp_element_child); + if (ret) { + ERR("Could not append output data to the snapshot_outputs node configuration"); ret = CMD_ERROR; goto error; } - ret = config_document_replace_element(template, "/sessions/session/output/snapshot_outputs/output/consumer_output/destination", temp_element); + config_element_free(temp_element_child); + temp_element_child = NULL; + + temp_element_child = temp_element; + temp_element = config_element_create("output", NULL); + if (!temp_element) { + ERR("Could not create output node configuration"); + ret = CMD_ERROR; + goto error; + } + + ret = config_element_add_child(temp_element, temp_element_child); + if (ret) { + ERR("Could not append output data to the output node configuration"); + ret = CMD_ERROR; + goto error; + } + + config_element_free(temp_element_child); + temp_element_child = NULL; break; default: ERR("Invalid session type"); @@ -797,6 +872,12 @@ static int create_session_from_template(struct config_document *template, goto error; } + if (!config_document_element_exist(template, "/sessions/session/output")) { + ret = config_document_insert_element(template, "/sessions/session", temp_element); + } else { + ret = config_document_replace_element(template, "/sessions/session/output", temp_element); + } + config_element_free(temp_element); temp_element = NULL; -- 2.34.1