From: Zbigniew Jędrzejewski-Szmek Date: Tue, 12 May 2026 12:37:35 +0000 (+0200) Subject: journalctl: move handling of --smart-relinquish-var to action logic X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1955c18a18b2822b35b3ab37bb868fff05f33fa6;p=thirdparty%2Fsystemd.git journalctl: move handling of --smart-relinquish-var to action logic The help string for --smart-relinquish-var and --relinquish-var were in reversed order because of the _fallthrough_. We would resolve the conditions for "smart relinquish" immediately in parse_argv() and call 'return 0' if the conditions were wrong, terminating option parsing and the program. It seems nicer to delay action until later. This makes the logic flow more standard. This also allows the option parsing cases to be exchanged, fixing the issue with --help. --- diff --git a/src/journal/journalctl-varlink.c b/src/journal/journalctl-varlink.c index c278bc33657..a38c320a4f8 100644 --- a/src/journal/journalctl-varlink.c +++ b/src/journal/journalctl-varlink.c @@ -65,7 +65,7 @@ int action_relinquish_var(void) { _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *link = NULL; int r; - assert(arg_action == ACTION_RELINQUISH_VAR); + assert(IN_SET(arg_action, ACTION_RELINQUISH_VAR, ACTION_SMART_RELINQUISH_VAR)); if (arg_machine || arg_namespace) return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index a48e28497d3..c5009eb6f05 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -835,36 +835,15 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) { arg_action = ACTION_SYNC; break; - OPTION_LONG("smart-relinquish-var", NULL, - "Similar, but NOP if log directory is on root mount"): { - int root_mnt_id, log_mnt_id; - - /* Try to be smart about relinquishing access to /var/log/journal/ during shutdown: - * if it's on the same mount as the root file system there's no point in - * relinquishing access and we can leave journald write to it until the very last - * moment. */ - - r = path_get_mnt_id("/", &root_mnt_id); - if (r < 0) - log_debug_errno(r, "Failed to get root mount ID, ignoring: %m"); - else { - r = path_get_mnt_id("/var/log/journal/", &log_mnt_id); - if (r < 0) - log_debug_errno(r, "Failed to get journal directory mount ID, ignoring: %m"); - else if (root_mnt_id == log_mnt_id) { - log_debug("/var/log/journal/ is on root file system, not relinquishing access to /var."); - return 0; - } else - log_debug("/var/log/journal/ is not on the root file system, relinquishing access to it."); - } - - _fallthrough_; - } - OPTION_LONG("relinquish-var", NULL, "Stop logging to disk, log to temporary file system"): arg_action = ACTION_RELINQUISH_VAR; break; + OPTION_LONG("smart-relinquish-var", NULL, + "Similar, but NOP if log directory is on root mount"): + arg_action = ACTION_SMART_RELINQUISH_VAR; + break; + OPTION_LONG("flush", NULL, "Flush all journal data from /run into /var"): arg_action = ACTION_FLUSH; break; @@ -1075,6 +1054,31 @@ static int run(int argc, char *argv[]) { case ACTION_FLUSH: return action_flush_to_var(); + case ACTION_SMART_RELINQUISH_VAR: { + int root_mnt_id, log_mnt_id; + + /* Try to be smart about relinquishing access to /var/log/journal/ during shutdown: + * if it's on the same mount as the root file system there's no point in + * relinquishing access and we can leave journald write to it until the very last + * moment. */ + + r = path_get_mnt_id("/", &root_mnt_id); + if (r < 0) + log_debug_errno(r, "Failed to get root mount ID, ignoring: %m"); + else { + r = path_get_mnt_id("/var/log/journal/", &log_mnt_id); + if (r < 0) + log_debug_errno(r, "Failed to get journal directory mount ID, ignoring: %m"); + else if (root_mnt_id == log_mnt_id) { + log_debug("/var/log/journal/ is on root file system, not relinquishing access to /var."); + return 0; + } else + log_debug("/var/log/journal/ is not on the root file system, relinquishing access to it."); + } + + _fallthrough_; + } + case ACTION_RELINQUISH_VAR: return action_relinquish_var(); diff --git a/src/journal/journalctl.h b/src/journal/journalctl.h index 090e3382496..406a16077be 100644 --- a/src/journal/journalctl.h +++ b/src/journal/journalctl.h @@ -21,6 +21,7 @@ typedef enum JournalctlAction { ACTION_LIST_NAMESPACES, ACTION_FLUSH, ACTION_RELINQUISH_VAR, + ACTION_SMART_RELINQUISH_VAR, ACTION_SYNC, ACTION_ROTATE, ACTION_VACUUM,