]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: move handling of --smart-relinquish-var to action logic
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 12 May 2026 12:37:35 +0000 (14:37 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 12 May 2026 13:29:51 +0000 (15:29 +0200)
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.

src/journal/journalctl-varlink.c
src/journal/journalctl.c
src/journal/journalctl.h

index c278bc3365724405254c859917d131a9612005a6..a38c320a4f8686906c60e99cdd586cbff161d452 100644 (file)
@@ -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),
index a48e28497d3a6fde94c13dedb23ad15ecf9fab9f..c5009eb6f05605267c50d95808733450c2a2cc90 100644 (file)
@@ -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();
 
index 090e3382496cab370de65662e2fd5cbc63dccda6..406a16077be0f714ebd2e1f8829566cc9dbdaed9 100644 (file)
@@ -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,