From: Jonathan Rajotte Date: Tue, 22 Mar 2016 18:12:08 +0000 (-0400) Subject: Refactor: embed mi in "add_output "to remove code duplication X-Git-Tag: v2.9.0-rc1~300 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=779f455d7b2074388346c75ec842112819fec8b8;p=lttng-tools.git Refactor: embed mi in "add_output "to remove code duplication Reduces the number of possible code paths and ensure a coherent return path. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c index b2e376758..c8a7ba058 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -266,55 +266,6 @@ error: return ret; } -/* - * Add output from the user URL (machine interface). - */ -static int mi_add_output(const char *url) -{ - int ret; - struct lttng_snapshot_output *output = NULL; - char name[NAME_MAX]; - const char *n_ptr; - - if (!url && (!opt_data_url || !opt_ctrl_url)) { - ret = CMD_ERROR; - goto error; - } - - output = create_output_from_args(url); - if (!output) { - ret = CMD_FATAL; - goto error; - } - - /* This call, if successful, populates the id of the output object. */ - ret = lttng_snapshot_add_output(current_session_name, output); - if (ret < 0) { - goto error; - } - - n_ptr = lttng_snapshot_output_get_name(output); - if (*n_ptr == '\0') { - int pret; - pret = snprintf(name, sizeof(name), DEFAULT_SNAPSHOT_NAME "-%" PRIu32, - lttng_snapshot_output_get_id(output)); - if (pret < 0) { - PERROR("snprintf add output name"); - } - n_ptr = name; - } - - ret = mi_lttng_snapshot_add_output(writer, current_session_name, n_ptr, - output); - if (ret) { - ret = CMD_ERROR; - } - -error: - lttng_snapshot_output_destroy(output); - return ret; -} - /* * Add output from the user URL. */ @@ -359,6 +310,13 @@ static int add_output(const char *url) lttng_snapshot_output_get_id(output), n_ptr, lttng_snapshot_output_get_ctrl_url(output), lttng_snapshot_output_get_maxsize(output)); + if (lttng_opt_mi) { + ret = mi_lttng_snapshot_add_output(writer, current_session_name, + n_ptr, output); + if (ret) { + ret = CMD_ERROR; + } + } error: lttng_snapshot_output_destroy(output); return ret; @@ -373,11 +331,7 @@ static int cmd_add_output(int argc, const char **argv) goto end; } - if (lttng_opt_mi) { - ret = mi_add_output(argv[1]); - } else { - ret = add_output(argv[1]); - } + ret = add_output(argv[1]); end: return ret;