Refactor: embed mi in "add_output "to remove code duplication
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 22 Mar 2016 18:12:08 +0000 (14:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 4 Apr 2016 15:38:28 +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 b2e376758ac5989a2ec77a813d10830adef9df1a..c8a7ba0588f4d47fcc5ed5de98101caee937ace5 100644 (file)
@@ -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;
This page took 0.035791 seconds and 4 git commands to generate.