From: David Tardon Date: Wed, 1 Oct 2025 17:07:53 +0000 (+0200) Subject: nspawn: postpone selection of console mode X-Git-Tag: v259-rc1~386^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99df84ef23ac46fad32b90961474911b56884fd1;p=thirdparty%2Fsystemd.git nspawn: postpone selection of console mode Moving it away from argument parsing code allows to simplify that. --- diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c index 47c1a30f1f2..c058ab28f71 100644 --- a/src/nspawn/nspawn-settings.c +++ b/src/nspawn/nspawn-settings.c @@ -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", diff --git a/src/nspawn/nspawn-settings.h b/src/nspawn/nspawn-settings.h index 874e168664f..5b36c2ad473 100644 --- a/src/nspawn/nspawn-settings.h +++ b/src/nspawn/nspawn-settings.h @@ -82,6 +82,7 @@ typedef enum TimezoneMode { } TimezoneMode; typedef enum ConsoleMode { + CONSOLE_AUTOPIPE, CONSOLE_INTERACTIVE, CONSOLE_READ_ONLY, CONSOLE_PASSIVE, diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index c980b1f5631..25af8520e23 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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;