Make code simpler for send buffer header size
[lttng-tools.git] / ltt-sessiond / ltt-sessiond.c
index 839c5204d08db774653090516a1cf803d968c854..4f9ca1bd4d2e45396edbbe367a165dca50af3830 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;
 }
 
 /*
@@ -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;
                }
This page took 0.024065 seconds and 4 git commands to generate.