X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Fltt-sessiond.c;h=4f9ca1bd4d2e45396edbbe367a165dca50af3830;hp=45f79a70980a4506b5dfc34f57f0cf17622cce7c;hb=7e6e59cdaccc23e1e69166490f7167a396748d69;hpb=c01bdd9d853345f49985ed448198bf1a8ac27e79 diff --git a/ltt-sessiond/ltt-sessiond.c b/ltt-sessiond/ltt-sessiond.c index 45f79a709..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; } @@ -812,16 +827,15 @@ end: */ static void usage(void) { - fprintf(stderr, "Usage:\n%s OPTIONS\n\nOptions:\n" - "\t-h, --help\t\tDisplay this usage.\n" - "\t-c, --client-sock PATH\t\tSpecify path for the client unix socket\n" - "\t-a, --apps-sock PATH\t\tSpecify path for apps unix socket.\n" - "\t-d, --daemonize\t\tStart as a daemon.\n" - "\t-g, --group NAME\t\tSpecify the tracing group name. (default: tracing)\n" - "\t-V, --version\t\tShow version number.\n" - "\t-S, --sig-parent\t\tSend SIGCHLD to parent pid to notify readiness.\n" - "\t-q, --quiet\t\tNo output at all.\n", - progname); + fprintf(stderr, "Usage: %s OPTIONS\n\nOptions:\n", progname); + fprintf(stderr, " -h, --help Display this usage.\n"); + fprintf(stderr, " -c, --client-sock PATH Specify path for the client unix socket\n"); + fprintf(stderr, " -a, --apps-sock PATH Specify path for apps unix socket.\n"); + fprintf(stderr, " -d, --daemonize Start as a daemon.\n"); + fprintf(stderr, " -g, --group NAME Specify the tracing group name. (default: tracing)\n"); + fprintf(stderr, " -V, --version Show version number.\n"); + fprintf(stderr, " -S, --sig-parent Send SIGCHLD to parent pid to notify readiness.\n"); + fprintf(stderr, " -q, --quiet No output at all.\n"); } /* @@ -857,7 +871,7 @@ static int parse_args(int argc, char **argv) fprintf(stderr, " with arg %s\n", optarg); } break; - case 's': + case 'c': snprintf(client_unix_sock_path, PATH_MAX, "%s", optarg); break; case 'a': @@ -1072,8 +1086,8 @@ static void sighandler(int sig) static void cleanup() { /* */ - MSG("\n\n%c[%d;%dm*** assert failed *** ==> %c[%dm", 27,1,31,27,0); - MSG("%c[%d;%dm Matthew, BEET driven development works!%c[%dm\n",27,1,33,27,0); + MSG("\n%c[%d;%dm*** assert failed *** ==> %c[%dm", 27,1,31,27,0); + MSG("%c[%d;%dmMatthew, BEET driven development works!%c[%dm",27,1,33,27,0); /* */ unlink(client_unix_sock_path); @@ -1137,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) {