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 */
.msg_iovlen = ELEMENTSOF(iovec),
};
time_t t;
- struct tm *tm;
+ struct tm tm;
if (syslog_fd < 0)
return 0;
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());
header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1];
int n = 0;
time_t t;
- struct tm *tm;
+ struct tm tm;
_cleanup_free_ char *ident_buf = NULL;
assert(s);
/* Second: timestamp */
t = tv ? tv->tv_sec : ((time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC));
- tm = localtime(&t);
- if (!tm)
+ if (!localtime_r(&t, &tm))
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;
iovec[n++] = IOVEC_MAKE_STRING(header_time);
if (c->local_rtc) {
struct timespec ts;
- struct tm *tm;
+ struct tm tm;
/* 4. Sync RTC from system clock, with the new delta */
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)
log_debug_errno(r, "Failed to sync time to hardware clock, ignoring: %m");
}