]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Use shared log ratelimit constant
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 5 Dec 2022 13:29:29 +0000 (14:29 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 5 Dec 2022 13:41:51 +0000 (14:41 +0100)
Instead of maintaining two different constants, move the constant
to journal-internal.h and share it between files.

src/journal/journald-audit.c
src/journal/journald-context.c
src/journal/journald-kmsg.c
src/journal/journald-native.c
src/journal/journald-server.c
src/journal/journald-server.h
src/journal/journald-stream.c
src/journal/journald-syslog.c
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/journal-internal.h

index d301d2896621d981231bcb1973cb630be302fc20..a2ebf97c9cb18b281392090e313dca75630c1957 100644 (file)
@@ -8,6 +8,7 @@
 #include "fd-util.h"
 #include "hexdecoct.h"
 #include "io-util.h"
+#include "journal-internal.h"
 #include "journald-audit.h"
 #include "missing_audit.h"
 #include "string-util.h"
@@ -441,7 +442,7 @@ void server_process_audit_message(
         }
 
         if (!NLMSG_OK(nl, buffer_size)) {
-                log_ratelimit_error(JOURNALD_LOG_RATELIMIT, "Audit netlink message truncated.");
+                log_ratelimit_error(JOURNAL_LOG_RATELIMIT, "Audit netlink message truncated.");
                 return;
         }
 
index 6d58422dddac0debc0f010dc6185a7248f36e287..b2f6fcc2a3c416068c423cf8c2b8195f7507ddee 100644 (file)
@@ -12,6 +12,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "io-util.h"
+#include "journal-internal.h"
 #include "journal-util.h"
 #include "journald-context.h"
 #include "parse-util.h"
@@ -771,7 +772,7 @@ void client_context_acquire_default(Server *s) {
 
                 r = client_context_acquire(s, ucred.pid, &ucred, NULL, 0, NULL, &s->my_context);
                 if (r < 0)
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to acquire our own context, ignoring: %m");
         }
 
@@ -781,7 +782,7 @@ void client_context_acquire_default(Server *s) {
 
                 r = client_context_acquire(s, 1, NULL, NULL, 0, NULL, &s->pid1_context);
                 if (r < 0)
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to acquire PID1's context, ignoring: %m");
 
         }
index 10faf2dd06e475f6c6f4cb72f1c206fb975af21a..99eace084876bb72b01a1faf078b5dca6800158a 100644 (file)
@@ -16,6 +16,7 @@
 #include "format-util.h"
 #include "fs-util.h"
 #include "io-util.h"
+#include "journal-internal.h"
 #include "journald-kmsg.h"
 #include "journald-server.h"
 #include "journald-syslog.h"
@@ -329,7 +330,7 @@ static int server_read_dev_kmsg(Server *s) {
                 if (ERRNO_IS_TRANSIENT(errno) || errno == EPIPE)
                         return 0;
 
-                return log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT, "Failed to read from /dev/kmsg: %m");
+                return log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT, "Failed to read from /dev/kmsg: %m");
         }
 
         dev_kmsg_record(s, buffer, l);
