journald,core: add short comments we we keep reopening /dev/console all the time
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Oct 2016 21:30:50 +0000 (23:30 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 20 Oct 2016 11:12:53 +0000 (13:12 +0200)
Just to make sure the next one reading this isn't surprised that the fd isn't
kept open. SAK and stuff...

Fix suggested:

https://github.com/systemd/systemd/pull/4366#issuecomment-253659162

src/core/show-status.c
src/journal/journald-console.c

index 59ebdc7..65f9cb8 100644 (file)
@@ -61,6 +61,11 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
         if (vasprintf(&s, format, ap) < 0)
                 return log_oom();
 
+        /* Before you ask: yes, on purpose we open/close the console for each status line we write individually. This
+         * is a good strategy to avoid PID 1 getting killed by the kernel's SAK concept (it doesn't fix this entirely,
+         * but minimizes the time window the kernel might end up killing PID 1 due to SAK). It also makes things easier
+         * for us so that we don't have to recover from hangups and suchlike triggered on the console. */
+
         fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
         if (fd < 0)
                 return fd;
index fcc9f25..3a9fba4 100644 (file)
@@ -102,6 +102,11 @@ void server_forward_console(
 
         tty = s->tty_path ? s->tty_path : "/dev/console";
 
+        /* Before you ask: yes, on purpose we open/close the console for each log line we write individually. This is a
+         * good strategy to avoid journald getting killed by the kernel's SAK concept (it doesn't fix this entirely,
+         * but minimizes the time window the kernel might end up killing journald due to SAK). It also makes things
+         * easier for us so that we don't have to recover from hangups and suchlike triggered on the console. */
+
         fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
         if (fd < 0) {
                 log_debug_errno(fd, "Failed to open %s for logging: %m", tty);