tree-wide: use localtime_r() instead of localtime()
Follow-up for e46acb7950.
This commit is contained in:
@@ -90,13 +90,13 @@ int clock_is_localtime(const char* adjtime_path) {
|
||||
int clock_set_timezone(int *min) {
|
||||
const struct timeval *tv_null = NULL;
|
||||
struct timespec ts;
|
||||
struct tm *tm;
|
||||
struct tm tm;
|
||||
int minutesdelta;
|
||||
struct timezone tz;
|
||||
|
||||
assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
|
||||
assert_se(tm = localtime(&ts.tv_sec));
|
||||
minutesdelta = tm->tm_gmtoff / 60;
|
||||
assert_se(localtime_r(&ts.tv_sec, &tm));
|
||||
minutesdelta = tm.tm_gmtoff / 60;
|
||||
|
||||
tz.tz_minuteswest = -minutesdelta;
|
||||
tz.tz_dsttime = 0; /* DST_NONE */
|
||||
|
||||
+3
-4
@@ -401,7 +401,7 @@ static int write_to_syslog(
|
||||
.msg_iovlen = ELEMENTSOF(iovec),
|
||||
};
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
struct tm tm;
|
||||
|
||||
if (syslog_fd < 0)
|
||||
return 0;
|
||||
@@ -409,11 +409,10 @@ static int write_to_syslog(
|
||||
xsprintf(header_priority, "<%i>", level);
|
||||
|
||||
t = (time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC);
|
||||
tm = localtime(&t);
|
||||
if (!tm)
|
||||
if (!localtime_r(&t, &tm))
|
||||
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;
|
||||
|
||||
xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
|
||||
|
||||
Reference in New Issue
Block a user