From 8382cf6f76c29b0451b7fe986c6b882d6029ca47 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 25 Mar 2014 12:14:01 -0400 Subject: [PATCH] Rename variable in session.h for clarity The "started" var. is changed to the flag "has_been_started" indicating if at least ONE start command has been seen. The "enabled" var. is changed to the flag "active" and the semantic is the same. Signed-off-by: David Goulet --- src/bin/lttng-sessiond/cmd.c | 49 +++++++++++--------------------- src/bin/lttng-sessiond/save.c | 2 +- src/bin/lttng-sessiond/session.h | 10 +++++-- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 6df18935e..161680a6c 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -916,7 +916,7 @@ int cmd_enable_channel(struct ltt_session *session, * Don't try to enable a channel if the session has been started at * some point in time before. The tracer does not allow it. */ - if (session->started) { + if (session->has_been_started) { ret = LTTNG_ERR_TRACE_ALREADY_STARTED; goto error; } @@ -939,15 +939,6 @@ int cmd_enable_channel(struct ltt_session *session, kchan = trace_kernel_get_channel_by_name(attr->name, session->kernel_session); if (kchan == NULL) { - /* - * Don't try to create a channel if the session - * has been started at some point in time - * before. The tracer does not allow it. - */ - if (session->started) { - ret = LTTNG_ERR_TRACE_ALREADY_STARTED; - goto error; - } ret = channel_kernel_create(session->kernel_session, attr, wpipe); if (attr->name[0] != '\0') { session->kernel_session->has_non_default_channel = 1; @@ -971,15 +962,6 @@ int cmd_enable_channel(struct ltt_session *session, uchan = trace_ust_find_channel_by_name(chan_ht, attr->name); if (uchan == NULL) { - /* - * Don't try to create a channel if the session - * has been started at some point in time - * before. The tracer does not allow it. - */ - if (session->started) { - ret = LTTNG_ERR_TRACE_ALREADY_STARTED; - goto error; - } ret = channel_ust_create(usess, attr, domain->buf_type); if (attr->name[0] != '\0') { usess->has_non_default_channel = 1; @@ -1806,8 +1788,8 @@ int cmd_start_trace(struct ltt_session *session) ksession = session->kernel_session; usess = session->ust_session; - if (session->enabled) { - /* Already started. */ + /* Is the session already started? */ + if (session->active) { ret = LTTNG_ERR_TRACE_ALREADY_STARTED; goto error; } @@ -1827,8 +1809,6 @@ int cmd_start_trace(struct ltt_session *session) goto error; } - session->enabled = 1; - /* Kernel tracing */ if (ksession != NULL) { ret = start_kernel_session(ksession, kernel_tracer_fd); @@ -1848,7 +1828,9 @@ int cmd_start_trace(struct ltt_session *session) } } - session->started = 1; + /* Flag this after a successful start. */ + session->has_been_started = 1; + session->active = 1; ret = LTTNG_OK; @@ -1872,13 +1854,12 @@ int cmd_stop_trace(struct ltt_session *session) ksession = session->kernel_session; usess = session->ust_session; - if (!session->enabled) { + /* Session is not active. Skip everythong and inform the client. */ + if (!session->active) { ret = LTTNG_ERR_TRACE_ALREADY_STOPPED; goto error; } - session->enabled = 0; - /* Kernel tracer */ if (ksession && ksession->started) { DBG("Stop kernel tracing"); @@ -1920,6 +1901,8 @@ int cmd_stop_trace(struct ltt_session *session) } } + /* Flag inactive after a successful stop. */ + session->active = 0; ret = LTTNG_OK; error: @@ -1941,8 +1924,8 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session, assert(uris); assert(nb_uri > 0); - /* Can't enable consumer after session started. */ - if (session->enabled) { + /* Can't set consumer URI if the session is active. */ + if (session->active) { ret = LTTNG_ERR_TRACE_ALREADY_STARTED; goto error; } @@ -2509,7 +2492,7 @@ void cmd_list_lttng_sessions(struct lttng_session *sessions, uid_t uid, strncpy(sessions[i].name, session->name, NAME_MAX); sessions[i].name[NAME_MAX - 1] = '\0'; - sessions[i].enabled = session->enabled; + sessions[i].enabled = session->active; sessions[i].snapshot_mode = session->snapshot_mode; sessions[i].live_timer_interval = session->live_timer; i++; @@ -2529,7 +2512,7 @@ int cmd_data_pending(struct ltt_session *session) assert(session); /* Session MUST be stopped to ask for data availability. */ - if (session->enabled) { + if (session->active) { ret = LTTNG_ERR_SESSION_STARTED; goto error; } else { @@ -2543,7 +2526,7 @@ int cmd_data_pending(struct ltt_session *session) * *VERY* important that we don't ask the consumer before a start * trace. */ - if (!session->started) { + if (!session->has_been_started) { ret = 0; goto error; } @@ -2977,7 +2960,7 @@ int cmd_snapshot_record(struct ltt_session *session, } /* The session needs to be started at least once. */ - if (!session->started) { + if (!session->has_been_started) { ret = LTTNG_ERR_START_SESSION_ONCE; goto error; } diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 812137f93..89b45ba83 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1523,7 +1523,7 @@ int save_session(struct ltt_session *session, } ret = config_writer_write_element_bool(writer, config_element_started, - session->enabled); + session->active); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index 9113faf8a..14ad7af0a 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -70,7 +70,6 @@ struct ltt_session { */ pthread_mutex_t lock; struct cds_list_head list; - int enabled; /* enabled/started flag */ uint64_t id; /* session unique identifier */ /* UID/GID of the user owning the session */ uid_t uid; @@ -88,8 +87,13 @@ struct ltt_session { */ struct consumer_output *consumer; - /* Did a start command occured before the kern/ust session creation? */ - unsigned int started; + /* Did at least ONE start command has been triggered?. */ + unsigned int has_been_started:1; + /* + * Is the session active? Start trace command sets this to 1 and the stop + * command reset it to 0. + */ + unsigned int active:1; /* Snapshot representation in a session. */ struct snapshot snapshot; -- 2.34.1