Deny multiple session with the same name
authorDavid Goulet <david.goulet@polymtl.ca>
Thu, 28 Apr 2011 18:27:46 +0000 (14:27 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 28 Apr 2011 18:29:52 +0000 (14:29 -0400)
This commit fixes the possibility of creating two or more
sessions with the same name.

Also fixes a small bug in the sessiond test.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
liblttsessiondcomm/liblttsessiondcomm.c
liblttsessiondcomm/liblttsessiondcomm.h
ltt-sessiond/ltt-sessiond.c
tests/ltt-sessiond/run.sh

index 2ab185ce950c03e3f0f870838db069edf4e3b68f..f9cdede856fc1a6037b2f1d9cfb554fd611ea602 100644 (file)
@@ -45,6 +45,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_START_FAIL) ] = "Start trace failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACEABLE) ] = "App is not traceable",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_SELECT_SESS) ] = "A session MUST be selected",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_EXIST_SESS) ] = "Session name already exist",
 };
 
 /*
index 540241a62df1078c4109d15c83d58d86757b552f..41c2cd419db807acc9a8d608997d6595210b8dc4 100644 (file)
@@ -78,6 +78,7 @@ enum lttcomm_return_code {
        LTTCOMM_FATAL,                  /* Session daemon had a fatal error */
        LTTCOMM_NO_TRACEABLE,   /* Error for non traceable app */
        LTTCOMM_SELECT_SESS,    /* Must select a session */
+       LTTCOMM_EXIST_SESS,             /* Session name already exist */
        LTTCOMM_NR,                             /* Last element */
 };
 
index 839c5204d08db774653090516a1cf803d968c854..275088f075e959fcfe07ddbd966c73c060646fdd 100644 (file)
@@ -477,21 +477,26 @@ static int create_session(char *name, uuid_t *session_id)
 {
        struct ltt_session *new_session;
 
+       new_session = find_session_by_name(name);
+       if (new_session != NULL) {
+               goto error;
+       }
+
        /* Allocate session data structure */
        new_session = malloc(sizeof(struct ltt_session));
        if (new_session == NULL) {
                perror("malloc");
-               goto error;
+               goto error_mem;
        }
 
        if (name != NULL) {
                if (asprintf(&new_session->name, "%s", name) < 0) {
-                       goto error;
+                       goto error_mem;
                }
        } else {
                /* Generate session name based on the session count */
                if (asprintf(&new_session->name, "%s%d", "lttng-", session_count) < 0) {
-                       goto error;
+                       goto error_mem;
                }
        }
 
@@ -516,6 +521,9 @@ static int create_session(char *name, uuid_t *session_id)
 
 error:
        return -1;
+
+error_mem:
+       return -ENOMEM;
 }
 
 /*
@@ -708,6 +716,11 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm)
                {
                        ret = create_session(lsm->session_name, &llm.session_id);
                        if (ret < 0) {
+                               if (ret == -1) {
+                                       ret = LTTCOMM_EXIST_SESS;
+                               } else {
+                                       ret = LTTCOMM_FATAL;
+                               }
                                goto end;
                        }
 
index f8bdf7fef006dea0ad771658846e85f0ef55bdf5..b378285ed008dacdb7dafe62f474b624402a7e08 100755 (executable)
@@ -93,7 +93,7 @@ function test_session_same_name()
 {
        lttng_create_session "test-same"
        lttng_create_session "test-same"
-       if [ $LTTNG_RET_CODE -ne 1 ]; then
+       if [ $LTTNG_RET_CODE -ne 0 ]; then
                echo "[-] Session with the same name: FAILED!"
                printf "Two session having the same name NOT ALLOWED\n"
                clean_exit 1
This page took 0.02877 seconds and 4 git commands to generate.