summaryrefslogtreecommitdiff
path: root/src/timedate
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-11-21 04:28:45 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-11-21 04:28:45 +0900
commit56b0ef2fc283425df6ae6f1dc198e0c408f70471 (patch)
treed2eca8663472d75025fb419bbeb593cba5a19d20 /src/timedate
parent07ccf434e77b17b20d773ce8b2637083cd4fdafc (diff)
downloadsystemd-56b0ef2fc283425df6ae6f1dc198e0c408f70471.tar.gz
timedate: use localtime_or_gmtime_r() and mktime_or_timegm()
Diffstat (limited to 'src/timedate')
-rw-r--r--src/timedate/timedated.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index cdc0938d5f..8bfcfd5cdc 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -763,10 +763,7 @@ static int method_set_local_rtc(sd_bus_message *m, void *userdata, sd_bus_error
struct tm tm;
/* Sync system clock from RTC; first, initialize the timezone fields of struct tm. */
- if (c->local_rtc)
- localtime_r(&ts.tv_sec, &tm);
- else
- gmtime_r(&ts.tv_sec, &tm);
+ localtime_or_gmtime_r(&ts.tv_sec, &tm, !c->local_rtc);
/* Override the main fields of struct tm, but not the timezone fields */
r = clock_get_hwclock(&tm);
@@ -774,10 +771,7 @@ static int method_set_local_rtc(sd_bus_message *m, void *userdata, sd_bus_error
log_debug_errno(r, "Failed to get hardware clock, ignoring: %m");
else {
/* And set the system clock with this */
- if (c->local_rtc)
- ts.tv_sec = mktime(&tm);
- else
- ts.tv_sec = timegm(&tm);
+ mktime_or_timegm(&tm, !c->local_rtc);
if (clock_settime(CLOCK_REALTIME, &ts) < 0)
log_debug_errno(errno, "Failed to update system clock, ignoring: %m");
@@ -787,10 +781,7 @@ static int method_set_local_rtc(sd_bus_message *m, void *userdata, sd_bus_error
struct tm tm;
/* Sync RTC from system clock */
- if (c->local_rtc)
- localtime_r(&ts.tv_sec, &tm);
- else
- gmtime_r(&ts.tv_sec, &tm);
+ localtime_or_gmtime_r(&ts.tv_sec, &tm, !c->local_rtc);
r = clock_set_hwclock(&tm);
if (r < 0)
@@ -884,10 +875,7 @@ static int method_set_time(sd_bus_message *m, void *userdata, sd_bus_error *erro
}
/* Sync down to RTC */
- if (c->local_rtc)
- localtime_r(&ts.tv_sec, &tm);
- else
- gmtime_r(&ts.tv_sec, &tm);
+ localtime_or_gmtime_r(&ts.tv_sec, &tm, !c->local_rtc);
r = clock_set_hwclock(&tm);
if (r < 0)