mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:35:06 -05:00
rtc: pass info whether RTC is on UTC as a function parameter
rtc_from_t() and t_from_rtc() call either gmtime or localtime depending on the value of a global rtc_on_utc variable. This will not be appropriate anymore when we start exporting functions that call rtc_from_t() and t_from_rtc() for use outside of rtc_linux.c as the rtc_on_utc variable may not have been initialized yet or at all. Therefore make whether the RTC is on UTC a function parameter of these functions, so the value can be propagated from the callers.
This commit is contained in:
committed by
Miroslav Lichvar
parent
13db3d6902
commit
68301238a0
14
rtc_linux.c
14
rtc_linux.c
@@ -297,10 +297,10 @@ slew_samples
|
||||
whether the user runs his RTC on the local time zone or UTC */
|
||||
|
||||
static void
|
||||
rtc_from_t(const time_t *t, struct rtc_time *rtc_raw)
|
||||
rtc_from_t(const time_t *t, struct rtc_time *rtc_raw, int utc)
|
||||
{
|
||||
struct tm *rtc_tm;
|
||||
if (rtc_on_utc) {
|
||||
if (utc) {
|
||||
rtc_tm = gmtime(t);
|
||||
} else {
|
||||
rtc_tm = localtime(t);
|
||||
@@ -352,7 +352,7 @@ rtc_from_t(const time_t *t, struct rtc_time *rtc_raw)
|
||||
*/
|
||||
|
||||
static time_t
|
||||
t_from_rtc(struct rtc_time *rtc_raw)
|
||||
t_from_rtc(struct rtc_time *rtc_raw, int utc)
|
||||
{
|
||||
struct tm rtc_tm, temp1, temp2, *tm;
|
||||
long diff;
|
||||
@@ -372,7 +372,7 @@ t_from_rtc(struct rtc_time *rtc_raw)
|
||||
|
||||
t1 = mktime(&temp1);
|
||||
|
||||
tm = rtc_on_utc ? gmtime(&t1) : localtime(&t1);
|
||||
tm = utc ? gmtime(&t1) : localtime(&t1);
|
||||
if (!tm) {
|
||||
DEBUG_LOG("gmtime()/localtime() failed");
|
||||
return -1;
|
||||
@@ -610,7 +610,7 @@ set_rtc(time_t new_rtc_time)
|
||||
struct rtc_time rtc_raw;
|
||||
int status;
|
||||
|
||||
rtc_from_t(&new_rtc_time, &rtc_raw);
|
||||
rtc_from_t(&new_rtc_time, &rtc_raw, rtc_on_utc);
|
||||
|
||||
status = ioctl(fd, RTC_SET_TIME, &rtc_raw);
|
||||
if (status < 0) {
|
||||
@@ -805,7 +805,7 @@ read_from_device(int fd_, int event, void *any)
|
||||
}
|
||||
|
||||
/* Convert RTC time into a struct timespec */
|
||||
rtc_t = t_from_rtc(&rtc_raw);
|
||||
rtc_t = t_from_rtc(&rtc_raw, rtc_on_utc);
|
||||
|
||||
if (rtc_t == (time_t)(-1)) {
|
||||
error = 1;
|
||||
@@ -955,7 +955,7 @@ RTC_Linux_TimePreInit(time_t driftfile_time)
|
||||
|
||||
if (status >= 0) {
|
||||
/* Convert to seconds since 1970 */
|
||||
rtc_t = t_from_rtc(&rtc_raw);
|
||||
rtc_t = t_from_rtc(&rtc_raw, rtc_on_utc);
|
||||
|
||||
if (rtc_t != (time_t)(-1)) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user