dcavalca / rpms / systemd

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