tree-wide: use localtime_r() instead of localtime()
Follow-up for e46acb7950
.
This commit is contained in:
parent
ad16158c10
commit
e0f691e1fd
|
@ -90,13 +90,13 @@ int clock_is_localtime(const char* adjtime_path) {
|
||||||
int clock_set_timezone(int *min) {
|
int clock_set_timezone(int *min) {
|
||||||
const struct timeval *tv_null = NULL;
|
const struct timeval *tv_null = NULL;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
int minutesdelta;
|
int minutesdelta;
|
||||||
struct timezone tz;
|
struct timezone tz;
|
||||||
|
|
||||||
assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
|
assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
|
||||||
assert_se(tm = localtime(&ts.tv_sec));
|
assert_se(localtime_r(&ts.tv_sec, &tm));
|
||||||
minutesdelta = tm->tm_gmtoff / 60;
|
minutesdelta = tm.tm_gmtoff / 60;
|
||||||
|
|
||||||
tz.tz_minuteswest = -minutesdelta;
|
tz.tz_minuteswest = -minutesdelta;
|
||||||
tz.tz_dsttime = 0; /* DST_NONE */
|
tz.tz_dsttime = 0; /* DST_NONE */
|
||||||
|
|
|
@ -401,7 +401,7 @@ static int write_to_syslog(
|
||||||
.msg_iovlen = ELEMENTSOF(iovec),
|
.msg_iovlen = ELEMENTSOF(iovec),
|
||||||
};
|
};
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
if (syslog_fd < 0)
|
if (syslog_fd < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -409,11 +409,10 @@ static int write_to_syslog(
|
||||||
xsprintf(header_priority, "<%i>", level);
|
xsprintf(header_priority, "<%i>", level);
|
||||||
|
|
||||||
t = (time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC);
|
t = (time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC);
|
||||||
tm = localtime(&t);
|
if (!localtime_r(&t, &tm))
|
||||||
if (!tm)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (strftime(header_time, sizeof(header_time), "%h %e %T ", tm) <= 0)
|
if (strftime(header_time, sizeof(header_time), "%h %e %T ", &tm) <= 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
|
xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
|
||||||
|
|
|
@ -117,7 +117,7 @@ void server_forward_syslog(Server *s, int priority, const char *identifier, cons
|
||||||
header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1];
|
header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1];
|
||||||
int n = 0;
|
int n = 0;
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
_cleanup_free_ char *ident_buf = NULL;
|
_cleanup_free_ char *ident_buf = NULL;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
|
@ -134,10 +134,9 @@ void server_forward_syslog(Server *s, int priority, const char *identifier, cons
|
||||||
|
|
||||||
/* Second: timestamp */
|
/* Second: timestamp */
|
||||||
t = tv ? tv->tv_sec : ((time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC));
|
t = tv ? tv->tv_sec : ((time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC));
|
||||||
tm = localtime(&t);
|
if (!localtime_r(&t, &tm))
|
||||||
if (!tm)
|
|
||||||
return;
|
return;
|
||||||
if (strftime(header_time, sizeof(header_time), "%h %e %T ", tm) <= 0)
|
if (strftime(header_time, sizeof(header_time), "%h %e %T ", &tm) <= 0)
|
||||||
return;
|
return;
|
||||||
iovec[n++] = IOVEC_MAKE_STRING(header_time);
|
iovec[n++] = IOVEC_MAKE_STRING(header_time);
|
||||||
|
|
||||||
|
|
|
@ -557,13 +557,13 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *
|
||||||
|
|
||||||
if (c->local_rtc) {
|
if (c->local_rtc) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
/* 4. Sync RTC from system clock, with the new delta */
|
/* 4. Sync RTC from system clock, with the new delta */
|
||||||
assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
|
assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
|
||||||
assert_se(tm = localtime(&ts.tv_sec));
|
assert_se(localtime_r(&ts.tv_sec, &tm));
|
||||||
|
|
||||||
r = clock_set_hwclock(tm);
|
r = clock_set_hwclock(&tm);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to sync time to hardware clock, ignoring: %m");
|
log_debug_errno(r, "Failed to sync time to hardware clock, ignoring: %m");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue