From: Jonathan Rajotte Date: Tue, 22 Mar 2016 18:12:07 +0000 (-0400) Subject: Refactor: embed mi in "del_record" to remove code duplication X-Git-Tag: v2.9.0-rc1~301 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=6546176b5450956323693480451bdbd17ca9a66a Refactor: embed mi in "del_record" 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 ce63e5e87..b2e376758 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -213,50 +213,6 @@ error: return ret; } -/* - * Delete output by ID (machine interface version). - */ -static int mi_del_output(uint32_t id, const char *name) -{ - int ret; - struct lttng_snapshot_output *output = NULL; - - assert(writer); - - output = lttng_snapshot_output_create(); - if (!output) { - ret = CMD_FATAL; - goto error; - } - - if (name) { - ret = lttng_snapshot_output_set_name(name, output); - } else if (id != UINT32_MAX) { - ret = lttng_snapshot_output_set_id(id, output); - } else { - ret = CMD_ERROR; - goto error; - } - if (ret < 0) { - ret = CMD_FATAL; - goto error; - } - - ret = lttng_snapshot_del_output(current_session_name, output); - if (ret < 0) { - goto error; - } - - ret = mi_lttng_snapshot_del_output(writer, id, name, current_session_name); - if (ret) { - ret = CMD_ERROR; - } - -error: - lttng_snapshot_output_destroy(output); - return ret; -} - /* * Delete output by ID. */ @@ -297,6 +253,14 @@ static int del_output(uint32_t id, const char *name) name, current_session_name); } + if (lttng_opt_mi) { + ret = mi_lttng_snapshot_del_output(writer, id, name, + current_session_name); + if (ret) { + ret = CMD_ERROR; + } + } + error: lttng_snapshot_output_destroy(output); return ret; @@ -433,17 +397,9 @@ static int cmd_del_output(int argc, const char **argv) errno = 0; id = strtol(argv[1], &name, 10); if (id == 0 && errno == 0) { - if (lttng_opt_mi) { - ret = mi_del_output(UINT32_MAX, name); - } else { - ret = del_output(UINT32_MAX, name); - } + ret = del_output(UINT32_MAX, name); } else if (errno == 0 && *name == '\0') { - if (lttng_opt_mi) { - ret = mi_del_output(id, NULL); - } else { - ret = del_output(id, NULL); - } + ret = del_output(id, NULL); } else { ERR("Argument %s not recognized", argv[1]); ret = -1;