X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-app.cpp;fp=src%2Fbin%2Flttng-sessiond%2Fust-app.cpp;h=3f39b02e4d9ee3d0e6faf65fa1d243ddf242f2e0;hp=88db75f8f4d7da8f1f2ae5cc3d7978cae26fafdd;hb=24ed18f2ceda5023e4ad755547ad79466730cbd3;hpb=2f35b2f5e29f337ad7c780e41d1eaeae378c1bc2 diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 88db75f8f..3f39b02e4 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -6426,23 +6426,47 @@ 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); - 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 (!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.set_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.get_event_context(); + + 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; + } + + 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: