From: Jonathan Rajotte Date: Tue, 22 Mar 2016 18:12:06 +0000 (-0400) Subject: Refactor: embed mi in "record" to remove code duplication X-Git-Tag: v2.9.0-rc1~302 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1862dfe0f2d0a7a1ec9a2a127b5559d400db05ba;p=lttng-tools.git Refactor: embed mi in "record" to remove code duplication Reduces the number of possible code paths and ensure a coherent return path. fixes #1002 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 e9c60fbbb..ce63e5e87 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -463,37 +463,6 @@ static int cmd_list_output(int argc, const char **argv) return ret; } -/* - * Do a snapshot record with the URL if one is given (machine interface). - */ -static int mi_record(const char *url) -{ - int ret; - struct lttng_snapshot_output *output = NULL; - - output = create_output_from_args(url); - if (!output) { - ret = CMD_FATAL; - goto error; - } - - ret = lttng_snapshot_record(current_session_name, output, 0); - if (ret < 0) { - ret = CMD_ERROR; - goto error; - } - - ret = mi_lttng_snapshot_record(writer, current_session_name, url, - opt_ctrl_url, opt_data_url); - if (ret) { - ret = CMD_ERROR; - } - -error: - lttng_snapshot_output_destroy(output); - return ret; -} - /* * Do a snapshot record with the URL if one is given. */ @@ -525,6 +494,14 @@ static int record(const char *url) opt_data_url); } + if (lttng_opt_mi) { + ret = mi_lttng_snapshot_record(writer, current_session_name, url, + opt_ctrl_url, opt_data_url); + if (ret) { + ret = CMD_ERROR; + } + } + error: lttng_snapshot_output_destroy(output); return ret; @@ -535,18 +512,9 @@ static int cmd_record(int argc, const char **argv) int ret; if (argc == 2) { - /* With a given URL */ - if (lttng_opt_mi) { - ret = mi_record(argv[1]); - } else { - ret = record(argv[1]); - } + ret = record(argv[1]); } else { - if (lttng_opt_mi) { - ret = mi_record(NULL); - } else { - ret = record(NULL); - } + ret = record(NULL); } return ret;