From: Lennart Poettering Date: Fri, 19 Jan 2024 22:41:01 +0000 (+0100) Subject: nspawn: optionally tint the background color of a container X-Git-Tag: v256-rc1~1061^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d8ba7b83f254ec9e137210630a602001674e4d0;p=thirdparty%2Fsystemd.git nspawn: optionally tint the background color of a container --- diff --git a/man/systemd-nspawn.xml b/man/systemd-nspawn.xml index 1a9fb09aaea..59b2c1a2d0b 100644 --- a/man/systemd-nspawn.xml +++ b/man/systemd-nspawn.xml @@ -1711,6 +1711,21 @@ After=sys-subsystem-net-devices-ens1.device + + + + + Change the terminal background color to the specified ANSI color as long as the + container runs. The color specified should be an ANSI X3.64 SGR background color, i.e. strings such + as 40, 41, …, 47, 48;2;…, + 48;5;…. See ANSI + Escape Code (Wikipedia) for details. Assign an empty string to disable any coloring. + + + + + diff --git a/shell-completion/bash/systemd-nspawn b/shell-completion/bash/systemd-nspawn index cc3d2f6598a..b12711be804 100644 --- a/shell-completion/bash/systemd-nspawn +++ b/shell-completion/bash/systemd-nspawn @@ -73,7 +73,7 @@ _systemd_nspawn() { --pivot-root --property --private-users --private-users-ownership --network-namespace-path --network-ipvlan --network-veth-extra --network-zone -p --port --system-call-filter --overlay --overlay-ro --settings --rlimit --hostname --no-new-privileges --oom-score-adjust --cpu-affinity - --resolv-conf --timezone --root-hash-sig' + --resolv-conf --timezone --root-hash-sig --background' ) _init_completion || return diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 89ef0e4daaa..5820be8d136 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -236,6 +236,7 @@ static bool arg_suppress_sync = false; static char *arg_settings_filename = NULL; static Architecture arg_architecture = _ARCHITECTURE_INVALID; static ImagePolicy *arg_image_policy = NULL; +static char *arg_background = NULL; STATIC_DESTRUCTOR_REGISTER(arg_directory, freep); STATIC_DESTRUCTOR_REGISTER(arg_template, freep); @@ -272,6 +273,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_sysctl, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_bind_user, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_settings_filename, freep); 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")) { @@ -450,6 +452,7 @@ static int help(void) { " --console=MODE Select how stdin/stdout/stderr and /dev/console are\n" " set up for the container.\n" " -P --pipe Equivalent to --console=pipe\n\n" + " --background=COLOR Set ANSI color for background\n" "%3$sCredentials:%4$s\n" " --set-credential=ID:VALUE\n" " Pass a credential with literal value to container.\n" @@ -745,6 +748,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_BIND_USER, ARG_SUPPRESS_SYNC, ARG_IMAGE_POLICY, + ARG_BACKGROUND, }; static const struct option options[] = { @@ -819,6 +823,7 @@ static int parse_argv(int argc, char *argv[]) { { "bind-user", required_argument, NULL, ARG_BIND_USER }, { "suppress-sync", required_argument, NULL, ARG_SUPPRESS_SYNC }, { "image-policy", required_argument, NULL, ARG_IMAGE_POLICY }, + { "background", required_argument, NULL, ARG_BACKGROUND }, {} }; @@ -1608,6 +1613,12 @@ static int parse_argv(int argc, char *argv[]) { return r; break; + case ARG_BACKGROUND: + r = free_and_strdup_warn(&arg_background, optarg); + if (r < 0) + return r; + break; + case '?': return -EINVAL; @@ -5339,9 +5350,14 @@ static int run_container( return log_error_errno(r, "Failed to create PTY forwarder: %m"); if (arg_console_width != UINT_MAX || arg_console_height != UINT_MAX) - (void) pty_forward_set_width_height(forward, - arg_console_width, - arg_console_height); + (void) pty_forward_set_width_height( + forward, + arg_console_width, + arg_console_height); + + if (!isempty(arg_background)) + (void) pty_forward_set_background_color(forward, arg_background); + break; default: