* URI was the same in the consumer so we do not append the subdir
* again so to not duplicate output dir.
*/
+ ret = LTTNG_OK;
goto error;
}
/* Quiescent wait after starting trace */
kernel_wait_quiescent(kernel_tracer_fd);
- ksess->started = 1;
+ ksess->active = 1;
ret = LTTNG_OK;
* 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;
}
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;
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;
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;
}
goto error;
}
- session->enabled = 1;
-
/* Kernel tracing */
if (ksession != NULL) {
ret = start_kernel_session(ksession, kernel_tracer_fd);
/* Flag session that trace should start automatically */
if (usess) {
- usess->start_trace = 1;
+ /*
+ * Even though the start trace might fail, flag this session active so
+ * other application coming in are started by default.
+ */
+ usess->active = 1;
ret = ust_app_start_trace_all(usess);
if (ret < 0) {
}
}
- session->started = 1;
+ /* Flag this after a successful start. */
+ session->has_been_started = 1;
+ session->active = 1;
ret = LTTNG_OK;
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) {
+ if (ksession && ksession->active) {
DBG("Stop kernel tracing");
/* Flush metadata if exist */
kernel_wait_quiescent(kernel_tracer_fd);
- ksession->started = 0;
+ ksession->active = 0;
}
- if (usess && usess->start_trace) {
- usess->start_trace = 0;
+ if (usess && usess->active) {
+ /*
+ * Even though the stop trace might fail, flag this session inactive so
+ * other application coming in are not started by default.
+ */
+ usess->active = 0;
ret = ust_app_stop_trace_all(usess);
if (ret < 0) {
}
}
+ /* Flag inactive after a successful stop. */
+ session->active = 0;
ret = LTTNG_OK;
error:
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;
}
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++;
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 {
+ /*
+ * If stopped, just make sure we've started before else the above call
+ * will always send that there is data pending.
+ *
+ * The consumer assumes that when the data pending command is received,
+ * the trace has been started before or else no output data is written
+ * by the streams which is a condition for data pending. So, this is
+ * *VERY* important that we don't ask the consumer before a start
+ * trace.
+ */
+ if (!session->has_been_started) {
+ ret = 0;
+ goto error;
+ }
}
if (ksess && ksess->consumer) {
}
/* 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;
}