richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
65878a
From 87823e84ec7b0e6939596063c540219a681bbbb9 Mon Sep 17 00:00:00 2001
65878a
From: Lennart Poettering <lennart@poettering.net>
65878a
Date: Wed, 18 Dec 2013 16:49:15 +0100
65878a
Subject: [PATCH] log: when we log to /dev/console and got disconnected (maybe
65878a
 due to vhangup) reconnect
65878a
65878a
---
65878a
 src/shared/log.c | 21 +++++++++++++++++++--
65878a
 1 file changed, 19 insertions(+), 2 deletions(-)
65878a
65878a
diff --git a/src/shared/log.c b/src/shared/log.c
65878a
index 8f4995a..605d069 100644
65878a
--- a/src/shared/log.c
65878a
+++ b/src/shared/log.c
65878a
@@ -337,8 +337,25 @@ static int write_to_console(
65878a
                 IOVEC_SET_STRING(iovec[n++], ANSI_HIGHLIGHT_OFF);
65878a
         IOVEC_SET_STRING(iovec[n++], "\n");
65878a
 
65878a
-        if (writev(console_fd, iovec, n) < 0)
65878a
-                return -errno;
65878a
+        if (writev(console_fd, iovec, n) < 0) {
65878a
+
65878a
+                if (errno == EIO && getpid() == 1) {
65878a
+
65878a
+                        /* If somebody tried to kick us from our
65878a
+                         * console tty (via vhangup() or suchlike),
65878a
+                         * try to reconnect */
65878a
+
65878a
+                        log_close_console();
65878a
+                        log_open_console();
65878a
+
65878a
+                        if (console_fd < 0)
65878a
+                                return 0;
65878a
+
65878a
+                        if (writev(console_fd, iovec, n) < 0)
65878a
+                                return -errno;
65878a
+                } else
65878a
+                        return -errno;
65878a
+        }
65878a
 
65878a
         return 1;
65878a
 }