Handle SdBusError exception in setting time
sdbusplus now throws SdBusError exception when a sd bus call fails.
When setting time via systemd timedatectl service, it may fail to set
time due to time settings.
So handle this exception and print the reason.
Tested: Verify this service does not crash but prints the exception in
journal log, when it fails to set time to systemd.
Change-Id: I7d3b2e35e58c3924f95d3664653e68efbae8bd14
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/epoch_base.cpp b/epoch_base.cpp
index e130578..8aa41dd 100644
--- a/epoch_base.cpp
+++ b/epoch_base.cpp
@@ -52,13 +52,17 @@
method.append(static_cast<int64_t>(usec.count()),
false, // relative
false); // user_interaction
- auto reply = bus.call(method);
- if (reply.is_method_error())
+
+ try
+ {
+ bus.call_noreply(method);
+ }
+ catch (const sdbusplus::exception::SdBusError& ex)
{
log<level::ERR>("Error in setting system time");
using namespace xyz::openbmc_project::Time;
elog<FailedError>(
- Failed::REASON("Systemd failed to set time"));
+ Failed::REASON(ex.what()));
}
return true;
}