diff options
author | Luca Boccassi <bluca@debian.org> | 2024-05-02 13:57:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 13:57:40 +0200 |
commit | afb1c42f5a4b5b2c26e18d983b3ed290a45dbc8a (patch) | |
tree | 9a98c375120bad32f49b6b73e3bbaae0791dff4f /src/journal | |
parent | Merge pull request #32609 from systemd/dependabot/github_actions/github/super... (diff) | |
parent | logs-show: adjust source timestamp with header timestamp (diff) | |
download | systemd-afb1c42f5a4b5b2c26e18d983b3ed290a45dbc8a.tar.xz systemd-afb1c42f5a4b5b2c26e18d983b3ed290a45dbc8a.zip |
Merge pull request #32592 from yuwata/journal-timestamp
journal: several timestamp cleanups and improvements
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/journald-audit.c | 19 | ||||
-rw-r--r-- | src/journal/journald-kmsg.c | 17 | ||||
-rw-r--r-- | src/journal/journald-server.c | 4 | ||||
-rw-r--r-- | src/journal/journald-server.h | 4 | ||||
-rw-r--r-- | src/journal/journald-socket.c | 2 | ||||
-rw-r--r-- | src/journal/journald-syslog.c | 4 |
6 files changed, 25 insertions, 25 deletions
diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index bddfe76c1a..d49283d225 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -335,10 +335,9 @@ void process_audit_string(Server *s, int type, const char *data, size_t size) { size_t n = 0, z; uint64_t seconds, msec, id; const char *p, *type_name; - char id_field[sizeof("_AUDIT_ID=") + DECIMAL_STR_MAX(uint64_t)], - type_field[sizeof("_AUDIT_TYPE=") + DECIMAL_STR_MAX(int)], - source_time_field[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)]; - struct iovec iovec[N_IOVEC_META_FIELDS + 8 + N_IOVEC_AUDIT_FIELDS]; + char id_field[STRLEN("_AUDIT_ID=") + DECIMAL_STR_MAX(uint64_t)], + type_field[STRLEN("_AUDIT_TYPE=") + DECIMAL_STR_MAX(int)]; + struct iovec iovec[N_IOVEC_META_FIELDS + 7 + N_IOVEC_AUDIT_FIELDS]; char *m, *type_field_name; int k; @@ -375,14 +374,10 @@ void process_audit_string(Server *s, int type, const char *data, size_t size) { iovec[n++] = IOVEC_MAKE_STRING("_TRANSPORT=audit"); - sprintf(source_time_field, "_SOURCE_REALTIME_TIMESTAMP=%" PRIu64, - (usec_t) seconds * USEC_PER_SEC + (usec_t) msec * USEC_PER_MSEC); - iovec[n++] = IOVEC_MAKE_STRING(source_time_field); - - sprintf(type_field, "_AUDIT_TYPE=%i", type); + xsprintf(type_field, "_AUDIT_TYPE=%i", type); iovec[n++] = IOVEC_MAKE_STRING(type_field); - sprintf(id_field, "_AUDIT_ID=%" PRIu64, id); + xsprintf(id_field, "_AUDIT_ID=%" PRIu64, id); iovec[n++] = IOVEC_MAKE_STRING(id_field); assert_cc(4 == LOG_FAC(LOG_AUTH)); @@ -401,7 +396,9 @@ void process_audit_string(Server *s, int type, const char *data, size_t size) { map_all_fields(p, map_fields_kernel, "_AUDIT_FIELD_", true, iovec, &n, n + N_IOVEC_AUDIT_FIELDS); - server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), NULL, NULL, LOG_NOTICE, 0); + server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), NULL, + TIMEVAL_STORE((usec_t) seconds * USEC_PER_SEC + (usec_t) msec * USEC_PER_MSEC), + LOG_NOTICE, 0); /* free() all entries that map_all_fields() added. All others * are allocated on the stack or are constant. */ diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 28d48808d0..a5e1715b13 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -98,7 +98,7 @@ static bool is_us(const char *identifier, const char *pid) { void dev_kmsg_record(Server *s, char *p, size_t l) { - _cleanup_free_ char *message = NULL, *syslog_priority = NULL, *syslog_pid = NULL, *syslog_facility = NULL, *syslog_identifier = NULL, *source_time = NULL, *identifier = NULL, *pid = NULL; + _cleanup_free_ char *message = NULL, *syslog_pid = NULL, *syslog_identifier = NULL, *identifier = NULL, *pid = NULL; struct iovec iovec[N_IOVEC_META_FIELDS + 7 + N_IOVEC_KERNEL_FIELDS + 2 + N_IOVEC_UDEV_FIELDS]; char *kernel_device = NULL; unsigned long long usec; @@ -253,16 +253,19 @@ void dev_kmsg_record(Server *s, char *p, size_t l) { } } - if (asprintf(&source_time, "_SOURCE_MONOTONIC_TIMESTAMP=%llu", usec) >= 0) - iovec[n++] = IOVEC_MAKE_STRING(source_time); + char source_time[STRLEN("_SOURCE_MONOTONIC_TIMESTAMP=") + DECIMAL_STR_MAX(unsigned long long)]; + xsprintf(source_time, "_SOURCE_MONOTONIC_TIMESTAMP=%llu", usec); + iovec[n++] = IOVEC_MAKE_STRING(source_time); iovec[n++] = IOVEC_MAKE_STRING("_TRANSPORT=kernel"); - if (asprintf(&syslog_priority, "PRIORITY=%i", priority & LOG_PRIMASK) >= 0) - iovec[n++] = IOVEC_MAKE_STRING(syslog_priority); + char syslog_priority[STRLEN("PRIORITY=") + DECIMAL_STR_MAX(int)]; + xsprintf(syslog_priority, "PRIORITY=%i", priority & LOG_PRIMASK); + iovec[n++] = IOVEC_MAKE_STRING(syslog_priority); - if (asprintf(&syslog_facility, "SYSLOG_FACILITY=%i", LOG_FAC(priority)) >= 0) - iovec[n++] = IOVEC_MAKE_STRING(syslog_facility); + char syslog_facility[STRLEN("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(int)]; + xsprintf(syslog_facility, "SYSLOG_FACILITY=%i", LOG_FAC(priority)); + iovec[n++] = IOVEC_MAKE_STRING(syslog_facility); if (LOG_FAC(priority) == LOG_KERN) iovec[n++] = IOVEC_MAKE_STRING("SYSLOG_IDENTIFIER=kernel"); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 2fa014a89c..a52aef5986 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -1073,7 +1073,7 @@ static void server_dispatch_message_real( int priority, pid_t object_pid) { - char source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)]; + char source_time[STRLEN("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)]; _unused_ _cleanup_free_ char *cmdline1 = NULL, *cmdline2 = NULL; uid_t journal_uid; ClientContext *o; @@ -1153,7 +1153,7 @@ static void server_dispatch_message_real( assert(n <= m); if (tv) { - sprintf(source_time, "_SOURCE_REALTIME_TIMESTAMP=" USEC_FMT, timeval_load(tv)); + xsprintf(source_time, "_SOURCE_REALTIME_TIMESTAMP=" USEC_FMT, timeval_load(tv)); iovec[n++] = IOVEC_MAKE_STRING(source_time); } diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index a7939029ca..3878061d09 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -162,8 +162,8 @@ struct Server { bool sent_notify_ready:1; bool sync_scheduled:1; - char machine_id_field[sizeof("_MACHINE_ID=") + 32]; - char boot_id_field[sizeof("_BOOT_ID=") + 32]; + char machine_id_field[STRLEN("_MACHINE_ID=") + SD_ID128_STRING_MAX]; + char boot_id_field[STRLEN("_BOOT_ID=") + SD_ID128_STRING_MAX]; char *hostname_field; char *namespace_field; char *runtime_directory; diff --git a/src/journal/journald-socket.c b/src/journal/journald-socket.c index 24c8f05d45..25e56de6f3 100644 --- a/src/journal/journald-socket.c +++ b/src/journal/journald-socket.c @@ -141,7 +141,7 @@ int server_forward_socket( /* Synthesise __REALTIME_TIMESTAMP as the last argument so systemd-journal-upload can receive these * export messages. */ - char buf[sizeof("__REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t) + 2]; + char buf[STRLEN("__REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t) + 2]; xsprintf(buf, "__REALTIME_TIMESTAMP="USEC_FMT"\n\n", now(CLOCK_REALTIME)); iov[iov_idx++] = IOVEC_MAKE_STRING(buf); diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index f6accb5b44..4539722b20 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -314,8 +314,8 @@ void server_process_syslog_message( const char *label, size_t label_len) { - char *t, syslog_priority[sizeof("PRIORITY=") + DECIMAL_STR_MAX(int)], - syslog_facility[sizeof("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(int)]; + char *t, syslog_priority[STRLEN("PRIORITY=") + DECIMAL_STR_MAX(int)], + syslog_facility[STRLEN("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(int)]; const char *msg, *syslog_ts, *a; _cleanup_free_ char *identifier = NULL, *pid = NULL, *dummy = NULL, *msg_msg = NULL, *msg_raw = NULL; |