Use proper errors when failing to set time
Previously it reports InsufficientPermission when it is not allowed to
set time.
Now phosphor-dbus-interfaces defines proper errors for such case, so
report NotAllowed error when it is not allowed to set time, and report
Failed error when it failed to set time.
Tested: Get NotAllowed and Failed error with expected metadata from
journal log.
Change-Id: I53610bf27ffc3f62608cea6fd0e66ca859d94675
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/host_epoch.cpp b/host_epoch.cpp
index ea3026c..c3e6400 100644
--- a/host_epoch.cpp
+++ b/host_epoch.cpp
@@ -3,17 +3,19 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
-#include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Time/error.hpp>
namespace phosphor
{
namespace time
{
-using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace sdbusplus::xyz::openbmc_project::Time;
using namespace phosphor::logging;
using namespace std::chrono;
+using NotAllowedError =
+ sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
+
HostEpoch::HostEpoch(sdbusplus::bus::bus& bus,
const char* objPath)
: EpochBase(bus, objPath),
@@ -53,8 +55,11 @@
(timeMode == Mode::NTP
&& (timeOwner == Owner::Host || timeOwner == Owner::Both)))
{
- log<level::ERR>("Setting HostTime is not allowed");
- elog<InsufficientPermission>();
+ using namespace xyz::openbmc_project::Time;
+ elog<NotAllowedError>(
+ NotAllowed::OWNER(utils::ownerToStr(timeOwner).c_str()),
+ NotAllowed::SYNC_METHOD(utils::modeToStr(timeMode).c_str()),
+ NotAllowed::REASON("Setting HostTime is not allowed"));
}
auto time = microseconds(value);