@@ -368,7 +369,7 @@ static int dispatch_dev_kmsg(sd_event_source *es, int fd, uint32_t revents, void
         assert(fd == s->dev_kmsg_fd);
 
         if (revents & EPOLLERR)
-                log_ratelimit_warning(JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning(JOURNAL_LOG_RATELIMIT,
                                       "/dev/kmsg buffer overrun, some messages lost.");
 
         if (!(revents & EPOLLIN))
index 21e20db2d44f033690dcff7c170a40d12ba96150..847f69c1ffebe545b37ac864e9c7958dd53d0cd8 100644 (file)
@@ -11,6 +11,7 @@
 #include "fs-util.h"
 #include "io-util.h"
 #include "journal-importer.h"
+#include "journal-internal.h"
 #include "journal-util.h"
 #include "journald-console.h"
 #include "journald-kmsg.h"
@@ -309,7 +310,7 @@ void server_process_native_message(
         if (ucred && pid_is_valid(ucred->pid)) {
                 r = client_context_get(s, ucred->pid, ucred, label, label_len, NULL, &context);
                 if (r < 0)
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to retrieve credentials for PID " PID_FMT ", ignoring: %m",
                                                     ucred->pid);
         }
@@ -350,33 +351,33 @@ void server_process_native_file(
 
                 r = fd_get_path(fd, &k);
                 if (r < 0) {
-                        log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                                   "readlink(/proc/self/fd/%i) failed: %m", fd);
                         return;
                 }
 
                 e = PATH_STARTSWITH_SET(k, "/dev/shm/", "/tmp/", "/var/tmp/");
                 if (!e) {
-                        log_ratelimit_error(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error(JOURNAL_LOG_RATELIMIT,
                                             "Received file outside of allowed directories. Refusing.");
                         return;
                 }
 
                 if (!filename_is_valid(e)) {
-                        log_ratelimit_error(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error(JOURNAL_LOG_RATELIMIT,
                                             "Received file in subdirectory of allowed directories. Refusing.");
                         return;
                 }
         }
 
         if (fstat(fd, &st) < 0) {
-                log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT,
                                           "Failed to stat passed file, ignoring: %m");
                 return;
         }
 
         if (!S_ISREG(st.st_mode)) {
-                log_ratelimit_error(JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_error(JOURNAL_LOG_RATELIMIT,
                                     "File passed is not regular. Ignoring.");
                 return;
         }
@@ -387,7 +388,7 @@ void server_process_native_file(
         /* When !sealed, set a lower memory limit. We have to read the file,
          * effectively doubling memory use. */
         if (st.st_size > ENTRY_SIZE_MAX / (sealed ? 1 : 2)) {
-                log_ratelimit_error(JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_error(JOURNAL_LOG_RATELIMIT,
                                     "File passed too large (%"PRIu64" bytes). Ignoring.",
                                     (uint64_t) st.st_size);
                 return;
@@ -402,7 +403,7 @@ void server_process_native_file(
                 ps = PAGE_ALIGN(st.st_size);
                 p = mmap(NULL, ps, PROT_READ, MAP_PRIVATE, fd, 0);
                 if (p == MAP_FAILED) {
-                        log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT,
                                                   "Failed to map memfd, ignoring: %m");
                         return;
                 }
@@ -415,7 +416,7 @@ void server_process_native_file(
                 ssize_t n;
 
                 if (fstatvfs(fd, &vfs) < 0) {
-                        log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT,
                                                   "Failed to stat file system of passed file, not processing it: %m");
                         return;
                 }
@@ -426,7 +427,7 @@ void server_process_native_file(
                  * https://github.com/systemd/systemd/issues/1822
                  */
                 if (vfs.f_flag & ST_MANDLOCK) {
-                        log_ratelimit_error(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error(JOURNAL_LOG_RATELIMIT,
                                             "Received file descriptor from file system with mandatory locking enabled, not processing it.");
                         return;
                 }
@@ -440,7 +441,7 @@ void server_process_native_file(
                  * and so is SMB. */
                 r = fd_nonblock(fd, true);
                 if (r < 0) {
-                        log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                                   "Failed to make fd non-blocking, not processing it: %m");
                         return;
                 }
@@ -457,7 +458,7 @@ void server_process_native_file(
 
                 n = pread(fd, p, st.st_size, 0);
                 if (n < 0)
-                        log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT,
                                                   "Failed to read file, ignoring: %m");
                 else if (n > 0)
                         server_process_native_message(s, p, n, ucred, tv, label, label_len);
index cb94a037d572e744fb826c9278f26f37e8614b96..a223f4fb2b61a5940be3bc600215e4087b2f925d 100644 (file)
@@ -102,10 +102,10 @@ static int determine_path_usage(
         d = opendir(path);
         if (!d)
                 return log_ratelimit_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
-                                                errno, JOURNALD_LOG_RATELIMIT, "Failed to open %s: %m", path);
+                                                errno, JOURNAL_LOG_RATELIMIT, "Failed to open %s: %m", path);
 
         if (fstatvfs(dirfd(d), &ss) < 0)
-                return log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT,
+                return log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT,
                                                 "Failed to fstatvfs(%s): %m", path);
 
         *ret_free = ss.f_bsize * ss.f_bavail;
@@ -256,7 +256,7 @@ static void server_add_acls(ManagedJournalFile *f, uid_t uid) {
 
         r = fd_add_uid_acl_permission(f->file->fd, uid, ACL_READ);
         if (r < 0)
-                log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                             "Failed to set ACL on %s, ignoring: %m", f->file->path);
 #endif
 }
@@ -357,7 +357,7 @@ static int system_journal_open(Server *s, bool flush_requested, bool relinquish_
                         patch_min_use(&s->system_storage);
                 } else {
                         if (!IN_SET(r, -ENOENT, -EROFS))
-                                log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                                log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                             "Failed to open system journal: %m");
 
                         r = 0;
@@ -387,7 +387,7 @@ static int system_journal_open(Server *s, bool flush_requested, bool relinquish_
                         r = open_journal(s, false, fn, O_RDWR, false, &s->runtime_storage.metrics, &s->runtime_journal);
                         if (r < 0) {
                                 if (r != -ENOENT)
-                                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                                     "Failed to open runtime journal: %m");
 
                                 r = 0;
@@ -402,7 +402,7 @@ static int system_journal_open(Server *s, bool flush_requested, bool relinquish_
 
                         r = open_journal(s, true, fn, O_RDWR|O_CREAT, false, &s->runtime_storage.metrics, &s->runtime_journal);
                         if (r < 0)
-                                return log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                                return log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                                    "Failed to open runtime journal: %m");
                 }
 
@@ -500,10 +500,10 @@ static int do_rotate(
         r = managed_journal_file_rotate(f, s->mmap, file_flags, s->compress.threshold_bytes, s->deferred_closes);
         if (r < 0) {
                 if (*f)
-                        return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                                          "Failed to rotate %s: %m", (*f)->file->path);
                 else
-                        return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                                          "Failed to create new %s journal: %m", name);
         }
 
@@ -554,7 +554,7 @@ static int vacuum_offline_user_journals(Server *s) {
                 if (errno == ENOENT)
                         return 0;
 
-                return log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT,
+                return log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT,
                                                  "Failed to open %s: %m", s->system_storage.path);
         }
 
@@ -570,7 +570,7 @@ static int vacuum_offline_user_journals(Server *s) {
                 de = readdir_no_dot(d);
                 if (!de) {
                         if (errno != 0)
-                                log_ratelimit_warning_errno(errno, JOURNALD_LOG_RATELIMIT,
+                                log_ratelimit_warning_errno(errno, JOURNAL_LOG_RATELIMIT,
                                                             "Failed to enumerate %s, ignoring: %m",
                                                             s->system_storage.path);
 
@@ -605,7 +605,7 @@ static int vacuum_offline_user_journals(Server *s) {
                 fd = openat(dirfd(d), de->d_name, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW|O_NONBLOCK);
                 if (fd < 0) {
                         log_ratelimit_full_errno(IN_SET(errno, ELOOP, ENOENT) ? LOG_DEBUG : LOG_WARNING,
-                                                 errno, JOURNALD_LOG_RATELIMIT,
+                                                 errno, JOURNAL_LOG_RATELIMIT,
                                                  "Failed to open journal file '%s' for rotation: %m", full);
                         continue;
                 }
@@ -628,13 +628,13 @@ static int vacuum_offline_user_journals(Server *s) {
                                 NULL,
                                 &f);
                 if (r < 0) {
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to read journal file %s for rotation, trying to move it out of the way: %m",
                                                     full);
 
                         r = journal_file_dispose(dirfd(d), de->d_name);
                         if (r < 0)
-                                log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                                log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                             "Failed to move %s out of the way, ignoring: %m",
                                                             full);
                         else
@@ -692,21 +692,21 @@ void server_sync(Server *s) {
         if (s->system_journal) {
                 r = managed_journal_file_set_offline(s->system_journal, false);
                 if (r < 0)
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to sync system journal, ignoring: %m");
         }
 
         ORDERED_HASHMAP_FOREACH(f, s->user_journals) {
                 r = managed_journal_file_set_offline(f, false);
                 if (r < 0)
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to sync user journal, ignoring: %m");
         }
 
         if (s->sync_event_source) {
                 r = sd_event_source_set_enabled(s->sync_event_source, SD_EVENT_OFF);
                 if (r < 0)
-                        log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                                   "Failed to disable sync timer source: %m");
         }
 
@@ -729,7 +729,7 @@ static void do_vacuum(Server *s, JournalStorage *storage, bool verbose) {
                                      storage->metrics.n_max_files, s->max_retention_usec,
                                      &s->oldest_file_usec, verbose);
         if (r < 0 && r != -ENOENT)
-                log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                             "Failed to vacuum %s, ignoring: %m", storage->path);
 
         cache_space_invalidate(&storage->space);
@@ -802,37 +802,37 @@ static bool shall_try_append_again(JournalFile *f, int r) {
                 return true;
 
         case -EIO:             /* I/O error of some kind (mmap) */
-                log_ratelimit_warning(JOURNALD_LOG_RATELIMIT, "%s: IO error, rotating.", f->path);
+                log_ratelimit_warning(JOURNAL_LOG_RATELIMIT, "%s: IO error, rotating.", f->path);
                 return true;
 
         case -EHOSTDOWN:       /* Other machine                 */
-                log_ratelimit_info(JOURNALD_LOG_RATELIMIT, "%s: Journal file from other machine, rotating.", f->path);
+                log_ratelimit_info(JOURNAL_LOG_RATELIMIT, "%s: Journal file from other machine, rotating.", f->path);
                 return true;
 
         case -EBUSY:           /* Unclean shutdown              */
-                log_ratelimit_info(JOURNALD_LOG_RATELIMIT, "%s: Unclean shutdown, rotating.", f->path);
+                log_ratelimit_info(JOURNAL_LOG_RATELIMIT, "%s: Unclean shutdown, rotating.", f->path);
                 return true;
 
         case -EPROTONOSUPPORT: /* Unsupported feature           */
-                log_ratelimit_info(JOURNALD_LOG_RATELIMIT, "%s: Unsupported feature, rotating.", f->path);
+                log_ratelimit_info(JOURNAL_LOG_RATELIMIT, "%s: Unsupported feature, rotating.", f->path);
                 return true;
 
         case -EBADMSG:         /* Corrupted                     */
         case -ENODATA:         /* Truncated                     */
         case -ESHUTDOWN:       /* Already archived              */
-                log_ratelimit_warning(JOURNALD_LOG_RATELIMIT, "%s: Journal file corrupted, rotating.", f->path);
+                log_ratelimit_warning(JOURNAL_LOG_RATELIMIT, "%s: Journal file corrupted, rotating.", f->path);
                 return true;
 
         case -EIDRM:           /* Journal file has been deleted */
-                log_ratelimit_warning(JOURNALD_LOG_RATELIMIT, "%s: Journal file has been deleted, rotating.", f->path);
+                log_ratelimit_warning(JOURNAL_LOG_RATELIMIT, "%s: Journal file has been deleted, rotating.", f->path);
                 return true;
 
         case -ETXTBSY:         /* Journal file is from the future */
-                log_ratelimit_warning(JOURNALD_LOG_RATELIMIT, "%s: Journal file is from the future, rotating.", f->path);
+                log_ratelimit_warning(JOURNAL_LOG_RATELIMIT, "%s: Journal file is from the future, rotating.", f->path);
                 return true;
 
         case -EAFNOSUPPORT:
-                log_ratelimit_warning(JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning(JOURNAL_LOG_RATELIMIT,
                                       "%s: underlying file system does not support memory mapping or another required file system feature.",
                                       f->path);
                 return false;
@@ -864,7 +864,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, size_t n
                  * to ensure that the entries in the journal files are strictly ordered by time, in order to ensure
                  * bisection works correctly. */
 
-                log_ratelimit_info(JOURNALD_LOG_RATELIMIT, "Time jumped backwards, rotating.");
+                log_ratelimit_info(JOURNAL_LOG_RATELIMIT, "Time jumped backwards, rotating.");
                 rotate = true;
         } else {
 
@@ -873,7 +873,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, size_t n
                         return;
 
                 if (journal_file_rotate_suggested(f->file, s->max_file_usec, LOG_INFO)) {
-                        log_ratelimit_info(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_info(JOURNAL_LOG_RATELIMIT,
                                            "%s: Journal header limits reached or header out-of-date, rotating.",
                                            f->file->path);
                         rotate = true;
@@ -1212,7 +1212,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
 
         r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY);
         if (r < 0)
-                return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT,
+                return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                                  "Failed to read runtime journal: %m");
 
         sd_journal_set_data_threshold(j, 0);
@@ -1228,7 +1228,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
 
                 r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
                 if (r < 0) {
-                        log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT, "Can't read entry: %m");
+                        log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Can't read entry: %m");
                         goto finish;
                 }
 
@@ -1237,17 +1237,17 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
                         continue;
 
                 if (!shall_try_append_again(s->system_journal->file, r)) {
-                        log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT, "Can't write entry: %m");
+                        log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Can't write entry: %m");
                         goto finish;
                 }
 
-                log_ratelimit_info(JOURNALD_LOG_RATELIMIT, "Rotating system journal.");
+                log_ratelimit_info(JOURNAL_LOG_RATELIMIT, "Rotating system journal.");
 
                 server_rotate(s);
                 server_vacuum(s, false);
 
                 if (!s->system_journal) {
-                        log_ratelimit_notice(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_notice(JOURNAL_LOG_RATELIMIT,
                                              "Didn't flush runtime journal since rotation of system journal wasn't successful.");
                         r = -EIO;
                         goto finish;
@@ -1256,7 +1256,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
                 log_debug("Retrying write.");
                 r = journal_file_copy_entry(f, s->system_journal->file, o, f->current_offset);
                 if (r < 0) {
-                        log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT, "Can't write entry: %m");
+                        log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Can't write entry: %m");
                         goto finish;
                 }
         }
@@ -1284,7 +1284,7 @@ finish:
         fn = strjoina(s->runtime_directory, "/flushed");
         k = touch(fn);
         if (k < 0)
-                log_ratelimit_warning_errno(k, JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning_errno(k, JOURNAL_LOG_RATELIMIT,
                                             "Failed to touch %s, ignoring: %m", fn);
 
         server_refresh_idle_timer(s);
@@ -1314,7 +1314,7 @@ static int server_relinquish_var(Server *s) {
 
         fn = strjoina(s->runtime_directory, "/flushed");
         if (unlink(fn) < 0 && errno != ENOENT)
-                log_ratelimit_warning_errno(errno, JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning_errno(errno, JOURNAL_LOG_RATELIMIT,
                                             "Failed to unlink %s, ignoring: %m", fn);
 
         server_refresh_idle_timer(s);
@@ -1387,11 +1387,11 @@ int server_process_datagram(
                 if (ERRNO_IS_TRANSIENT(n))
                         return 0;
                 if (n == -EXFULL) {
-                        log_ratelimit_warning(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning(JOURNAL_LOG_RATELIMIT,
                                               "Got message with truncated control data (too many fds sent?), ignoring.");
                         return 0;
                 }
-                return log_ratelimit_error_errno(n, JOURNALD_LOG_RATELIMIT, "recvmsg() failed: %m");
+                return log_ratelimit_error_errno(n, JOURNAL_LOG_RATELIMIT, "recvmsg() failed: %m");
         }
 
         CMSG_FOREACH(cmsg, &msghdr)
@@ -1424,7 +1424,7 @@ int server_process_datagram(
                 if (n > 0 && n_fds == 0)
                         server_process_syslog_message(s, s->buffer, n, ucred, tv, label, label_len);
                 else if (n_fds > 0)
-                        log_ratelimit_warning(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning(JOURNAL_LOG_RATELIMIT,
                                               "Got file descriptors via syslog socket. Ignoring.");
 
         } else if (fd == s->native_fd) {
@@ -1433,7 +1433,7 @@ int server_process_datagram(
                 else if (n == 0 && n_fds == 1)
                         server_process_native_file(s, fds[0], ucred, tv, label, label_len);
                 else if (n_fds > 0)
-                        log_ratelimit_warning(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning(JOURNAL_LOG_RATELIMIT,
                                               "Got too many file descriptors via native socket. Ignoring.");
 
         } else {
@@ -1442,7 +1442,7 @@ int server_process_datagram(
                 if (n > 0 && n_fds == 0)
                         server_process_audit_message(s, s->buffer, n, ucred, &sa, msghdr.msg_namelen);
                 else if (n_fds > 0)
-                        log_ratelimit_warning(JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning(JOURNAL_LOG_RATELIMIT,
                                               "Got file descriptors via audit socket. Ignoring.");
         }
 
@@ -1496,7 +1496,7 @@ static void server_full_rotate(Server *s) {
         fn = strjoina(s->runtime_directory, "/rotated");
         r = write_timestamp_file_atomic(fn, now(CLOCK_MONOTONIC));
         if (r < 0)
-                log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                             "Failed to write %s, ignoring: %m", fn);
 }
 
@@ -1600,7 +1600,7 @@ static void server_full_sync(Server *s) {
         fn = strjoina(s->runtime_directory, "/synced");
         r = write_timestamp_file_atomic(fn, now(CLOCK_MONOTONIC));
         if (r < 0)
-                log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                             "Failed to write %s, ignoring: %m", fn);
 
         return;
index fb512dcfeb7664906f3c19464053145848a014b7..ee8f37419088c2e7e9c99e29ba078ec28b4923d5 100644 (file)
@@ -20,8 +20,6 @@ typedef struct Server Server;
 #include "time-util.h"
 #include "varlink.h"
 
-#define JOURNALD_LOG_RATELIMIT ((const RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 })
-
 typedef enum Storage {
         STORAGE_AUTO,
         STORAGE_VOLATILE,
index abfd04683713f42c91ca08665119e74e0acedadf..49f28972ea205edf140b4fde8f7da0744871ea1c 100644 (file)
@@ -19,6 +19,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "io-util.h"
+#include "journal-internal.h"
 #include "journald-console.h"
 #include "journald-context.h"
 #include "journald-kmsg.h"
@@ -160,7 +161,7 @@ static int stdout_stream_save(StdoutStream *s) {
 
                 r = fstat(s->fd, &st);
                 if (r < 0)
-                        return log_ratelimit_warning_errno(errno, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_warning_errno(errno, JOURNAL_LOG_RATELIMIT,
                                                            "Failed to stat connected stream: %m");
 
                 /* We use device and inode numbers as identifier for the stream */
@@ -232,7 +233,7 @@ static int stdout_stream_save(StdoutStream *s) {
                 if (s->server->notify_event_source) {
                         r = sd_event_source_set_enabled(s->server->notify_event_source, SD_EVENT_ON);
                         if (r < 0)
-                                log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT, "Failed to enable notify event source: %m");
+                                log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT, "Failed to enable notify event source: %m");
                 }
         }
 
@@ -240,7 +241,7 @@ static int stdout_stream_save(StdoutStream *s) {
 
 fail:
         (void) unlink(s->state_file);
-        return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT,
+        return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
                                          "Failed to save stream data %s: %m", s->state_file);
 }
 
@@ -268,7 +269,7 @@ static int stdout_stream_log(
         else if (pid_is_valid(s->ucred.pid)) {
                 r = client_context_acquire(s->server, s->ucred.pid, &s->ucred, s->label, strlen_ptr(s->label), s->unit_id, &s->context);
                 if (r < 0)
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to acquire client context, ignoring: %m");
         }
 
@@ -366,7 +367,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
 
         /* line breaks by NUL, line max length or EOF are not permissible during the negotiation part of the protocol */
         if (line_break != LINE_BREAK_NEWLINE && s->state != STDOUT_STREAM_RUNNING)
-                return log_ratelimit_warning_errno(SYNTHETIC_ERRNO(EINVAL), JOURNALD_LOG_RATELIMIT,
+                return log_ratelimit_warning_errno(SYNTHETIC_ERRNO(EINVAL), JOURNAL_LOG_RATELIMIT,
                                                    "Control protocol line not properly terminated.");
 
         switch (s->state) {
@@ -398,7 +399,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
 
                 priority = syslog_parse_priority_and_facility(p);
                 if (priority < 0)
-                        return log_ratelimit_warning_errno(priority, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_warning_errno(priority, JOURNAL_LOG_RATELIMIT,
                                                            "Failed to parse log priority line: %m");
 
                 s->priority = priority;
@@ -409,7 +410,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
         case STDOUT_STREAM_LEVEL_PREFIX:
                 r = parse_boolean(p);
                 if (r < 0)
-                        return log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                            "Failed to parse level prefix line: %m");
 
                 s->level_prefix = r;
@@ -419,7 +420,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
         case STDOUT_STREAM_FORWARD_TO_SYSLOG:
                 r = parse_boolean(p);
                 if (r < 0)
-                        return log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                            "Failed to parse forward to syslog line: %m");
 
                 s->forward_to_syslog = r;
@@ -429,7 +430,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
         case STDOUT_STREAM_FORWARD_TO_KMSG:
                 r = parse_boolean(p);
                 if (r < 0)
-                        return log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                            "Failed to parse copy to kmsg line: %m");
 
                 s->forward_to_kmsg = r;
@@ -439,7 +440,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
         case STDOUT_STREAM_FORWARD_TO_CONSOLE:
                 r = parse_boolean(p);
                 if (r < 0)
-                        return log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        return log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                            "Failed to parse copy to console line.");
 
                 s->forward_to_console = r;
@@ -597,7 +598,7 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents,
                 if (ERRNO_IS_TRANSIENT(errno))
                         return 0;
 
-                log_ratelimit_warning_errno(errno, JOURNALD_LOG_RATELIMIT, "Failed to read from stream: %m");
+                log_ratelimit_warning_errno(errno, JOURNAL_LOG_RATELIMIT, "Failed to read from stream: %m");
                 goto terminate;
         }
         cmsg_close_all(&msghdr);
@@ -656,7 +657,7 @@ int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
 
         r = sd_id128_randomize(&id);
         if (r < 0)
-                return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT, "Failed to generate stream ID: %m");
+                return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Failed to generate stream ID: %m");
 
         stream = new(StdoutStream, 1);
         if (!stream)
@@ -672,7 +673,7 @@ int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
 
         r = getpeercred(fd, &stream->ucred);
         if (r < 0)
-                return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT, "Failed to determine peer credentials: %m");
+                return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Failed to determine peer credentials: %m");
 
         r = setsockopt_int(fd, SOL_SOCKET, SO_PASSCRED, true);
         if (r < 0)
@@ -681,18 +682,18 @@ int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
         if (mac_selinux_use()) {
                 r = getpeersec(fd, &stream->label);
                 if (r < 0 && r != -EOPNOTSUPP)
-                        (void) log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT, "Failed to determine peer security context: %m");
+                        (void) log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT, "Failed to determine peer security context: %m");
         }
 
         (void) shutdown(fd, SHUT_WR);
 
         r = sd_event_add_io(s->event, &stream->event_source, fd, EPOLLIN, stdout_stream_process, stream);
         if (r < 0)
-                return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT, "Failed to add stream to event loop: %m");
+                return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Failed to add stream to event loop: %m");
 
         r = sd_event_source_set_priority(stream->event_source, SD_EVENT_PRIORITY_NORMAL+5);
         if (r < 0)
-                return log_ratelimit_error_errno(r, JOURNALD_LOG_RATELIMIT, "Failed to adjust stdout event source priority: %m");
+                return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Failed to adjust stdout event source priority: %m");
 
         stream->fd = fd;
 
@@ -724,7 +725,7 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
                 if (ERRNO_IS_ACCEPT_AGAIN(errno))
                         return 0;
 
-                return log_ratelimit_error_errno(errno, JOURNALD_LOG_RATELIMIT, "Failed to accept stdout connection: %m");
+                return log_ratelimit_error_errno(errno, JOURNAL_LOG_RATELIMIT, "Failed to accept stdout connection: %m");
         }
 
         if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) {
index 6394adfdfdf2291d30b214c92b99f4770b82ff5e..d8708b07755ce98676ecbbfc79d349b11c43ea79 100644 (file)
@@ -10,6 +10,7 @@
 #include "fd-util.h"
 #include "format-util.h"
 #include "io-util.h"
+#include "journal-internal.h"
 #include "journald-console.h"
 #include "journald-kmsg.h"
 #include "journald-server.h"
@@ -334,7 +335,7 @@ void server_process_syslog_message(
         if (ucred && pid_is_valid(ucred->pid)) {
                 r = client_context_get(s, ucred->pid, ucred, label, label_len, NULL, &context);
                 if (r < 0)
-                        log_ratelimit_warning_errno(r, JOURNALD_LOG_RATELIMIT,
+                        log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
                                                     "Failed to retrieve credentials for PID " PID_FMT ", ignoring: %m",
                                                     ucred->pid);
         }
index 9084da41e3648171ad25049d847908b16f7bb380..6fcd1fac07a0b344b08454761d3d914f62874591 100644 (file)
@@ -23,6 +23,7 @@
 #include "journal-authenticate.h"
 #include "journal-def.h"
 #include "journal-file.h"
+#include "journal-internal.h"
 #include "lookup3.h"
 #include "memory-util.h"
 #include "path-util.h"
@@ -4161,10 +4162,6 @@ int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot_id, u
         return 1;
 }
 
-/* Ideally this would be a function parameter but initializers for static fields have to be compile
- * time constants so we hardcode the interval instead. */
-#define LOG_RATELIMIT ((const RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 })
-
 bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log_level) {
         assert(f);
         assert(f->header);
@@ -4183,7 +4180,7 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
         if (JOURNAL_HEADER_CONTAINS(f->header, n_data))
                 if (le64toh(f->header->n_data) * 4ULL > (le64toh(f->header->data_hash_table_size) / sizeof(HashItem)) * 3ULL) {
                         log_ratelimit_full(
-                                log_level, LOG_RATELIMIT,
+                                log_level, JOURNAL_LOG_RATELIMIT,
                                 "Data hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items, %llu file size, %"PRIu64" bytes per hash table item), suggesting rotation.",
                                 f->path,
                                 100.0 * (double) le64toh(f->header->n_data) / ((double) (le64toh(f->header->data_hash_table_size) / sizeof(HashItem))),
@@ -4197,7 +4194,7 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
         if (JOURNAL_HEADER_CONTAINS(f->header, n_fields))
                 if (le64toh(f->header->n_fields) * 4ULL > (le64toh(f->header->field_hash_table_size) / sizeof(HashItem)) * 3ULL) {
                         log_ratelimit_full(
-                                log_level, LOG_RATELIMIT,
+                                log_level, JOURNAL_LOG_RATELIMIT,
                                 "Field hash table of %s has a fill level at %.1f (%"PRIu64" of %"PRIu64" items), suggesting rotation.",
                                 f->path,
                                 100.0 * (double) le64toh(f->header->n_fields) / ((double) (le64toh(f->header->field_hash_table_size) / sizeof(HashItem))),
@@ -4211,7 +4208,7 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
         if (JOURNAL_HEADER_CONTAINS(f->header, data_hash_chain_depth) &&
             le64toh(f->header->data_hash_chain_depth) > HASH_CHAIN_DEPTH_MAX) {
                 log_ratelimit_full(
-                        log_level, LOG_RATELIMIT,
+                        log_level, JOURNAL_LOG_RATELIMIT,
                         "Data hash table of %s has deepest hash chain of length %" PRIu64 ", suggesting rotation.",
                         f->path, le64toh(f->header->data_hash_chain_depth));
                 return true;
@@ -4220,7 +4217,7 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
         if (JOURNAL_HEADER_CONTAINS(f->header, field_hash_chain_depth) &&
             le64toh(f->header->field_hash_chain_depth) > HASH_CHAIN_DEPTH_MAX) {
                 log_ratelimit_full(
-                        log_level, LOG_RATELIMIT,
+                        log_level, JOURNAL_LOG_RATELIMIT,
                         "Field hash table of %s has deepest hash chain of length at %" PRIu64 ", suggesting rotation.",
                         f->path, le64toh(f->header->field_hash_chain_depth));
                 return true;
@@ -4232,7 +4229,7 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
             le64toh(f->header->n_data) > 0 &&
             le64toh(f->header->n_fields) == 0) {
                 log_ratelimit_full(
-                        log_level, LOG_RATELIMIT,
+                        log_level, JOURNAL_LOG_RATELIMIT,
                         "Data objects of %s are not indexed by field objects, suggesting rotation.",
                         f->path);
                 return true;
@@ -4246,7 +4243,7 @@ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log
 
                 if (h > 0 && t > h + max_file_usec) {
                         log_ratelimit_full(
-                                log_level, LOG_RATELIMIT,
+                                log_level, JOURNAL_LOG_RATELIMIT,
                                 "Oldest entry in %s is older than the configured file retention duration (%s), suggesting rotation.",
                                 f->path, FORMAT_TIMESPAN(max_file_usec, USEC_PER_SEC));
                         return true;
index 7fc6896522e27df3c73cd52251ba83032b3af1e3..ed052d1b890de82277e6802dcf509afba658be7c 100644 (file)
@@ -14,6 +14,8 @@
 #include "list.h"
 #include "set.h"
 
+#define JOURNAL_LOG_RATELIMIT ((const RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 })
+
 typedef struct Match Match;
 typedef struct Location Location;
 typedef struct Directory Directory;