X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Fltt-sessiond.c;h=4f9ca1bd4d2e45396edbbe367a165dca50af3830;hp=9c33ff9ec40e71a00ccd5dd4a860e21154a20cd6;hb=60cdef54fab0dea23a80ab199064128ab559af84;hpb=b716ce682239502527ac1faac4d8aa6e84c78729 diff --git a/ltt-sessiond/ltt-sessiond.c b/ltt-sessiond/ltt-sessiond.c index 9c33ff9ec..4f9ca1bd4 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; } /* @@ -676,6 +684,7 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm) { int ret; int buf_size; + size_t header_size; char *send_buf = NULL; struct lttcomm_lttng_msg llm; @@ -696,18 +705,24 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm) } } - /* Default return code. * In our world, everything is OK... right? ;) */ llm.ret_code = LTTCOMM_OK; + header_size = sizeof(struct lttcomm_lttng_msg); + /* Process by command type */ switch (lsm->cmd_type) { case LTTNG_CREATE_SESSION: { 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; } @@ -758,7 +773,7 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm) goto end; } - get_list_apps((pid_t *)(send_buf + sizeof(struct lttcomm_lttng_msg))); + get_list_apps((pid_t *)(send_buf + header_size)); break; } @@ -778,7 +793,7 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm) goto end; } - get_list_sessions((struct lttng_session *)(send_buf + sizeof(struct lttcomm_lttng_msg))); + get_list_sessions((struct lttng_session *)(send_buf + header_size)); break; } @@ -1136,7 +1151,10 @@ int main(int argc, char **argv) */ if ((ret = check_existing_daemon()) == 0) { ERR("Already running daemon.\n"); - goto error; + /* We do not goto error because we must not + * cleanup() because a daemon is already working. + */ + return EXIT_FAILURE; } if (set_signal_handler() < 0) {