projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: don't destroy the sockets if the snapshot was successful
[lttng-tools.git]
/
src
/
bin
/
lttng-sessiond
/
cmd.c
diff --git
a/src/bin/lttng-sessiond/cmd.c
b/src/bin/lttng-sessiond/cmd.c
index 36fe233ae8fc8681c0a90ef8b854d76af01c888e..26e8d152c2d02c9558f200f78a8af3da2c614033 100644
(file)
--- a/
src/bin/lttng-sessiond/cmd.c
+++ b/
src/bin/lttng-sessiond/cmd.c
@@
-17,6
+17,7
@@
#define _GNU_SOURCE
#include <assert.h>
#define _GNU_SOURCE
#include <assert.h>
+#include <string.h>
#include <inttypes.h>
#include <urcu/list.h>
#include <urcu/uatomic.h>
#include <inttypes.h>
#include <urcu/list.h>
#include <urcu/uatomic.h>
@@
-903,11
+904,21
@@
int cmd_enable_channel(struct ltt_session *session,
int ret;
struct ltt_ust_session *usess = session->ust_session;
struct lttng_ht *chan_ht;
int ret;
struct ltt_ust_session *usess = session->ust_session;
struct lttng_ht *chan_ht;
+ size_t len;
assert(session);
assert(attr);
assert(domain);
assert(session);
assert(attr);
assert(domain);
+ len = strnlen(attr->name, sizeof(attr->name));
+
+ /* Validate channel name */
+ if (attr->name[0] == '.' ||
+ memchr(attr->name, '/', len) != NULL) {
+ ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
+ goto end;
+ }
+
DBG("Enabling channel %s for session %s", attr->name, session->name);
rcu_read_lock();
DBG("Enabling channel %s for session %s", attr->name, session->name);
rcu_read_lock();
@@
-916,7
+927,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.
*/
* 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;
}
ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
goto error;
}
@@
-931,6
+942,16
@@
int cmd_enable_channel(struct ltt_session *session,
attr->attr.switch_timer_interval = 0;
}
attr->attr.switch_timer_interval = 0;
}
+ /*
+ * The ringbuffer (both in user space and kernel) behave badly in overwrite
+ * mode and with less than 2 subbuf so block it right away and send back an
+ * invalid attribute error.
+ */
+ if (attr->attr.overwrite && attr->attr.num_subbuf < 2) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
+
switch (domain->type) {
case LTTNG_DOMAIN_KERNEL:
{
switch (domain->type) {
case LTTNG_DOMAIN_KERNEL:
{
@@
-939,15
+960,6
@@
int cmd_enable_channel(struct ltt_session *session,
kchan = trace_kernel_get_channel_by_name(attr->name,
session->kernel_session);
if (kchan == NULL) {
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;
ret = channel_kernel_create(session->kernel_session, attr, wpipe);
if (attr->name[0] != '\0') {
session->kernel_session->has_non_default_channel = 1;
@@
-971,15
+983,6
@@
int cmd_enable_channel(struct ltt_session *session,
uchan = trace_ust_find_channel_by_name(chan_ht, attr->name);
if (uchan == NULL) {
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;
ret = channel_ust_create(usess, attr, domain->buf_type);
if (attr->name[0] != '\0') {
usess->has_non_default_channel = 1;
@@
-996,6
+999,7
@@
int cmd_enable_channel(struct ltt_session *session,
error:
rcu_read_unlock();
error:
rcu_read_unlock();
+end:
return ret;
}
return ret;
}
@@
-1461,16
+1465,16
@@
int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
tmp_dom.type = LTTNG_DOMAIN_UST;
ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
tmp_dom.type = LTTNG_DOMAIN_UST;
ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
- &uevent,
NULL
, NULL, wpipe);
+ &uevent,
filter
, NULL, wpipe);
if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
goto error;
}
/* The wild card * means that everything should be enabled. */
if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
goto error;
}
/* The wild card * means that everything should be enabled. */
if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
- ret = event_jul_enable_all(usess, event);
+ ret = event_jul_enable_all(usess, event
, filter
);
} else {
} else {
- ret = event_jul_enable(usess, event);
+ ret = event_jul_enable(usess, event
, filter
);
}
if (ret != LTTNG_OK) {
goto error;
}
if (ret != LTTNG_OK) {
goto error;
@@
-1689,7
+1693,7
@@
int cmd_enable_event_all(struct ltt_session *session,
strncpy(event.name, "*", sizeof(event.name));
event.name[sizeof(event.name) - 1] = '\0';
strncpy(event.name, "*", sizeof(event.name));
event.name[sizeof(event.name) - 1] = '\0';
- ret = event_jul_enable_all(usess, &event);
+ ret = event_jul_enable_all(usess, &event
, filter
);
if (ret != LTTNG_OK) {
goto error;
}
if (ret != LTTNG_OK) {
goto error;
}
@@
-1802,8
+1806,8
@@
int cmd_start_trace(struct ltt_session *session)
ksession = session->kernel_session;
usess = session->ust_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;
}
ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
goto error;
}
@@
-1813,7
+1817,9
@@
int cmd_start_trace(struct ltt_session *session)
* possible to enable channel thus inform the client.
*/
if (usess && usess->domain_global.channels) {
* possible to enable channel thus inform the client.
*/
if (usess && usess->domain_global.channels) {
+ rcu_read_lock();
nb_chan += lttng_ht_get_count(usess->domain_global.channels);
nb_chan += lttng_ht_get_count(usess->domain_global.channels);
+ rcu_read_unlock();
}
if (ksession) {
nb_chan += ksession->channel_count;
}
if (ksession) {
nb_chan += ksession->channel_count;
@@
-1823,8
+1829,6
@@
int cmd_start_trace(struct ltt_session *session)
goto error;
}
goto error;
}
- session->enabled = 1;
-
/* Kernel tracing */
if (ksession != NULL) {
ret = start_kernel_session(ksession, kernel_tracer_fd);
/* Kernel tracing */
if (ksession != NULL) {
ret = start_kernel_session(ksession, kernel_tracer_fd);
@@
-1844,7
+1848,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;
ret = LTTNG_OK;
@@
-1868,13
+1874,12
@@
int cmd_stop_trace(struct ltt_session *session)
ksession = session->kernel_session;
usess = session->ust_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;
}
ret = LTTNG_ERR_TRACE_ALREADY_STOPPED;
goto error;
}
- session->enabled = 0;
-
/* Kernel tracer */
if (ksession && ksession->started) {
DBG("Stop kernel tracing");
/* Kernel tracer */
if (ksession && ksession->started) {
DBG("Stop kernel tracing");
@@
-1916,6
+1921,8
@@
int cmd_stop_trace(struct ltt_session *session)
}
}
}
}
+ /* Flag inactive after a successful stop. */
+ session->active = 0;
ret = LTTNG_OK;
error:
ret = LTTNG_OK;
error:
@@
-1937,8
+1944,8
@@
int cmd_set_consumer_uri(int domain, struct ltt_session *session,
assert(uris);
assert(nb_uri > 0);
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;
}
ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
goto error;
}
@@
-1978,6
+1985,17
@@
int cmd_set_consumer_uri(int domain, struct ltt_session *session,
}
}
}
}
+ /*
+ * Make sure to set the session in output mode after we set URI since a
+ * session can be created without URL (thus flagged in no output mode).
+ */
+ session->output_traces = 1;
+ if (ksess) {
+ ksess->output_traces = 1;
+ } else if (usess) {
+ usess->output_traces = 1;
+ }
+
/* All good! */
ret = LTTNG_OK;
/* All good! */
ret = LTTNG_OK;
@@
-2380,16
+2398,18
@@
ssize_t cmd_list_channels(int domain, struct ltt_session *session,
break;
case LTTNG_DOMAIN_UST:
if (session->ust_session != NULL) {
break;
case LTTNG_DOMAIN_UST:
if (session->ust_session != NULL) {
+ rcu_read_lock();
nb_chan = lttng_ht_get_count(
nb_chan = lttng_ht_get_count(
- session->ust_session->domain_global.channels);
+ session->ust_session->domain_global.channels);
+ rcu_read_unlock();
}
DBG3("Number of UST global channels %zd", nb_chan);
}
DBG3("Number of UST global channels %zd", nb_chan);
- if (nb_chan <
=
0) {
+ if (nb_chan < 0) {
ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+ goto error;
}
break;
default:
}
break;
default:
- *channels = NULL;
ret = LTTNG_ERR_UND;
goto error;
}
ret = LTTNG_ERR_UND;
goto error;
}
@@
-2402,10
+2422,6
@@
ssize_t cmd_list_channels(int domain, struct ltt_session *session,
}
list_lttng_channels(domain, session, *channels);
}
list_lttng_channels(domain, session, *channels);
- } else {
- *channels = NULL;
- /* Ret value was set in the domain switch case */
- goto error;
}
return nb_chan;
}
return nb_chan;
@@
-2505,7
+2521,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';
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++;
sessions[i].snapshot_mode = session->snapshot_mode;
sessions[i].live_timer_interval = session->live_timer;
i++;
@@
-2525,7
+2541,7
@@
int cmd_data_pending(struct ltt_session *session)
assert(session);
/* Session MUST be stopped to ask for data availability. */
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 {
ret = LTTNG_ERR_SESSION_STARTED;
goto error;
} else {
@@
-2539,7
+2555,7
@@
int cmd_data_pending(struct ltt_session *session)
* *VERY* important that we don't ask the consumer before a start
* trace.
*/
* *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;
}
ret = 0;
goto error;
}
@@
-2691,7
+2707,7
@@
ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
struct lttng_snapshot_output **outputs)
{
int ret, idx = 0;
struct lttng_snapshot_output **outputs)
{
int ret, idx = 0;
- struct lttng_snapshot_output *list;
+ struct lttng_snapshot_output *list
= NULL
;
struct lttng_ht_iter iter;
struct snapshot_output *output;
struct lttng_ht_iter iter;
struct snapshot_output *output;
@@
-2705,7
+2721,7
@@
ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
* set in no output mode.
*/
if (session->output_traces) {
* set in no output mode.
*/
if (session->output_traces) {
- ret = LTTNG_ERR_EPERM;
+ ret =
-
LTTNG_ERR_EPERM;
goto error;
}
goto error;
}
@@
-2716,11
+2732,12
@@
ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
list = zmalloc(session->snapshot.nb_output * sizeof(*list));
if (!list) {
list = zmalloc(session->snapshot.nb_output * sizeof(*list));
if (!list) {
- ret = LTTNG_ERR_NOMEM;
+ ret =
-
LTTNG_ERR_NOMEM;
goto error;
}
/* Copy list from session to the new list object. */
goto error;
}
/* Copy list from session to the new list object. */
+ rcu_read_lock();
cds_lfht_for_each_entry(session->snapshot.output_ht->ht, &iter.iter,
output, node.node) {
assert(output->consumer);
cds_lfht_for_each_entry(session->snapshot.output_ht->ht, &iter.iter,
output, node.node) {
assert(output->consumer);
@@
-2735,28
+2752,28
@@
ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
ret = uri_to_str_url(&output->consumer->dst.net.control,
list[idx].ctrl_url, sizeof(list[idx].ctrl_url));
if (ret < 0) {
ret = uri_to_str_url(&output->consumer->dst.net.control,
list[idx].ctrl_url, sizeof(list[idx].ctrl_url));
if (ret < 0) {
- ret = LTTNG_ERR_NOMEM;
- goto
free_
error;
+ ret =
-
LTTNG_ERR_NOMEM;
+ goto error;
}
/* Data URI. */
ret = uri_to_str_url(&output->consumer->dst.net.data,
list[idx].data_url, sizeof(list[idx].data_url));
if (ret < 0) {
}
/* Data URI. */
ret = uri_to_str_url(&output->consumer->dst.net.data,
list[idx].data_url, sizeof(list[idx].data_url));
if (ret < 0) {
- ret = LTTNG_ERR_NOMEM;
- goto
free_
error;
+ ret =
-
LTTNG_ERR_NOMEM;
+ goto error;
}
}
idx++;
}
*outputs = list;
}
}
idx++;
}
*outputs = list;
- return session->snapshot.nb_output;
-
-free_error:
- free(list);
+ list = NULL;
+ ret = session->snapshot.nb_output;
error:
error:
- return -ret;
+ free(list);
+ rcu_read_unlock();
+ return ret;
}
/*
}
/*
@@
-2849,11
+2866,13
@@
static int record_kernel_snapshot(struct ltt_kernel_session *ksess,
}
ret = LTTNG_OK;
}
ret = LTTNG_OK;
+ goto end;
error_snapshot:
/* Clean up copied sockets so this output can use some other later on. */
consumer_destroy_output_sockets(output->consumer);
error:
error_snapshot:
/* Clean up copied sockets so this output can use some other later on. */
consumer_destroy_output_sockets(output->consumer);
error:
+end:
return ret;
}
return ret;
}
@@
-2973,7
+2992,7
@@
int cmd_snapshot_record(struct ltt_session *session,
}
/* The session needs to be started at least once. */
}
/* 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;
}
ret = LTTNG_ERR_START_SESSION_ONCE;
goto error;
}
This page took
0.040954 seconds
and
4
git commands to generate.