X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=0cc71303aeb6704de4bc926f39d0e2acbf58bc39;hp=a57409d411b10ac09e53e655ca9cfc8c4a215710;hb=930a2e995548ba32bfe27d996e306a07f1129b8a;hpb=ff94328ff1538f1da009e81a27bbd922ef031727 diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index a57409d41..0cc71303a 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1301,6 +1301,38 @@ error: return ret; } +static int validate_event_name(const char *name) +{ + int ret = 0; + const char *c = name; + const char *event_name_end = c + LTTNG_SYMBOL_NAME_LEN; + + /* + * Make sure that unescaped wildcards are only used as the last + * character of the event name. + */ + while (c < event_name_end) { + switch (*c) { + case '\0': + goto end; + case '\\': + c++; + break; + case '*': + if ((c + 1) < event_name_end && *(c + 1)) { + /* Wildcard is not the last character */ + ret = LTTNG_ERR_INVALID_EVENT_NAME; + goto end; + } + default: + break; + } + c++; + } +end: + return ret; +} + /* * Command LTTNG_ENABLE_EVENT processed by the client thread. */ @@ -1318,6 +1350,11 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, assert(event); assert(channel_name); + ret = validate_event_name(event->name); + if (ret) { + goto error; + } + rcu_read_lock(); switch (domain->type) { @@ -1466,9 +1503,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, /* 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 { - ret = event_jul_enable(usess, event); + ret = event_jul_enable(usess, event, filter); } if (ret != LTTNG_OK) { goto error; @@ -1689,7 +1726,7 @@ int cmd_enable_event_all(struct ltt_session *session, 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; } @@ -1987,6 +2024,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; @@ -2821,7 +2869,7 @@ error: */ static int record_kernel_snapshot(struct ltt_kernel_session *ksess, struct snapshot_output *output, struct ltt_session *session, - int wait, int nb_streams) + int wait, uint64_t max_stream_size) { int ret; @@ -2852,7 +2900,7 @@ static int record_kernel_snapshot(struct ltt_kernel_session *ksess, goto error_snapshot; } - ret = kernel_snapshot_record(ksess, output, wait, nb_streams); + ret = kernel_snapshot_record(ksess, output, wait, max_stream_size); if (ret != LTTNG_OK) { goto error_snapshot; } @@ -2873,7 +2921,7 @@ error: */ static int record_ust_snapshot(struct ltt_ust_session *usess, struct snapshot_output *output, struct ltt_session *session, - int wait, int nb_streams) + int wait, uint64_t max_stream_size) { int ret; @@ -2904,7 +2952,7 @@ static int record_ust_snapshot(struct ltt_ust_session *usess, goto error_snapshot; } - ret = ust_app_snapshot_record(usess, output, wait, nb_streams); + ret = ust_app_snapshot_record(usess, output, wait, max_stream_size); if (ret < 0) { switch (-ret) { case EINVAL: @@ -2929,11 +2977,51 @@ error: return ret; } +/* + * Return the biggest subbuffer size of all channels in the given session. + */ +static uint64_t get_session_max_subbuf_size(struct ltt_session *session) +{ + uint64_t max_size = 0; + + assert(session); + + if (session->kernel_session) { + struct ltt_kernel_channel *chan; + struct ltt_kernel_session *ksess = session->kernel_session; + + /* + * For each channel, add to the max size the size of each subbuffer + * multiplied by their sized. + */ + cds_list_for_each_entry(chan, &ksess->channel_list.head, list) { + if (chan->channel->attr.subbuf_size > max_size) { + max_size = chan->channel->attr.subbuf_size; + } + } + } + + if (session->ust_session) { + struct lttng_ht_iter iter; + struct ltt_ust_channel *uchan; + struct ltt_ust_session *usess = session->ust_session; + + cds_lfht_for_each_entry(usess->domain_global.channels->ht, &iter.iter, + uchan, node.node) { + if (uchan->attr.subbuf_size > max_size) { + max_size = uchan->attr.subbuf_size; + } + } + } + + return max_size; +} + /* * Returns the total number of streams for a session or a negative value * on error. */ -static unsigned int get_total_nb_stream(struct ltt_session *session) +static unsigned int get_session_nb_streams(struct ltt_session *session) { unsigned int total_streams = 0; @@ -2967,6 +3055,7 @@ int cmd_snapshot_record(struct ltt_session *session, unsigned int use_tmp_output = 0; struct snapshot_output tmp_output; unsigned int nb_streams, snapshot_success = 0; + uint64_t session_max_size = 0, max_stream_size = 0; assert(session); @@ -3006,17 +3095,43 @@ int cmd_snapshot_record(struct ltt_session *session, } /* - * Get the total number of stream of that session which is used by the - * maximum size of the snapshot feature. + * Get the session maximum size for a snapshot meaning it will compute the + * size of all streams from all domain. */ - nb_streams = get_total_nb_stream(session); + max_stream_size = get_session_max_subbuf_size(session); + + nb_streams = get_session_nb_streams(session); + if (nb_streams) { + /* + * The maximum size of the snapshot is the number of streams multiplied + * by the biggest subbuf size of all channels in a session which is the + * maximum stream size available for each stream. The session max size + * is now checked against the snapshot max size value given by the user + * and if lower, an error is returned. + */ + session_max_size = max_stream_size * nb_streams; + } + + DBG3("Snapshot max size is %" PRIu64 " for max stream size of %" PRIu64, + session_max_size, max_stream_size); + + /* + * If we use a temporary output, check right away if the max size fits else + * for each output the max size will be checked. + */ + if (use_tmp_output && + (tmp_output.max_size != 0 && + tmp_output.max_size < session_max_size)) { + ret = LTTNG_ERR_MAX_SIZE_INVALID; + goto error; + } if (session->kernel_session) { struct ltt_kernel_session *ksess = session->kernel_session; if (use_tmp_output) { ret = record_kernel_snapshot(ksess, &tmp_output, session, - wait, nb_streams); + wait, max_stream_size); if (ret != LTTNG_OK) { goto error; } @@ -3040,6 +3155,13 @@ int cmd_snapshot_record(struct ltt_session *session, tmp_output.max_size = output->max_size; } + if (tmp_output.max_size != 0 && + tmp_output.max_size < session_max_size) { + rcu_read_unlock(); + ret = LTTNG_ERR_MAX_SIZE_INVALID; + goto error; + } + /* Use temporary name. */ if (*output->name != '\0') { strncpy(tmp_output.name, output->name, @@ -3049,7 +3171,7 @@ int cmd_snapshot_record(struct ltt_session *session, tmp_output.nb_snapshot = session->snapshot.nb_snapshot; ret = record_kernel_snapshot(ksess, &tmp_output, - session, wait, nb_streams); + session, wait, max_stream_size); if (ret != LTTNG_OK) { rcu_read_unlock(); goto error; @@ -3065,7 +3187,7 @@ int cmd_snapshot_record(struct ltt_session *session, if (use_tmp_output) { ret = record_ust_snapshot(usess, &tmp_output, session, - wait, nb_streams); + wait, max_stream_size); if (ret != LTTNG_OK) { goto error; } @@ -3089,6 +3211,13 @@ int cmd_snapshot_record(struct ltt_session *session, tmp_output.max_size = output->max_size; } + if (tmp_output.max_size != 0 && + tmp_output.max_size < session_max_size) { + rcu_read_unlock(); + ret = LTTNG_ERR_MAX_SIZE_INVALID; + goto error; + } + /* Use temporary name. */ if (*output->name != '\0') { strncpy(tmp_output.name, output->name, @@ -3098,7 +3227,7 @@ int cmd_snapshot_record(struct ltt_session *session, tmp_output.nb_snapshot = session->snapshot.nb_snapshot; ret = record_ust_snapshot(usess, &tmp_output, session, - wait, nb_streams); + wait, max_stream_size); if (ret != LTTNG_OK) { rcu_read_unlock(); goto error;