[lttng-dev] [PATCH lttng-tools v2 4/5] Refactor: embed mi in "del_record" to remove code duplication

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Tue Mar 22 18:12:07 UTC 2016


Reduces the number of possible code paths and ensure a coherent return
path.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 src/bin/lttng/commands/snapshot.c | 64 ++++++---------------------------------
 1 file changed, 10 insertions(+), 54 deletions(-)

diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c
index ce63e5e..b2e3767 100644
--- a/src/bin/lttng/commands/snapshot.c
+++ b/src/bin/lttng/commands/snapshot.c
@@ -214,50 +214,6 @@ error:
 }
 
 /*
- * 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.
  */
 static int del_output(uint32_t id, const char *name)
@@ -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;
-- 
2.7.0



More information about the lttng-dev mailing list