mirror of
https://github.com/systemd/systemd
synced 2025-10-05 16:03:15 +02:00
nspawn: use table to parse --console=
This commit is contained in:
@@ -914,6 +914,15 @@ 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_INTERACTIVE] = "interactive",
|
||||
[CONSOLE_READ_ONLY] = "read-only",
|
||||
[CONSOLE_PASSIVE] = "passive",
|
||||
[CONSOLE_PIPE] = "pipe",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(console_mode, ConsoleMode);
|
||||
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_userns_ownership, user_namespace_ownership, UserNamespaceOwnership);
|
||||
|
||||
static const char *const user_namespace_ownership_table[_USER_NAMESPACE_OWNERSHIP_MAX] = {
|
||||
|
@@ -282,6 +282,9 @@ ResolvConfMode resolv_conf_mode_from_string(const char *s) _pure_;
|
||||
const char* timezone_mode_to_string(TimezoneMode a) _const_;
|
||||
TimezoneMode timezone_mode_from_string(const char *s) _pure_;
|
||||
|
||||
const char* console_mode_to_string(ConsoleMode m) _const_;
|
||||
ConsoleMode console_mode_from_string(const char *s) _pure_;
|
||||
|
||||
const char* user_namespace_ownership_to_string(UserNamespaceOwnership a) _const_;
|
||||
UserNamespaceOwnership user_namespace_ownership_from_string(const char *s) _pure_;
|
||||
|
||||
|
@@ -288,35 +288,19 @@ STATIC_DESTRUCTOR_REGISTER(arg_background, freep);
|
||||
|
||||
static int handle_arg_console(const char *arg) {
|
||||
if (streq(arg, "help")) {
|
||||
puts("autopipe\n"
|
||||
"interactive\n"
|
||||
"passive\n"
|
||||
"pipe\n"
|
||||
"read-only");
|
||||
return 0;
|
||||
puts("autopipe\n");
|
||||
return DUMP_STRING_TABLE(console_mode, ConsoleMode, _CONSOLE_MODE_MAX);
|
||||
}
|
||||
|
||||
if (streq(arg, "interactive"))
|
||||
arg_console_mode = CONSOLE_INTERACTIVE;
|
||||
else if (streq(arg, "read-only"))
|
||||
arg_console_mode = CONSOLE_READ_ONLY;
|
||||
else if (streq(arg, "passive"))
|
||||
arg_console_mode = CONSOLE_PASSIVE;
|
||||
else if (streq(arg, "pipe")) {
|
||||
if (isatty_safe(STDIN_FILENO) && isatty_safe(STDOUT_FILENO))
|
||||
log_full(arg_quiet ? LOG_DEBUG : LOG_NOTICE,
|
||||
"Console mode 'pipe' selected, but standard input/output are connected to an interactive TTY. "
|
||||
"Most likely you want to use 'interactive' console mode for proper interactivity and shell job control. "
|
||||
"Proceeding anyway.");
|
||||
|
||||
arg_console_mode = CONSOLE_PIPE;
|
||||
} else if (streq(arg, "autopipe")) {
|
||||
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
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown console mode: %s", 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);
|
||||
|
||||
arg_settings_mask |= SETTING_CONSOLE_MODE;
|
||||
return 1;
|
||||
@@ -1738,6 +1722,12 @@ static int verify_arguments(void) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (arg_console_mode == CONSOLE_PIPE && isatty_safe(STDIN_FILENO) && isatty_safe(STDOUT_FILENO))
|
||||
log_full(arg_quiet ? LOG_DEBUG : LOG_NOTICE,
|
||||
"Console mode 'pipe' selected, but standard input/output are connected to an interactive TTY. "
|
||||
"Most likely you want to use 'interactive' console mode for proper interactivity and shell job control. "
|
||||
"Proceeding anyway.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user