libchromeos: Fixed D-Bus method call error handling
Extracted portions of ExtractMethodCallResults into a separate
set of functions (ExtractMessageParametersAsTuple and
ExtractMessageParameters) to help with reading data from
D-Bus message buffers.
Also changed ExtractMethodCallResults to accespt generic
dbus::Message instead of dbus::Response. This way we can
deserialize parameters from other message types, such as
dbus::Signal.
Finally, since dbus::ObjectProxy::CallMethodAndBlock()
does not return any error information when a D-Bus method
call failed, it returns a nullptr response instead of
expected dbus::ErrorResponse. Therefore the intended
implementation of chromeos::dbus_utils::CallMethodAndBlock()
and chromeos::dbus_utils::ExtractMethodCallResults()
functions were not treating the failures correctly.
As a step towards fixing the issue, added error parameter
to chromeos::dbus_utils::CallMethodAndBlock() and
updated code that called it to check for nullptr return
values. The second step would be to add a new method
dbus::ObjectProxy::CallMethodAndBlockWithError() to
Chrome and switch chromeos::dbus_utils::CallMethodAndBlock()
to use that method instead and retrieve the error information
correctly.
BUG=chromium:414838
TEST=USE=attestation FEATURES=test emerge-link libchromeos buffet peerd platform2
Change-Id: Ia5d6999afb50c0b3c9ab1c5057a9fc805a528ab5
Reviewed-on: https://chromium-review.googlesource.com/218468
Reviewed-by: Alex Vakulenko <[email protected]>
Commit-Queue: Alex Vakulenko <[email protected]>
Tested-by: Alex Vakulenko <[email protected]>
diff --git a/client/main.cc b/client/main.cc
index 1b0d4fb..4c33107 100644
--- a/client/main.cc
+++ b/client/main.cc
@@ -22,14 +22,16 @@
attestation::kAttestationServiceName,
dbus::ObjectPath(attestation::kAttestationServicePath));
+ chromeos::ErrorPtr error;
auto response = chromeos::dbus_utils::CallMethodAndBlock(
object,
attestation::kAttestationInterface,
- attestation::kStatsMethod);
+ attestation::kStatsMethod,
+ &error);
attestation::StatsResponse stats;
- chromeos::ErrorPtr error;
- if (chromeos::dbus_utils::ExtractMethodCallResults(response.get(),
+ if (response &&
+ chromeos::dbus_utils::ExtractMethodCallResults(response.get(),
&error,
&stats)) {
printf("Attestation has been up for %u seconds.\n", stats.uptime());