bus/new_{method,signal}: Implement error handling for underlying errors
More improvements to error handling coverage to ensure new message
creation doesn't silently fail and cause corruption in our daemons.
Tested:
Builds for zaius and boots on a fully power cycled machine all the
way up into the host.
Change-Id: Iff9e04b7fb05859f5ab8b171dafda7332d5ead99
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/sdbusplus/bus.hpp.in b/sdbusplus/bus.hpp.in
index 11bacd3..1f13a5e 100644
--- a/sdbusplus/bus.hpp.in
+++ b/sdbusplus/bus.hpp.in
@@ -203,8 +203,12 @@
const char* interf, const char* method)
{
sd_bus_message* m = nullptr;
- _intf->sd_bus_message_new_method_call(_bus.get(), &m, service, objpath,
- interf, method);
+ int r = _intf->sd_bus_message_new_method_call(_bus.get(), &m, service,
+ objpath, interf, method);
+ if (r < 0)
+ {
+ throw exception::SdBusError(-r, "sd_bus_message_new_method_call");
+ }
return message::message(m, _intf, std::false_type());
}
@@ -220,8 +224,12 @@
auto new_signal(const char* objpath, const char* interf, const char* member)
{
sd_bus_message* m = nullptr;
- _intf->sd_bus_message_new_signal(_bus.get(), &m, objpath, interf,
- member);
+ int r = _intf->sd_bus_message_new_signal(_bus.get(), &m, objpath,
+ interf, member);
+ if (r < 0)
+ {
+ throw exception::SdBusError(-r, "sd_bus_message_new_signal");
+ }
return message::message(m, _intf, std::false_type());
}