nspawn: add --console=autopipe mode
By default we'll run a container in --console=interactive and --console=read-only mode depending if we are invoked on a tty or not so that the container always gets a /dev/console allocated, i.e is always suitable to run a full init system /as those typically expect a /dev/console to exist). With the new --console=autopipe mode we do something similar, but slightly different: when not invoked on a tty we'll use --console=pipe. This means, if you invoke some tool in a container with this you'll get full inetractivity if you invoke it on a tty but things will also be very nicely pipeable. OTOH you cannot invoke a full init system like this, because you might or might not become a /dev/console this way... Prompted-by: #17070 (I named this "autopipe" rather than "auto" or so, since the default mode probably should be named "auto" one day if we add a name for it, and this is so similar to "auto" except that it uses pipes in the non-tty case).
This commit is contained in:
parent
335d2eadca
commit
10e8a60baa
|
@ -1370,15 +1370,18 @@
|
||||||
|
|
||||||
<listitem><para>Configures how to set up standard input, output and error output for the container
|
<listitem><para>Configures how to set up standard input, output and error output for the container
|
||||||
payload, as well as the <filename>/dev/console</filename> device for the container. Takes one of
|
payload, as well as the <filename>/dev/console</filename> device for the container. Takes one of
|
||||||
<option>interactive</option>, <option>read-only</option>, <option>passive</option>, or
|
<option>interactive</option>, <option>read-only</option>, <option>passive</option>,
|
||||||
<option>pipe</option>. If <option>interactive</option>, a pseudo-TTY is allocated and made available
|
<option>pipe</option> or <option>autopipe</option>. If <option>interactive</option>, a pseudo-TTY is
|
||||||
as <filename>/dev/console</filename> in the container. It is then bi-directionally connected to the
|
allocated and made available as <filename>/dev/console</filename> in the container. It is then
|
||||||
standard input and output passed to <command>systemd-nspawn</command>. <option>read-only</option> is
|
bi-directionally connected to the standard input and output passed to
|
||||||
similar but only the output of the container is propagated and no input from the caller is read. If
|
<command>systemd-nspawn</command>. <option>read-only</option> is similar but only the output of the
|
||||||
<option>passive</option>, a pseudo TTY is allocated, but it is not connected anywhere. Finally, in
|
container is propagated and no input from the caller is read. If <option>passive</option>, a pseudo
|
||||||
<option>pipe</option> mode no pseudo TTY is allocated, but the standard input, output and error
|
TTY is allocated, but it is not connected anywhere. In <option>pipe</option> mode no pseudo TTY is
|
||||||
output file descriptors passed to <command>systemd-nspawn</command> are passed on — as they are — to
|
allocated, but the standard input, output and error output file descriptors passed to
|
||||||
the container payload, see the following paragraph. Defaults to <option>interactive</option> if
|
<command>systemd-nspawn</command> are passed on — as they are — to the container payload, see the
|
||||||
|
following paragraph. Finally, <option>autopipe</option> mode operates like
|
||||||
|
<option>interactive</option> when <command>systemd-nspawn</command> is invoked on a terminal, and
|
||||||
|
like <option>pipe</option> otherwise. Defaults to <option>interactive</option> if
|
||||||
<command>systemd-nspawn</command> is invoked from a terminal, and <option>read-only</option>
|
<command>systemd-nspawn</command> is invoked from a terminal, and <option>read-only</option>
|
||||||
otherwise.</para>
|
otherwise.</para>
|
||||||
|
|
||||||
|
|
|
@ -256,10 +256,11 @@ STATIC_DESTRUCTOR_REGISTER(arg_sysctl, strv_freep);
|
||||||
|
|
||||||
static int handle_arg_console(const char *arg) {
|
static int handle_arg_console(const char *arg) {
|
||||||
if (streq(arg, "help")) {
|
if (streq(arg, "help")) {
|
||||||
puts("interactive\n"
|
puts("autopipe\n"
|
||||||
"read-only\n"
|
"interactive\n"
|
||||||
"passive\n"
|
"passive\n"
|
||||||
"pipe");
|
"pipe\n"
|
||||||
|
"read-only");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,6 +277,11 @@ static int handle_arg_console(const char *arg) {
|
||||||
"Most likely you want to use 'interactive' console mode for proper interactivity and shell job control. "
|
"Most likely you want to use 'interactive' console mode for proper interactivity and shell job control. "
|
||||||
"Proceeding anyway.");
|
"Proceeding anyway.");
|
||||||
|
|
||||||
|
arg_console_mode = CONSOLE_PIPE;
|
||||||
|
} else if (streq(arg, "autopipe")) {
|
||||||
|
if (isatty(STDIN_FILENO) > 0 && isatty(STDOUT_FILENO) > 0)
|
||||||
|
arg_console_mode = CONSOLE_INTERACTIVE;
|
||||||
|
else
|
||||||
arg_console_mode = CONSOLE_PIPE;
|
arg_console_mode = CONSOLE_PIPE;
|
||||||
} else
|
} else
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown console mode: %s", optarg);
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown console mode: %s", optarg);
|
||||||
|
|
Loading…
Reference in a new issue