From cde3e505b7948c15880114268534d21fb1f10a1c Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 25 Feb 2014 14:22:19 -0500 Subject: [PATCH] Fix: don't start session if no channel This adds a new error code that indicates that the session contains NO channel. Fixes #715 Signed-off-by: David Goulet --- include/lttng/lttng-error.h | 2 +- src/bin/lttng-sessiond/cmd.c | 16 ++++++++++++++++ src/common/error.c | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index 93a8c2187..93196fe2b 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -102,7 +102,7 @@ enum lttng_error_code { LTTNG_ERR_UST_CONSUMER32_FAIL = 69, /* 32-bit UST consumer start failed */ LTTNG_ERR_UST_STREAM_FAIL = 70, /* UST create stream failed */ LTTNG_ERR_SNAPSHOT_NODATA = 71, /* No data in snapshot. */ - /* 72 */ + LTTNG_ERR_NO_CHANNEL = 72, /* No channel found in the session. */ /* 73 */ LTTNG_ERR_UST_LIST_FAIL = 74, /* UST listing events failed */ LTTNG_ERR_UST_EVENT_EXIST = 75, /* UST event exist */ diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index dc465173e..5bf00be85 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1779,6 +1779,7 @@ error: int cmd_start_trace(struct ltt_session *session) { int ret; + unsigned long nb_chan = 0; struct ltt_kernel_session *ksession; struct ltt_ust_session *usess; @@ -1794,6 +1795,21 @@ int cmd_start_trace(struct ltt_session *session) goto error; } + /* + * Starting a session without channel is useless since after that it's not + * possible to enable channel thus inform the client. + */ + if (usess && usess->domain_global.channels) { + nb_chan += lttng_ht_get_count(usess->domain_global.channels); + } + if (ksession) { + nb_chan += ksession->channel_count; + } + if (!nb_chan) { + ret = LTTNG_ERR_NO_CHANNEL; + goto error; + } + session->enabled = 1; /* Kernel tracing */ diff --git a/src/common/error.c b/src/common/error.c index b5e3fcea1..bff21ae71 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -115,6 +115,7 @@ static const char *error_string_array[] = { [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_FAIL) ] = "Snapshot record failed", [ ERROR_INDEX(LTTNG_ERR_CHAN_EXIST) ] = "Channel already exists", [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_NODATA) ] = "No data available in snapshot", + [ ERROR_INDEX(LTTNG_ERR_NO_CHANNEL) ] = "No channel found in the session", /* Last element */ [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code" -- 2.34.1