From 2627c8e79e23252dc786acb7b3eb6a54a2b7aef5 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 13 May 2025 22:54:10 +0200 Subject: [PATCH 1/5] journal: do not clear individual fields if the struct won't be reused Especially that only some of the fields are cleared currently. --- src/journal/journalctl-show.c | 4 ++-- src/journal/journald-sync.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/journal/journalctl-show.c b/src/journal/journalctl-show.c index d4a7c730c5..f2b43a7f3e 100644 --- a/src/journal/journalctl-show.c +++ b/src/journal/journalctl-show.c @@ -35,8 +35,8 @@ typedef struct Context { static void context_done(Context *c) { assert(c); - c->synchronize_varlink = sd_varlink_flush_close_unref(c->synchronize_varlink); - c->event = sd_event_unref(c->event); + sd_varlink_flush_close_unref(c->synchronize_varlink); + sd_event_unref(c->event); sd_journal_close(c->journal); } diff --git a/src/journal/journald-sync.c b/src/journal/journald-sync.c index c3b8de7412..e3b28f77f0 100644 --- a/src/journal/journald-sync.c +++ b/src/journal/journald-sync.c @@ -138,7 +138,7 @@ SyncReq* sync_req_free(SyncReq *req) { LIST_REMOVE(pending_rqlen, req->server->sync_req_pending_rqlen, req); } - req->idle_event_source = sd_event_source_disable_unref(req->idle_event_source); + sd_event_source_disable_unref(req->idle_event_source); sd_varlink_unref(req->link); From df3c049fa52f3c9183ebfdebfc33330025b6793c Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 13 May 2025 22:55:15 +0200 Subject: [PATCH 2/5] journalctl-show: check Context.has_cursor rather than arg_* --- src/journal/journalctl-show.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/journal/journalctl-show.c b/src/journal/journalctl-show.c index f2b43a7f3e..20b39da62d 100644 --- a/src/journal/journalctl-show.c +++ b/src/journal/journalctl-show.c @@ -313,7 +313,7 @@ static int on_first_event(sd_event_source *s, void *userdata) { if (r < 0) return r; - if (arg_follow && !arg_reverse && !arg_cursor && !arg_after_cursor && !arg_cursor_file && !arg_since_set) { + if (arg_follow && !arg_reverse && !c->has_cursor && !arg_since_set) { r = sd_journal_get_cursor(c->journal, /* ret_cursor= */ NULL); if (r == -EADDRNOTAVAIL) { /* If we shall operate in --follow mode, and we are unable to get a cursor after From c49c2477a441cc36904bec51926d05093ce398c6 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 13 May 2025 22:56:02 +0200 Subject: [PATCH 3/5] journalctl-show: report VARLINKERROR= Who knows, maybe one day we'd support spawning journalctl as varlink socket-activatable service, where this bit of info would help. --- src/journal/journalctl-show.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/journal/journalctl-show.c b/src/journal/journalctl-show.c index 20b39da62d..eac93b222d 100644 --- a/src/journal/journalctl-show.c +++ b/src/journal/journalctl-show.c @@ -350,8 +350,10 @@ static int on_synchronize_reply( assert(vl); - if (error_id) + if (error_id) { log_warning("Failed to synchronize on Journal, ignoring: %s", error_id); + (void) sd_notifyf(/* unset_environment= */ false, "VARLINKERROR=%s", error_id); + } r = show_and_fflush(c); if (r < 0) @@ -377,7 +379,7 @@ static int on_signal(sd_event_source *s, const struct signalfd_siginfo *si, void r = varlink_connect_journal(&vl); if (r < 0) { - log_error_errno(r, "Failed to connect to Journal Varlink IPC interface, ignoring: %m"); + log_error_errno(r, "Failed to connect to Journal Varlink IPC interface, skipping synchronization: %m"); goto finish; } From b86b1ca22f6b9d2ca7ea79be539911ff4e7d76a8 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 13 May 2025 22:58:02 +0200 Subject: [PATCH 4/5] fork-journal: use char* const* for strv input param This is compatible with char** and is what I originally asked for in https://github.com/systemd/systemd/pull/36858#discussion_r2086792739 Someone needs to read better ;-) --- src/run/run.c | 2 +- src/shared/fork-journal.c | 4 ++-- src/shared/fork-journal.h | 2 +- src/systemctl/systemctl-start-unit.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index 4005d26d45..876e436a5d 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -2438,7 +2438,7 @@ static int start_transient_service(sd_bus *bus) { _cleanup_(journal_terminate) PidRef journal_pid = PIDREF_NULL; if (arg_verbose) - (void) journal_fork(arg_runtime_scope, (const char**) STRV_MAKE(c.unit), &journal_pid); + (void) journal_fork(arg_runtime_scope, STRV_MAKE(c.unit), &journal_pid); r = bus_call_with_hint(bus, m, "service", &reply); if (r < 0) diff --git a/src/shared/fork-journal.c b/src/shared/fork-journal.c index ccefc74df0..8972476e7c 100644 --- a/src/shared/fork-journal.c +++ b/src/shared/fork-journal.c @@ -87,7 +87,7 @@ static int on_child_notify(sd_event_source *s, int fd, uint32_t revents, void *u return 0; } -int journal_fork(RuntimeScope scope, const char * const *units, PidRef *ret_pidref) { +int journal_fork(RuntimeScope scope, char * const *units, PidRef *ret_pidref) { int r; assert(scope >= 0); @@ -97,7 +97,7 @@ int journal_fork(RuntimeScope scope, const char * const *units, PidRef *ret_pidr if (!is_main_thread()) return -EPERM; - if (strv_isempty((char**) units)) + if (strv_isempty(units)) return 0; _cleanup_(sd_event_unrefp) sd_event *event = NULL; diff --git a/src/shared/fork-journal.h b/src/shared/fork-journal.h index c7ff87b8f7..1825a7f5eb 100644 --- a/src/shared/fork-journal.h +++ b/src/shared/fork-journal.h @@ -6,6 +6,6 @@ #include "runtime-scope.h" #include "set.h" -int journal_fork(RuntimeScope scope, const char * const *units, PidRef *ret_pidref); +int journal_fork(RuntimeScope scope, char * const *units, PidRef *ret_pidref); void journal_terminate(PidRef *pidref); diff --git a/src/systemctl/systemctl-start-unit.c b/src/systemctl/systemctl-start-unit.c index 7e81afae00..1cb2a6db46 100644 --- a/src/systemctl/systemctl-start-unit.c +++ b/src/systemctl/systemctl-start-unit.c @@ -394,7 +394,7 @@ int verb_start(int argc, char *argv[], void *userdata) { ret = enqueue_marked_jobs(bus, w); else { if (arg_verbose) - (void) journal_fork(arg_runtime_scope, (const char**) names, &journal_pid); + (void) journal_fork(arg_runtime_scope, names, &journal_pid); STRV_FOREACH(name, names) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; From 38e3f79d52b1f6dae49b1c2edc142a977a82714d Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 13 May 2025 23:07:17 +0200 Subject: [PATCH 5/5] fork-journal: drop unneeded cast --- src/shared/fork-journal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/fork-journal.c b/src/shared/fork-journal.c index 8972476e7c..883d9b5195 100644 --- a/src/shared/fork-journal.c +++ b/src/shared/fork-journal.c @@ -162,7 +162,7 @@ int journal_fork(RuntimeScope scope, char * const *units, PidRef *ret_pidref) { _exit(EXIT_MEMORY); } - r = invoke_callout_binary(argv[0], (char**) argv); + r = invoke_callout_binary(argv[0], argv); log_debug_errno(r, "Failed to invoke journalctl: %m"); _exit(EXIT_EXEC); }