naccyde / rpms / systemd

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