diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-05-22 16:52:50 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-05-22 16:52:50 +0200 |
commit | 17cac366ae5f31d07fc245bef702e6ec953e4cab (patch) | |
tree | 1c9a65e5156702937169c8f332936bac142dafdd /src/nspawn | |
parent | 8ca082b49ac816457dc258c297a96b2f623b152e (diff) | |
download | systemd-17cac366ae5f31d07fc245bef702e6ec953e4cab.tar.gz |
nspawn: make sure our container PID 1 keeps logging to the original stderr as long as possible
If we log to the pty that is configured as stdin/stdout/stderr of the
container too early we risk filling it up in full before we start
processing the pty from the parent process, resulting in deadlocks.
Let's hence keep a copy of the original tty we were started on before
setting up stdin/stdout/stderr, so that we can log to it, and keep using
it as long as we can.
Since the kernel's pty internal buffer is pretty small this actually
triggered deadlocks when we debug logged at lot from nspawn's child
processes, see: https://github.com/systemd/systemd/pull/9024#issuecomment-390403674
With this change we won't use the pty at all, only the actual payload we
start will, and hence we won't deadlock on it, ever.
Diffstat (limited to 'src/nspawn')
-rw-r--r-- | src/nspawn/nspawn.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index b1add0f159..cc1f4c2da0 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2720,6 +2720,11 @@ static int outer_child( if (terminal < 0) return log_error_errno(terminal, "Failed to open console: %m"); + /* Make sure we can continue logging to the original stderr, even if stderr points elsewhere now */ + r = log_dup_console(); + if (r < 0) + return log_error_errno(r, "Failed to duplicate stderr: %m"); + r = rearrange_stdio(terminal, terminal, terminal); /* invalidates 'terminal' on success and failure */ if (r < 0) return log_error_errno(r, "Failed to move console to stdin/stdout/stderr: %m"); |