]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: use LOG_ITEM() macros in server_driver_message() 36780/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Mar 2025 09:23:00 +0000 (18:23 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Mar 2025 16:58:28 +0000 (01:58 +0900)
src/journal/journald-kmsg.c
src/journal/journald-server.c
src/journal/journald-server.h
src/journal/journald-stream.c
src/journal/journald-syslog.c
src/journal/journald.c

index 8e327b8d237050ceccf41a999dba6ebe43839dcc..86115ad70da82cce89a2264074298cd75013208a 100644 (file)
@@ -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
index 4faaae5d771f6dd361f3dc1263f7240bc1a15aa2..abb45258779bba2bb63dd208a6542dea05b377ae 100644 (file)
@@ -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);
index 1f9e5dcf67d75230b8cba6bbeb8052e53a7e5265..c8669a8a97699f621593a745a92e21c57a737f8f 100644 (file)
@@ -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);
index 30a7737712703ec79d39b2397d7358ae05c9bf9d..2ada374b7393b285d955c156b8326e1967f67424 100644 (file)
@@ -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;
         }
 
index 811ff1a52247fc5301a45275c79cea9bf48290d7..5e6778fbbd7f4fdfddda3a9b296cb38f885ab44a 100644 (file)
@@ -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;
index 84f44c46b44f794ab482b489f15feb6c412bee3b..975afaa9529b28c448988abdd234c49f95e827f7 100644 (file)
@@ -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;
 }