Catch sdbus-c++ exceptions flying from Proxy callbacks to libsystemd

This commit is contained in:
Stanislav Angelovic
2021-07-22 14:33:38 +02:00
committed by Urs Ritzmann
parent 6433b38ed1
commit b4f5c0f46c
3 changed files with 27 additions and 22 deletions

View File

@ -593,7 +593,7 @@ namespace sdbus {
{
reply >> args;
}
catch (const sdbus::Error& e)
catch (const Error& e)
{
// Catch message unpack exceptions and pass them to the callback
// in the expected manner to avoid propagating them up the call
@ -641,17 +641,7 @@ namespace sdbus {
tuple_of_function_input_arg_types_t<_Function> signalArgs;
// Deserialize input arguments from the signal message into the tuple
try
{
signal >> signalArgs;
}
catch (const sdbus::Error& e)
{
// The convenience API callback cannot handle an incoming signal with
// an unexpected payload, so catch and ignore this exception to avoid
// propagating it up the call stack to the event loop.
return;
}
signal >> signalArgs;
// Invoke callback with input arguments from the tuple.
sdbus::apply(callback, signalArgs);

View File

@ -337,7 +337,7 @@ int Object::sdbus_method_callback(sd_bus_message *sdbusMessage, void *userData,
{
callback(message);
}
catch (const sdbus::Error& e)
catch (const Error& e)
{
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
}
@ -371,7 +371,7 @@ int Object::sdbus_property_get_callback( sd_bus */*bus*/
{
callback(reply);
}
catch (const sdbus::Error& e)
catch (const Error& e)
{
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
}
@ -406,7 +406,7 @@ int Object::sdbus_property_set_callback( sd_bus */*bus*/
{
callback(value);
}
catch (const sdbus::Error& e)
catch (const Error& e)
{
sd_bus_error_set(retError, e.getName().c_str(), e.getMessage().c_str());
}

View File

@ -240,15 +240,22 @@ int Proxy::sdbus_async_reply_handler(sd_bus_message *sdbusMessage, void *userDat
proxy.m_CurrentlyProcessedMessage.store(nullptr, std::memory_order_relaxed);
};
const auto* error = sd_bus_message_get_error(sdbusMessage);
if (error == nullptr)
try
{
asyncCallData->callback(message, nullptr);
const auto* error = sd_bus_message_get_error(sdbusMessage);
if (error == nullptr)
{
asyncCallData->callback(message, nullptr);
}
else
{
Error exception(error->name, error->message);
asyncCallData->callback(message, &exception);
}
}
else
catch (const Error&)
{
sdbus::Error exception(error->name, error->message);
asyncCallData->callback(message, &exception);
// Intentionally left blank -- sdbus-c++ exceptions shall not bubble up to the underlying C sd-bus library
}
return 1;
@ -268,7 +275,15 @@ int Proxy::sdbus_signal_handler(sd_bus_message *sdbusMessage, void *userData, sd
signalData->proxy.m_CurrentlyProcessedMessage.store(nullptr, std::memory_order_relaxed);
};
signalData->callback(message);
try
{
signalData->callback(message);
}
catch (const Error&)
{
// Intentionally left blank -- sdbus-c++ exceptions shall not bubble up to the underlying C sd-bus library
}
return 0;
}