naccyde / rpms / systemd

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