]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: postpone selection of console mode
authorDavid Tardon <dtardon@redhat.com>
Wed, 1 Oct 2025 17:07:53 +0000 (19:07 +0200)
committerDavid Tardon <dtardon@redhat.com>
Thu, 2 Oct 2025 14:19:03 +0000 (16:19 +0200)
Moving it away from argument parsing code allows to simplify that.

src/nspawn/nspawn-settings.c
src/nspawn/nspawn-settings.h
src/nspawn/nspawn.c

index 47c1a30f1f29d4804b06ec5db6a564dff58d239e..c058ab28f71deb4e9abbac39d814ac3a442e224f 100644 (file)
@@ -915,6 +915,7 @@ static const char *const timezone_mode_table[_TIMEZONE_MODE_MAX] = {
 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(timezone_mode, TimezoneMode, TIMEZONE_AUTO);
 
 static const char *const console_mode_table[_CONSOLE_MODE_MAX] = {
+        [CONSOLE_AUTOPIPE]    = "autopipe",
         [CONSOLE_INTERACTIVE] = "interactive",
         [CONSOLE_READ_ONLY]   = "read-only",
         [CONSOLE_PASSIVE]     = "passive",
index 874e168664fa21fcb1ee5e802b0ad09f96619675..5b36c2ad473e5a02e8c83acf9ad87373011c44ce 100644 (file)
@@ -82,6 +82,7 @@ typedef enum TimezoneMode {
 } TimezoneMode;
 
 typedef enum ConsoleMode {
+        CONSOLE_AUTOPIPE,
         CONSOLE_INTERACTIVE,
         CONSOLE_READ_ONLY,
         CONSOLE_PASSIVE,
index c980b1f5631ce0e3be527d59715357883e058672..25af8520e23158501b4fca5e1d94bcc1e201779a 100644 (file)
@@ -287,18 +287,10 @@ STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_background, freep);
 
 static int handle_arg_console(const char *arg) {
-        if (streq(arg, "help")) {
-                puts("autopipe\n");
+        if (streq(arg, "help"))
                 return DUMP_STRING_TABLE(console_mode, ConsoleMode, _CONSOLE_MODE_MAX);
-        }
 
-        if (streq(arg, "autopipe")) {
-                if (isatty_safe(STDIN_FILENO) && isatty_safe(STDOUT_FILENO))
-                        arg_console_mode = CONSOLE_INTERACTIVE;
-                else
-                        arg_console_mode = CONSOLE_PIPE;
-        } else
-                arg_console_mode = console_mode_from_string(optarg);
+        arg_console_mode = console_mode_from_string(optarg);
         if (arg_console_mode < 0)
                 return log_error_errno(arg_console_mode, "Unknown console mode: %s", optarg);
 
@@ -5973,6 +5965,13 @@ static int run(int argc, char *argv[]) {
                 arg_console_mode = isatty_safe(STDIN_FILENO) && isatty_safe(STDOUT_FILENO) ?
                                    CONSOLE_INTERACTIVE : CONSOLE_READ_ONLY;
 
+        if (arg_console_mode == CONSOLE_AUTOPIPE) {
+                if (isatty_safe(STDIN_FILENO) && isatty_safe(STDOUT_FILENO))
+                        arg_console_mode = CONSOLE_INTERACTIVE;
+                else
+                        arg_console_mode = CONSOLE_PIPE;
+        }
+
         if (arg_console_mode == CONSOLE_PIPE) /* if we pass STDERR on to the container, don't add our own logs into it too */
                 arg_quiet = true;