summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-07-06 15:01:45 +0530
committerVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-07-06 15:01:45 +0530
commiteaee45522525b0b6d479cf9ac6afe4767648d258 (patch)
tree45a5a18e137476032b17f4a5246662e5d170ab87
parent25b4ce95f9d0bea33fbf0364e72f304542a19bc5 (diff)
downloadphosphor-time-manager-eaee45522525b0b6d479cf9ac6afe4767648d258.tar.gz
phosphor-time-manager-eaee45522525b0b6d479cf9ac6afe4767648d258.zip
Use error message thrown by timedate1 service
If NTP is set, SetTime from timedate1 service throws a standard error. Current code was throwing a custom error and it was not much helpful. Correct thing is to re-throw what timedate1 throws. Also, current code was gating the SetTime request if the time mode was NTP. This has been removed now and the decision is left to timedate1 service now on whether to allow setting the time or not when NTP is enabled. Change-Id: I2b132bcea57f5181198dfe0c3635666bc8d7c070 Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
-rw-r--r--time-manager.cpp35
-rw-r--r--time-manager.hpp5
2 files changed, 9 insertions, 31 deletions
diff --git a/time-manager.cpp b/time-manager.cpp
index f9e307e..0279e4a 100644
--- a/time-manager.cpp
+++ b/time-manager.cpp
@@ -199,7 +199,8 @@ int TimeManager::setTime(sd_bus_message* m, void* userdata,
return sd_bus_reply_method_return(m, "i", 0);
}
-int Time::setTimeOfDay(const std::chrono::microseconds& timeOfDayUsec)
+int Time::setTimeOfDay(const std::chrono::microseconds& timeOfDayUsec,
+ sd_bus_error *retError)
{
// These 2 are for bypassing some policy
// checking in the timedate1 service
@@ -211,7 +212,7 @@ int Time::setTimeOfDay(const std::chrono::microseconds& timeOfDayUsec)
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
"SetTime",
- nullptr,
+ retError,
nullptr, // timedate1 does not return response
"xbb",
(int64_t)timeOfDayUsec.count(), //newTimeUsec,
@@ -297,15 +298,6 @@ int BmcTime::setTime(sd_bus_message *m, sd_bus_error *retError)
<< " Curr_Owner: " << TimeConfig::ownerStr(config.getCurrTimeOwner())
<< std::endl;
- if (config.getCurrTimeMode() == TimeConfig::timeModes::NTP)
- {
- std::cerr << "Can not set time. Mode is NTP" << std::endl;
- *retError = SD_BUS_ERROR_MAKE_CONST(
- SD_BUS_ERROR_FAILED, "Current Mode is NTP");
-
- return -1;
- }
-
if(config.getCurrTimeOwner() == TimeConfig::timeOwners::HOST)
{
std::cerr << "Can not set time. Owner is HOST" << std::endl;
@@ -354,15 +346,7 @@ int BmcTime::setTime(sd_bus_message *m, sd_bus_error *retError)
// Set REALTIME and also update hwclock
auto timeInUsec = std::chrono::microseconds(
std::chrono::seconds(timeOfDay));
- r = setTimeOfDay(timeInUsec);
- if (r < 0)
- {
- std::cerr <<"Error: " << strerror(-r)
- << "setting time on BMC" << std::endl;
- *retError = SD_BUS_ERROR_MAKE_CONST(
- SD_BUS_ERROR_FAILED, "Error setting time on BMC");
- }
- return r < 0 ? r : 0;
+ return setTimeOfDay(timeInUsec, retError);
}
// Gets the time string from IPMI ( which is currently in seconds since epoch )
@@ -422,16 +406,7 @@ int HostTime::setTime(sd_bus_message *m, sd_bus_error *retError)
}
// We are okay to update time in as long as BMC is not the owner
- r = setTimeOfDay(hostTimeUsec);
- if (r < 0)
- {
- std::cerr <<"Error: " << strerror(-r)
- << "setting HOST time" << std::endl;
- *retError = SD_BUS_ERROR_MAKE_CONST(
- SD_BUS_ERROR_FAILED, "Error setting time");
- }
-
- return r < 0 ? r : 0;
+ return setTimeOfDay(hostTimeUsec, retError);
}
// Gets called into by sd_event on an activity seen on sd_bus
diff --git a/time-manager.hpp b/time-manager.hpp
index 5e32a72..23560a4 100644
--- a/time-manager.hpp
+++ b/time-manager.hpp
@@ -14,9 +14,12 @@ public:
* to set the system time
*
* @param[in] timeOfDayUsec - Time value in microseconds
+ * @param[out] retError - Error message on failure
* @return - Status of time set operation
+ * @error - Error message populated
*/
- int setTimeOfDay(const std::chrono::microseconds& timeOfDayUsec);
+ int setTimeOfDay(const std::chrono::microseconds& timeOfDayUsec,
+ sd_bus_error *retError);
/** @brief Reads BMC time
*
OpenPOWER on IntegriCloud