From: ppm.floss@gmail.com (Partha Pratim Mukherjee)
Subject: [lttng-dev] [PATCH lttng-tools] Fix: set session should not set not-existent session
Date: Sat, 25 Jul 2015 13:25:19 +0530 [thread overview]
Message-ID: <87si8cwu1k.fsf@nono.intra.net> (raw)
set session does not check the existence of a session before setting
it as the current session. Fix it so that it gives error for
not-existent session.
Fixes: #885
Signed-off-by: Partha Pratim Mukherjee <ppm.floss at gmail.com>
---
src/bin/lttng/commands/set_session.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/bin/lttng/commands/set_session.c b/src/bin/lttng/commands/set_session.c
index 3196f12..14fe9af 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;
}
--
1.7.10.4
reply other threads:[~2015-07-25 7:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87si8cwu1k.fsf@nono.intra.net \
--to=ppm.floss@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox