sdbuspp_support: correct return value from method callbacks
It was reported that even successful method calls were observed with
dbus-monitor to have an error string:
error_name=org.freedesktop.DBus.Error.UnknownMethod reply_serial=2
string "Unknown method DeleteAll or interface
xyz.openbmc_project.Collection.DeleteAll."
Looking at the sd-bus code for this string, I noticed that there is a
for-loop that iterates through the vtable and continues looking for
additional vtable callbacks if a 0 is returned from a callback. At
the end of the loop, this string is added.
This behavior is also mentioned in the man page for vtable entries:
When a request is received, any associated callbacks are called
sequentially until a callback returns a non-zero integer. Return
zero from a callback to give other callbacks the chance to process
the request.
`method_callback` in sdbuspp_support/server.hpp was returning a 0 instead
of a positive integer indicating success. Modify the support callbacks
so that they all return a non-zero return to indicate non-delegation.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I3f3239951b873c42527d130b66e53d52c97427e1
diff --git a/include/sdbusplus/sdbuspp_support/server.hpp b/include/sdbusplus/sdbuspp_support/server.hpp
index 113fb5d..74f673a 100644
--- a/include/sdbusplus/sdbuspp_support/server.hpp
+++ b/include/sdbusplus/sdbuspp_support/server.hpp
@@ -24,8 +24,8 @@
* function 'f', and then pack them into the response message.
*/
template <typename... Args, typename Return>
-bool property_callback(sd_bus_message* msg, sdbusplus::SdBusInterface* intf,
- sd_bus_error* error, std::function<Return(Args&&...)> f)
+int property_callback(sd_bus_message* msg, sdbusplus::SdBusInterface* intf,
+ sd_bus_error* error, std::function<Return(Args&&...)> f)
{
try
{
@@ -56,7 +56,9 @@
return intf->sd_bus_error_set(error, e.name(), e.description());
}
- return true;
+ // A positive integer must be returned to indicate that the callback
+ // has done its work (and not delegate to a later callback in the vtable).
+ return 1;
}
/** Handle common parts of a method callback.
@@ -127,7 +129,9 @@
return intf->sd_bus_error_set(error, e.name(), e.description());
}
- return 0;
+ // A positive integer must be returned to indicate that the callback
+ // has done its work (and not delegate to a later callback in the vtable).
+ return 1;
}
} // namespace sdbuspp