Fix: set session should not set non-existent session
authorPartha Pratim Mukherjee <ppm.floss@gmail.com>
Sat, 25 Jul 2015 07:55:19 +0000 (13:25 +0530)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 28 Jul 2015 15:52:26 +0000 (11:52 -0400)
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 a
non-existent session.

Fixes #885

Signed-off-by: Partha Pratim Mukherjee <ppm.floss@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/set_session.c

index fd3d9a11813a3a7fdd9bb9f8b47afb8a74b0e4ca..effc41f77ec5647a6781039b2e7fc3446db42c8d 100644 (file)
@@ -105,11 +105,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;
        }
 
@@ -132,6 +155,8 @@ static int set_session(void)
        ret = CMD_SUCCESS;
 
 error:
+       free(sessions);
+end:
        return ret;
 }
 
This page took 0.026212 seconds and 4 git commands to generate.