|
|
17b0f1 |
From 98169577b83b45a40105cf58e6cffe0272074817 Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: Peter Portante <peter.a.portante@gmail.com>
|
|
|
17b0f1 |
Date: Sun, 28 Jan 2018 16:48:04 -0500
|
|
|
17b0f1 |
Subject: [PATCH] journalctl: Periodically call sd_journal_process in
|
|
|
17b0f1 |
journalctl
|
|
|
17b0f1 |
|
|
|
17b0f1 |
If `journalctl` take a long time to process messages, and during that
|
|
|
17b0f1 |
time journal file rotation occurs, a `journalctl` client will keep
|
|
|
17b0f1 |
those rotated files open until it calls `sd_journal_process()`, which
|
|
|
17b0f1 |
typically happens as a result of calling `sd_journal_wait()` below in
|
|
|
17b0f1 |
the "following" case. By periodically calling `sd_journal_process()`
|
|
|
17b0f1 |
during the processing loop we shrink the window of time a client
|
|
|
17b0f1 |
instance has open file descriptors for rotated (deleted) journal
|
|
|
17b0f1 |
files.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
(Lennart: slightly reworked version, that dropped some of the commenting
|
|
|
17b0f1 |
which was solved otherwise)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
(cherry picked from commit ec316d199a13d8db3f6550d60e369893de2fb417)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Related: #1540538
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
src/journal/journalctl.c | 16 ++++++++++++++++
|
|
|
17b0f1 |
1 file changed, 16 insertions(+)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
|
|
|
17b0f1 |
index 0be70764ef..1e6d0761c7 100644
|
|
|
17b0f1 |
--- a/src/journal/journalctl.c
|
|
|
17b0f1 |
+++ b/src/journal/journalctl.c
|
|
|
17b0f1 |
@@ -67,6 +67,8 @@
|
|
|
17b0f1 |
|
|
|
17b0f1 |
#define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+#define PROCESS_INOTIFY_INTERVAL 1024 /* Every 1,024 messages processed */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
enum {
|
|
|
17b0f1 |
/* Special values for arg_lines */
|
|
|
17b0f1 |
ARG_LINES_DEFAULT = -2,
|
|
|
17b0f1 |
@@ -2294,6 +2296,20 @@ int main(int argc, char *argv[]) {
|
|
|
17b0f1 |
goto finish;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
n_shown++;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ /* If journalctl take a long time to process messages, and during that time journal file
|
|
|
17b0f1 |
+ * rotation occurs, a journalctl client will keep those rotated files open until it calls
|
|
|
17b0f1 |
+ * sd_journal_process(), which typically happens as a result of calling sd_journal_wait() below
|
|
|
17b0f1 |
+ * in the "following" case. By periodically calling sd_journal_process() during the processing
|
|
|
17b0f1 |
+ * loop we shrink the window of time a client instance has open file descriptors for rotated
|
|
|
17b0f1 |
+ * (deleted) journal files. */
|
|
|
17b0f1 |
+ if ((n_shown % PROCESS_INOTIFY_INTERVAL) == 0) {
|
|
|
17b0f1 |
+ r = sd_journal_process(j);
|
|
|
17b0f1 |
+ if (r < 0) {
|
|
|
17b0f1 |
+ log_error_errno(r, "Failed to process inotify events: %m");
|
|
|
17b0f1 |
+ goto finish;
|
|
|
17b0f1 |
+ }
|
|
|
17b0f1 |
+ }
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
if (!arg_follow) {
|