From: Yu Watanabe Date: Tue, 18 Mar 2025 09:23:00 +0000 (+0900) Subject: journal: use LOG_ITEM() macros in server_driver_message() X-Git-Tag: v258-rc1~1016^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b05969ffd6c07efb4319ea8c0f6472ec51a4956b;p=thirdparty%2Fsystemd.git journal: use LOG_ITEM() macros in server_driver_message() --- diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 8e327b8d237..86115ad70da 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -147,10 +147,9 @@ void dev_kmsg_record(Server *s, char *p, size_t l) { /* Did we lose any? */ if (serial > *s->kernel_seqnum) server_driver_message(s, 0, - "MESSAGE_ID=" SD_MESSAGE_JOURNAL_MISSED_STR, + LOG_MESSAGE_ID(SD_MESSAGE_JOURNAL_MISSED_STR), LOG_MESSAGE("Missed %"PRIu64" kernel messages", - serial - *s->kernel_seqnum), - NULL); + serial - *s->kernel_seqnum)); /* Make sure we never read this one again. Note that * we always store the next message serial we expect diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 4faaae5d771..abb45258779 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -228,27 +228,26 @@ void server_space_usage_message(Server *s, JournalStorage *storage) { const JournalMetrics *metrics = &storage->metrics; server_driver_message(s, 0, - "MESSAGE_ID=" SD_MESSAGE_JOURNAL_USAGE_STR, + LOG_MESSAGE_ID(SD_MESSAGE_JOURNAL_USAGE_STR), LOG_MESSAGE("%s (%s) is %s, max %s, %s free.", storage->name, storage->path, FORMAT_BYTES(storage->space.vfs_used), FORMAT_BYTES(storage->space.limit), FORMAT_BYTES(storage->space.available)), - "JOURNAL_NAME=%s", storage->name, - "JOURNAL_PATH=%s", storage->path, - "CURRENT_USE=%"PRIu64, storage->space.vfs_used, - "CURRENT_USE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_used), - "MAX_USE=%"PRIu64, metrics->max_use, - "MAX_USE_PRETTY=%s", FORMAT_BYTES(metrics->max_use), - "DISK_KEEP_FREE=%"PRIu64, metrics->keep_free, - "DISK_KEEP_FREE_PRETTY=%s", FORMAT_BYTES(metrics->keep_free), - "DISK_AVAILABLE=%"PRIu64, storage->space.vfs_available, - "DISK_AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_available), - "LIMIT=%"PRIu64, storage->space.limit, - "LIMIT_PRETTY=%s", FORMAT_BYTES(storage->space.limit), - "AVAILABLE=%"PRIu64, storage->space.available, - "AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.available), - NULL); + LOG_ITEM("JOURNAL_NAME=%s", storage->name), + LOG_ITEM("JOURNAL_PATH=%s", storage->path), + LOG_ITEM("CURRENT_USE=%"PRIu64, storage->space.vfs_used), + LOG_ITEM("CURRENT_USE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_used)), + LOG_ITEM("MAX_USE=%"PRIu64, metrics->max_use), + LOG_ITEM("MAX_USE_PRETTY=%s", FORMAT_BYTES(metrics->max_use)), + LOG_ITEM("DISK_KEEP_FREE=%"PRIu64, metrics->keep_free), + LOG_ITEM("DISK_KEEP_FREE_PRETTY=%s", FORMAT_BYTES(metrics->keep_free)), + LOG_ITEM("DISK_AVAILABLE=%"PRIu64, storage->space.vfs_available), + LOG_ITEM("DISK_AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_available)), + LOG_ITEM("LIMIT=%"PRIu64, storage->space.limit), + LOG_ITEM("LIMIT_PRETTY=%s", FORMAT_BYTES(storage->space.limit)), + LOG_ITEM("AVAILABLE=%"PRIu64, storage->space.available), + LOG_ITEM("AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.available))); } static void server_add_acls(JournalFile *f, uid_t uid) { @@ -1211,8 +1210,7 @@ static void server_dispatch_message_real( server_write_to_journal(s, journal_uid, iovec, n, &ts, priority); } -void server_driver_message(Server *s, pid_t object_pid, const char *message_id, const char *format, ...) { - +void server_driver_message_internal(Server *s, pid_t object_pid, const char *format, ...) { struct iovec *iovec; size_t n = 0, k, m; va_list ap; @@ -1232,12 +1230,12 @@ void server_driver_message(Server *s, pid_t object_pid, const char *message_id, assert_cc(6 == LOG_INFO); iovec[n++] = IOVEC_MAKE_STRING("PRIORITY=6"); - if (message_id) - iovec[n++] = IOVEC_MAKE_STRING(message_id); k = n; va_start(ap, format); + DISABLE_WARNING_FORMAT_NONLITERAL; r = log_format_iovec(iovec, m, &n, false, 0, format, ap); + REENABLE_WARNING; /* Error handling below */ va_end(ap); @@ -1302,10 +1300,9 @@ void server_dispatch_message( /* Write a suppression message if we suppressed something */ if (rl > 1) server_driver_message(s, c->pid, - "MESSAGE_ID=" SD_MESSAGE_JOURNAL_DROPPED_STR, + LOG_MESSAGE_ID(SD_MESSAGE_JOURNAL_DROPPED_STR), LOG_MESSAGE("Suppressed %i messages from %s", rl - 1, c->unit), - "N_DROPPED=%i", rl - 1, - NULL); + LOG_ITEM("N_DROPPED=%i", rl - 1)); } server_dispatch_message_real(s, iovec, n, m, c, tv, priority, object_pid); @@ -1449,12 +1446,11 @@ finish: } } - server_driver_message(s, 0, NULL, + server_driver_message(s, 0, LOG_MESSAGE("Time spent on flushing to %s is %s for %u entries.", s->system_storage.path, FORMAT_TIMESPAN(usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0), - n), - NULL); + n)); fn = strjoina(s->runtime_directory, "/flushed"); k = touch(fn); diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index 1f9e5dcf67d..c8669a8a976 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -209,7 +209,8 @@ struct Server { #define N_IOVEC_AUDIT_FIELDS 64 void server_dispatch_message(Server *s, struct iovec *iovec, size_t n, size_t m, ClientContext *c, const struct timeval *tv, int priority, pid_t object_pid); -void server_driver_message(Server *s, pid_t object_pid, const char *message_id, const char *format, ...) _sentinel_ _printf_(4,0); +void server_driver_message_internal(Server *s, pid_t object_pid, const char *format, ...) _sentinel_; +#define server_driver_message(...) server_driver_message_internal(__VA_ARGS__, NULL) /* gperf lookup function */ const struct ConfigPerfItem* journald_gperf_lookup(const char *key, GPERF_LEN_TYPE length); diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 30a77377127..2ada374b739 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -745,7 +745,7 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent */ fd = safe_close(fd); - server_driver_message(s, u.pid, NULL, LOG_MESSAGE("Too many stdout streams, refusing connection."), NULL); + server_driver_message(s, u.pid, LOG_MESSAGE("Too many stdout streams, refusing connection.")); return 0; } diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 811ff1a5224..5e6778fbbd7 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -521,10 +521,9 @@ void server_maybe_warn_forward_syslog_missed(Server *s) { return; server_driver_message(s, 0, - "MESSAGE_ID=" SD_MESSAGE_FORWARD_SYSLOG_MISSED_STR, + LOG_MESSAGE_ID(SD_MESSAGE_FORWARD_SYSLOG_MISSED_STR), LOG_MESSAGE("Forwarding to syslog missed %u messages.", - s->n_forward_syslog_missed), - NULL); + s->n_forward_syslog_missed)); s->n_forward_syslog_missed = 0; s->last_warn_forward_syslog_missed = n; diff --git a/src/journal/journald.c b/src/journal/journald.c index 84f44c46b44..975afaa9529 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -66,9 +66,8 @@ static int run(int argc, char *argv[]) { log_debug("systemd-journald running as PID "PID_FMT" for the system.", getpid_cached()); server_driver_message(s, 0, - "MESSAGE_ID=" SD_MESSAGE_JOURNAL_START_STR, - LOG_MESSAGE("Journal started"), - NULL); + LOG_MESSAGE_ID(SD_MESSAGE_JOURNAL_START_STR), + LOG_MESSAGE("Journal started")); /* Make sure to send the usage message *after* flushing the * journal so entries from the runtime journals are ordered @@ -124,9 +123,8 @@ static int run(int argc, char *argv[]) { log_debug("systemd-journald stopped as PID "PID_FMT" for the system.", getpid_cached()); server_driver_message(s, 0, - "MESSAGE_ID=" SD_MESSAGE_JOURNAL_STOP_STR, - LOG_MESSAGE("Journal stopped"), - NULL); + LOG_MESSAGE_ID(SD_MESSAGE_JOURNAL_STOP_STR), + LOG_MESSAGE("Journal stopped")); return 0; }