Handle SdBusError exception in setting NTP
sdbusplus now throws SdBusError exception when a sd bus call fails.
When setting NTP via systemd timedatectl service, it may potentially
fail.
So handle this exception.
Also fix a typo in logging, where it should use `=` in meta.
Change-Id: I6c5669b7f06cef47c8d62cb0cbcb0c7fbd2a46e7
Tested: Verify it sets NTP setting OK.
diff --git a/manager.cpp b/manager.cpp
index 1145d33..8d3d955 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -194,14 +194,16 @@
method.append(isNtp, false); // isNtp: 'true/false' means Enable/Disable
// 'false' meaning no policy-kit
- if (bus.call(method))
+ try
{
+ bus.call_noreply(method);
log<level::INFO>("Updated NTP setting",
- entry("ENABLED:%d", isNtp));
+ entry("ENABLED=%d", isNtp));
}
- else
+ catch (const sdbusplus::exception::SdBusError& ex)
{
- log<level::ERR>("Failed to update NTP setting");
+ log<level::ERR>("Failed to update NTP setting",
+ entry("ERR=%s", ex.what()));
}
}