a52f674
From 203562872b07690556d196ef8980c3af41f1d21c Mon Sep 17 00:00:00 2001
930e1b8
From: Olivier Brunel <jjk@jjacky.com>
930e1b8
Date: Fri, 20 Sep 2013 22:18:28 +0200
930e1b8
Subject: [PATCH] Resolve /dev/console to the active tty instead of just "tty0"
930e1b8
930e1b8
When resolving /dev/console one would often get "tty0" meaning the active VT.
930e1b8
Resolving to the actual tty (e.g. "tty1") will notably help on boot when
930e1b8
determining whether or not PID1 can output to the console.
930e1b8
---
930e1b8
 src/shared/util.c | 10 ++++++++++
930e1b8
 1 file changed, 10 insertions(+)
930e1b8
930e1b8
diff --git a/src/shared/util.c b/src/shared/util.c
930e1b8
index 6c88040..3fc080a 100644
930e1b8
--- a/src/shared/util.c
930e1b8
+++ b/src/shared/util.c
930e1b8
@@ -3621,6 +3621,16 @@ char *resolve_dev_console(char **active) {
930e1b8
         else
930e1b8
                 tty = *active;
930e1b8
 
930e1b8
+        if (streq(tty, "tty0")) {
930e1b8
+                char *tmp;
930e1b8
+
930e1b8
+                /* Get the active VC (e.g. tty1) */
930e1b8
+                if (read_one_line_file("/sys/class/tty/tty0/active", &tmp) >= 0) {
930e1b8
+                        free(*active);
930e1b8
+                        tty = *active = tmp;
930e1b8
+                }
930e1b8
+        }
930e1b8
+
930e1b8
         return tty;
930e1b8
 }
930e1b8