]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: also update cursor with --follow
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 May 2023 00:36:27 +0000 (09:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 28 May 2023 05:52:32 +0000 (14:52 +0900)
Fixes #26746.

src/journal/journalctl.c

index 9bfeb121eecb02c0ff84604425e035ccca9c08dd..8944c95e64ff093f1ceabe17183a5eb64050044c 100644 (file)
@@ -65,6 +65,7 @@
 #include "rlimit-util.h"
 #include "set.h"
 #include "sigbus.h"
+#include "signal-util.h"
 #include "static-destruct.h"
 #include "stdio-util.h"
 #include "string-table.h"
@@ -2303,6 +2304,14 @@ static int on_first_event(sd_event_source *s, void *userdata) {
         return show_and_fflush(userdata, s);
 }
 
+static int on_signal(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
+        assert(s);
+        assert(si);
+        assert(IN_SET(si->ssi_signo, SIGTERM, SIGINT));
+
+        return sd_event_exit(sd_event_source_get_event(s), si->ssi_signo);
+}
+
 static int setup_event(Context *c, int fd, sd_event **ret) {
         _cleanup_(sd_event_unrefp) sd_event *e = NULL;
         int r;
@@ -2316,6 +2325,9 @@ static int setup_event(Context *c, int fd, sd_event **ret) {
         if (r < 0)
                 return log_error_errno(r, "Failed to allocate sd_event object: %m");
 
+        (void) sd_event_add_signal(e, NULL, SIGTERM | SD_EVENT_SIGNAL_PROCMASK, on_signal, NULL);
+        (void) sd_event_add_signal(e, NULL, SIGINT | SD_EVENT_SIGNAL_PROCMASK, on_signal, NULL);
+
         r = sd_event_add_io(e, NULL, fd, EPOLLIN, &on_journal_event, c);
         if (r < 0)
                 return log_error_errno(r, "Failed to add io event source for journal: %m");
@@ -2758,6 +2770,7 @@ static int run(int argc, char *argv[]) {
 
         if (arg_follow) {
                 _cleanup_(sd_event_unrefp) sd_event *e = NULL;
+                int sig;
 
                 assert(poll_fd >= 0);
 
@@ -2765,7 +2778,24 @@ static int run(int argc, char *argv[]) {
                 if (r < 0)
                         return r;
 
-                return sd_event_loop(e);
+                r = sd_event_loop(e);
+                if (r < 0)
+                        return r;
+                sig = r;
+
+                /* unref signal event sources. */
+                e = sd_event_unref(e);
+
+                r = update_cursor(j);
+                if (r < 0)
+                        return r;
+
+                /* re-send the original signal. */
+                assert(SIGNAL_VALID(sig));
+                if (raise(sig) < 0)
+                        log_error("Failed to raise the original signal SIG%s, ignoring: %m", signal_to_string(sig));
+
+                return 0;
         }
 
         r = show(&c);