diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-08-28 14:10:01 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-09-05 17:40:25 +0200 |
commit | 6f5cf41570776f489967d1a7de18260b2bc9acf9 (patch) | |
tree | 0c94612f28294ccf45e6f737c439d0f921c88cc2 /src/journal/journald-syslog.c | |
parent | hwclock-util: the struct tm parameter is not a pure return parameter, it's al... (diff) | |
download | systemd-6f5cf41570776f489967d1a7de18260b2bc9acf9.tar.xz systemd-6f5cf41570776f489967d1a7de18260b2bc9acf9.zip |
time-util: rework localtime_or_gmtime() into localtime_or_gmtime_usec()
We typically want to deal in usec_t, hence let's change the prototype
accordingly, and do proper range checks. Also, make sure are not
confused by negative times.
Do something similar for mktime_or_timegm().
This is a more comprehensive alternative to #34065
Replaces: #34065
Diffstat (limited to 'src/journal/journald-syslog.c')
-rw-r--r-- | src/journal/journald-syslog.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 4ad73ed387..811ff1a522 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -127,7 +127,6 @@ void server_forward_syslog(Server *s, int priority, const char *identifier, cons char header_priority[DECIMAL_STR_MAX(priority) + 3], header_time[64], header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1]; int n = 0; - time_t t; struct tm tm; _cleanup_free_ char *ident_buf = NULL; @@ -144,8 +143,7 @@ void server_forward_syslog(Server *s, int priority, const char *identifier, cons iovec[n++] = IOVEC_MAKE_STRING(header_priority); /* Second: timestamp */ - t = tv ? tv->tv_sec : ((time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC)); - if (!localtime_r(&t, &tm)) + if (localtime_or_gmtime_usec(tv ? tv->tv_sec * USEC_PER_SEC : now(CLOCK_REALTIME), /* utc= */ false, &tm) < 0) return; if (strftime(header_time, sizeof(header_time), "%h %e %T ", &tm) <= 0) return; |