From: David Goulet Date: Thu, 28 Apr 2011 18:27:46 +0000 (-0400) Subject: Deny multiple session with the same name X-Git-Tag: v2.0-pre1~171 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=27673bb674a1b11ad5f11f585360e031b5baccb1;p=lttng-tools.git Deny multiple session with the same name 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 --- diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index 2ab185ce9..f9cdede85 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -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", }; /* diff --git a/liblttsessiondcomm/liblttsessiondcomm.h b/liblttsessiondcomm/liblttsessiondcomm.h index 540241a62..41c2cd419 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.h +++ b/liblttsessiondcomm/liblttsessiondcomm.h @@ -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 */ }; diff --git a/ltt-sessiond/ltt-sessiond.c b/ltt-sessiond/ltt-sessiond.c index 839c5204d..275088f07 100644 --- a/ltt-sessiond/ltt-sessiond.c +++ b/ltt-sessiond/ltt-sessiond.c @@ -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; } diff --git a/tests/ltt-sessiond/run.sh b/tests/ltt-sessiond/run.sh index f8bdf7fef..b378285ed 100755 --- a/tests/ltt-sessiond/run.sh +++ b/tests/ltt-sessiond/run.sh @@ -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