[lttng-dev] [PATCH lttng-tools] Fix: set session should not set not-existent session

Jérémie Galarneau jeremie.galarneau at efficios.com
Mon Aug 3 14:58:49 EDT 2015


Merged in master, stable-2.7, stable-2.6 and stable-2.5. Thanks!

Jérémie

On Sat, Jul 25, 2015 at 3:55 AM, Partha Pratim Mukherjee <
ppm.floss at gmail.com> wrote:

> set session does not check the existence of a session before setting
> it as the current session. Fix it so that it gives error for
> not-existent session.
>
> Fixes: #885
>
> Signed-off-by: Partha Pratim Mukherjee <ppm.floss at gmail.com>
> ---
>  src/bin/lttng/commands/set_session.c |   25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>
> diff --git a/src/bin/lttng/commands/set_session.c
> b/src/bin/lttng/commands/set_session.c
> index 3196f12..14fe9af 100644
> --- a/src/bin/lttng/commands/set_session.c
> +++ b/src/bin/lttng/commands/set_session.c
> @@ -106,11 +106,34 @@ end:
>  static int set_session(void)
>  {
>         int ret = CMD_SUCCESS;
> +       int count, i;
> +       unsigned int session_found = 0;
> +       struct lttng_session *sessions;
>
>         if (opt_session_name && strlen(opt_session_name) > NAME_MAX) {
>                 ERR("Session name too long. Length must be lower or equal
> to %d",
>                         NAME_MAX);
>                 ret = CMD_ERROR;
> +               goto end;
> +       }
> +
> +       count = lttng_list_sessions(&sessions);
> +       if (count < 0) {
> +               ret = CMD_ERROR;
> +               ERR("%s", lttng_strerror(count));
> +               goto end;
> +       }
> +
> +       for (i = 0; i < count; i++) {
> +               if (strncmp(sessions[i].name, opt_session_name, NAME_MAX)
> == 0) {
> +                       session_found = 1;
> +                       break;
> +               }
> +       }
> +
> +       if (!session_found) {
> +               ERR("Session '%s' not found", opt_session_name);
> +               ret = CMD_ERROR;
>                 goto error;
>         }
>
> @@ -133,6 +156,8 @@ static int set_session(void)
>         ret = CMD_SUCCESS;
>
>  error:
> +       free(sessions);
> +end:
>         return ret;
>  }
>
> --
> 1.7.10.4
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150803/3080ceca/attachment.html>


More information about the lttng-dev mailing list