Refactor: embed mi in "del_record" to remove code duplication
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 22 Mar 2016 18:12:07 +0000 (14:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 4 Apr 2016 15:38:26 +0000 (11:38 -0400)
Reduces the number of possible code paths and ensure a coherent return
path.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/snapshot.c

index ce63e5e875c858fc749a1e63199605469c5fc87a..b2e376758ac5989a2ec77a813d10830adef9df1a 100644 (file)
@@ -213,50 +213,6 @@ error:
        return ret;
 }
 
        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.
  */
 /*
  * Delete output by ID.
  */
@@ -297,6 +253,14 @@ static int del_output(uint32_t id, const char *name)
                                name, current_session_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;
 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) {
        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') {
        } 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;
        } else {
                ERR("Argument %s not recognized", argv[1]);
                ret = -1;
This page took 0.036543 seconds and 4 git commands to generate.