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

Jérémie Galarneau jeremie.galarneau at efficios.com
Mon Apr 4 16:50:00 UTC 2016


Merged, thanks!

Jérémie

On Tue, Mar 22, 2016 at 2:12 PM, Jonathan Rajotte
<jonathan.rajotte-julien at efficios.com> wrote:
> 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 | 62 +++++----------------------------------
>  1 file changed, 8 insertions(+), 54 deletions(-)
>
> diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c
> index b2e3767..c8a7ba0 100644
> --- a/src/bin/lttng/commands/snapshot.c
> +++ b/src/bin/lttng/commands/snapshot.c
> @@ -267,55 +267,6 @@ error:
>  }
>
>  /*
> - * 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.
>   */
>  static int add_output(const char *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;
> --
> 2.7.0
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list