From 1cd4248d4afa664b94411dd57e7e686f944dfafc Mon Sep 17 00:00:00 2001 From: Lei YU Date: Tue, 24 Jul 2018 10:40:59 +0800 Subject: Fix un-initialized time owner/mode in manager The timeOwner/Mode in Manager class has no init value, and it is initialized with the cached time owner/mode in file system. In most of time it is OK because there is cached time owner/mode. But if the BMC does a factory reset, the cached values are cleaned up, and in next reboot the timeOwner/Mode will not be initialized at all. The fix is to give default time owner/mode, so when BMC comes from factory reset it uses default time settings. Tested: Verify the timeOwner/Mode have correct init values after factory reset. Change-Id: Ib1a8fba4d758f33ed09a7afdc9ed684867fca1c5 --- configure.ac | 7 +++++++ epoch_base.hpp | 5 +++-- manager.hpp | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 59cf5ce..2680788 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,13 @@ AC_ARG_VAR(HOST_OFFSET_FILE, [The file to save host time offset]) AS_IF([test "x$HOST_OFFSET_FILE" == "x"], [HOST_OFFSET_FILE="/var/lib/obmc/saved_host_offset"]) AC_DEFINE_UNQUOTED([HOST_OFFSET_FILE], ["$HOST_OFFSET_FILE"], [The file to save host time offset]) +AC_ARG_VAR(DEFAULT_TIME_MODE, [The default time mode]) +AS_IF([test "x$DEFAULT_TIME_MODE" == "x"], [DEFAULT_TIME_MODE=Mode::Manual]) +AC_DEFINE_UNQUOTED([DEFAULT_TIME_MODE], [$DEFAULT_TIME_MODE], [The default time mode]) + +AC_ARG_VAR(DEFAULT_TIME_OWNER, [The default time owner]) +AS_IF([test "x$DEFAULT_TIME_OWNER" == "x"], [DEFAULT_TIME_OWNER=Owner::Both]) +AC_DEFINE_UNQUOTED([DEFAULT_TIME_OWNER], [$DEFAULT_TIME_OWNER], [The default time owner]) AC_CONFIG_FILES([Makefile test/Makefile]) AC_OUTPUT diff --git a/epoch_base.hpp b/epoch_base.hpp index 4f23d51..79aca90 100644 --- a/epoch_base.hpp +++ b/epoch_base.hpp @@ -1,5 +1,6 @@ #pragma once +#include "config.h" #include "property_change_listener.hpp" #include @@ -38,10 +39,10 @@ class EpochBase : public sdbusplus::server::object::object < sdbusplus::bus::bus& bus; /** @brief The current time mode */ - Mode timeMode = Mode::Manual; + Mode timeMode = DEFAULT_TIME_MODE; /** @brief The current time owner */ - Owner timeOwner = Owner::Both; + Owner timeOwner = DEFAULT_TIME_OWNER; /** @brief Set current time to system * diff --git a/manager.hpp b/manager.hpp index e84652c..3256f59 100644 --- a/manager.hpp +++ b/manager.hpp @@ -1,5 +1,6 @@ #pragma once +#include "config.h" #include "types.hpp" #include "property_change_listener.hpp" #include "settings.hpp" @@ -64,10 +65,10 @@ class Manager std::string requestedOwner; /** @brief The current time mode */ - Mode timeMode; + Mode timeMode = DEFAULT_TIME_MODE; /** @brief The current time owner */ - Owner timeOwner; + Owner timeOwner = DEFAULT_TIME_OWNER; /** @brief Restore saved settings */ void restoreSettings(); -- cgit v1.2.1