summaryrefslogtreecommitdiff
path: root/src/basic/log.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-05-22 16:52:50 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commit6eaca9fa182ca675a93cbc30a814770865bef35c (patch)
tree3aea472e7335fbd9e20d2800b1347bed9c12d5f5 /src/basic/log.c
parent80861dbf7898213688d56fff36ee0db6ed95a07a (diff)
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/basic/log.c')
-rw-r--r--src/basic/log.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/basic/log.c b/src/basic/log.c
index ed02a4b90..6fe3a8fb1 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -1354,3 +1354,20 @@ int log_emergency_level(void) {
return getpid_cached() == 1 ? LOG_EMERG : LOG_ERR;
}
+
+int log_dup_console(void) {
+ int copy;
+
+ /* Duplicate the fd we use for fd logging if it's < 3 and use the copy from now on. This call is useful
+ * whenever we want to continue logging through the original fd, but want to rearrange stderr. */
+
+ if (console_fd >= 3)
+ return 0;
+
+ copy = fcntl(console_fd, F_DUPFD_CLOEXEC, 3);
+ if (copy < 0)
+ return -errno;
+
+ console_fd = copy;
+ return 0;
+}