X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fset_session.c;h=14fe9afd8362ee20eaaf2bc5618460af7217d953;hb=7f0c090ded845bb58c341f75d28d2379db5c3e7e;hp=3196f12bdd3863373938267a4106241eaac9100c;hpb=44c1a903e17ad14d5ba1cd07585a7a2415eac78a;p=lttng-tools.git diff --git a/src/bin/lttng/commands/set_session.c b/src/bin/lttng/commands/set_session.c index 3196f12bd..14fe9afd8 100644 --- a/src/bin/lttng/commands/set_session.c +++ b/src/bin/lttng/commands/set_session.c @@ -106,11 +106,34 @@ end: static int set_session(void) { int ret = CMD_SUCCESS; + int count, i; + unsigned int session_found = 0; + struct lttng_session *sessions; if (opt_session_name && strlen(opt_session_name) > NAME_MAX) { ERR("Session name too long. Length must be lower or equal to %d", NAME_MAX); ret = CMD_ERROR; + goto end; + } + + count = lttng_list_sessions(&sessions); + if (count < 0) { + ret = CMD_ERROR; + ERR("%s", lttng_strerror(count)); + goto end; + } + + for (i = 0; i < count; i++) { + if (strncmp(sessions[i].name, opt_session_name, NAME_MAX) == 0) { + session_found = 1; + break; + } + } + + if (!session_found) { + ERR("Session '%s' not found", opt_session_name); + ret = CMD_ERROR; goto error; } @@ -133,6 +156,8 @@ static int set_session(void) ret = CMD_SUCCESS; error: + free(sessions); +end: return ret; }