From: Yu Watanabe Date: Thu, 4 May 2023 00:36:27 +0000 (+0900) Subject: journalctl: also update cursor with --follow X-Git-Tag: v254-rc1~337^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24d633e4385d7cd5b8197ecc09876044d7c280e8;p=thirdparty%2Fsystemd.git journalctl: also update cursor with --follow Fixes #26746. --- diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 9bfeb121eec..8944c95e64f 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -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);