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

fixes #1002

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 e9c60fbbbba42436bba04dfc891168af96cb7627..ce63e5e875c858fc749a1e63199605469c5fc87a 100644 (file)
@@ -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;
This page took 0.025857 seconds and 4 git commands to generate.