X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-app.cpp;h=ec8aa1c39ca7e4dd270c2d828e248a8f6b1dfd73;hb=4bcf2294f0701b731d620c38216e1922e919e1b9;hp=0246501a53a31c69bc1ea3a9cddbaec75c67f6d4;hpb=0114db0ec2407029052eb61a0189c9b1cd64d520;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 0246501a5..ec8aa1c39 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -3454,18 +3454,14 @@ static int create_channel_per_uid(struct ust_app *app, { auto locked_registry = reg_uid->registry->reg.ust->lock(); - auto& ust_reg_chan = locked_registry->get_channel(ua_chan->tracing_channel_id); + auto& ust_reg_chan = locked_registry->channel(ua_chan->tracing_channel_id); ust_reg_chan._consumer_key = ua_chan->key; } /* Notify the notification subsystem of the channel's creation. */ notification_ret = notification_thread_command_add_channel( - the_notification_thread_handle, session->name, - lttng_credentials_get_uid( - &ua_sess->effective_credentials), - lttng_credentials_get_gid( - &ua_sess->effective_credentials), + the_notification_thread_handle, session->id, ua_chan->name, ua_chan->key, LTTNG_DOMAIN_UST, ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf); if (notification_ret != LTTNG_OK) { @@ -3558,16 +3554,12 @@ static int create_channel_per_pid(struct ust_app *app, { auto locked_registry = registry->lock(); - auto& ust_reg_chan = locked_registry->get_channel(chan_reg_key); + auto& ust_reg_chan = locked_registry->channel(chan_reg_key); ust_reg_chan._consumer_key = ua_chan->key; } cmd_ret = notification_thread_command_add_channel( - the_notification_thread_handle, session->name, - lttng_credentials_get_uid( - &ua_sess->effective_credentials), - lttng_credentials_get_gid( - &ua_sess->effective_credentials), + the_notification_thread_handle, session->id, ua_chan->name, ua_chan->key, LTTNG_DOMAIN_UST, ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf); if (cmd_ret != LTTNG_OK) { @@ -6416,7 +6408,7 @@ static int handle_app_register_channel_notification(int sock, chan_reg_key = ua_chan->key; } - auto& ust_reg_chan = locked_registry_session->get_channel(chan_reg_key); + auto& ust_reg_chan = locked_registry_session->channel(chan_reg_key); /* Channel id is set during the object creation. */ chan_id = ust_reg_chan.id; @@ -6434,32 +6426,49 @@ static int handle_app_register_channel_notification(int sock, * that all apps provide the same typing for the context fields as a * sanity check. */ - lst::type::cuptr context_fields = lttng::make_unique(0, - lsu::create_trace_fields_from_ust_ctl_fields(*locked_registry_session, - ust_ctl_context_fields.get(), context_field_count)); + try { + auto app_context_fields = lsu::create_trace_fields_from_ust_ctl_fields( + *locked_registry_session, ust_ctl_context_fields.get(), + context_field_count, + lst::field_location::root::EVENT_RECORD_COMMON_CONTEXT, + lsu::ctl_field_quirks::UNDERSCORE_PREFIXED_VARIANT_TAG_MAPPINGS); + + if (!ust_reg_chan.is_registered()) { + lst::type::cuptr event_context = app_context_fields.size() ? + lttng::make_unique( + 0, std::move(app_context_fields)) : + nullptr; + + ust_reg_chan.event_context(std::move(event_context)); + } else { + /* + * Validate that the context fields match between + * registry and newcoming application. + */ + bool context_fields_match; + const auto *previous_event_context = ust_reg_chan.event_context(); - if (!ust_reg_chan.is_registered()) { - ust_reg_chan.set_context(std::move(context_fields)); - } else { - /* - * Validate that the context fields match between - * registry and newcoming application. - */ - if (ust_reg_chan.get_context() != *context_fields) { - ERR("Registering application channel due to context field mismatch: pid = %d, sock = %d", - app->pid, app->sock); - ret_code = -EINVAL; - goto reply; - } - } + if (!previous_event_context) { + context_fields_match = app_context_fields.size() == 0; + } else { + const lst::structure_type app_event_context_struct( + 0, std::move(app_context_fields)); + + context_fields_match = *previous_event_context == + app_event_context_struct; + } - /* Append to metadata */ - if (!ust_reg_chan._metadata_dumped) { - /*ret_code = ust_metadata_channel_statedump(registry, ust_reg_chan);*/ - if (ret_code) { - ERR("Error appending channel metadata (errno = %d)", ret_code); - goto reply; + if (!context_fields_match) { + ERR("Registering application channel due to context field mismatch: pid = %d, sock = %d", + app->pid, app->sock); + ret_code = -EINVAL; + goto reply; + } } + } catch (std::exception& ex) { + ERR("Failed to handle application context: %s", ex.what()); + ret_code = -EINVAL; + goto reply; } reply: @@ -6468,7 +6477,7 @@ reply: ret_code); ret = lttng_ust_ctl_reply_register_channel(sock, chan_id, - ust_reg_chan.header_type == lst::stream_class::header_type::COMPACT ? + ust_reg_chan.header_type_ == lst::stream_class::header_type::COMPACT ? LTTNG_UST_CTL_CHANNEL_HEADER_COMPACT : LTTNG_UST_CTL_CHANNEL_HEADER_LARGE, ret_code); @@ -6550,18 +6559,22 @@ static int add_event_ust_registry(int sock, int sobjd, int cobjd, const char *na * These three variables MUST NOT be read/write after this. */ try { - auto& channel = locked_registry->get_channel(chan_reg_key); + auto& channel = locked_registry->channel(chan_reg_key); /* event_id is set on success. */ channel.add_event(sobjd, cobjd, name, signature.get(), lsu::create_trace_fields_from_ust_ctl_fields( *locked_registry, fields.get(), - nr_fields), + nr_fields, + lst::field_location::root:: + EVENT_RECORD_PAYLOAD, + lsu::ctl_field_quirks:: + UNDERSCORE_PREFIXED_VARIANT_TAG_MAPPINGS), loglevel_value, model_emf_uri.get() ? nonstd::optional( model_emf_uri.get()) : - nonstd::nullopt, + nonstd::nullopt, ua_sess->buffer_type, *app, event_id); ret_code = 0; } catch (const std::exception& ex) { @@ -7882,3 +7895,30 @@ error: rcu_read_unlock(); return ret; } + +lsu::ctl_field_quirks ust_app::ctl_field_quirks() const +{ + /* + * Application contexts are expressed as variants. LTTng-UST announces + * those by registering an enumeration named `..._tag`. It then registers a + * variant as part of the event context that contains the various possible + * types. + * + * Unfortunately, the names used in the enumeration and variant don't + * match: the enumeration names are all prefixed with an underscore while + * the variant type tag fields aren't. + * + * While the CTF 1.8.3 specification mentions that + * underscores *should* (not *must*) be removed by CTF readers. Babeltrace + * 1.x (and possibly others) expect a perfect match between the names used + * by tags and variants. + * + * When the UNDERSCORE_PREFIXED_VARIANT_TAG_MAPPINGS quirk is enabled, + * the variant's fields are modified to match the mappings of its tag. + * + * From ABI version >= 10.x, the variant fields and tag mapping names + * correctly match, making this quirk unnecessary. + */ + return v_major <= 9 ? lsu::ctl_field_quirks::UNDERSCORE_PREFIXED_VARIANT_TAG_MAPPINGS : + lsu::ctl_field_quirks::NONE; +} \ No newline at end of file