chiark / gitweb /
getty: don't parse console= anymore, use /sys/class/tty/console/active instead
[elogind.git] / src / util.c
index 09c13143c6bf528afaa7e3f551bac6d43159d878..80b88b0e4e2fee36dc9dbf278ed919276107cc19 100644 (file)
@@ -3549,19 +3549,43 @@ void filter_environ(const char *prefix) {
         environ[j] = NULL;
 }
 
+bool tty_is_vc(const char *tty) {
+        assert(tty);
+
+        if (startswith(tty, "/dev/"))
+                tty += 5;
+
+        return startswith(tty, "tty") &&
+                tty[3] >= '0' && tty[3] <= '9';
+}
+
 const char *default_term_for_tty(const char *tty) {
+        char *active = NULL;
+        const char *term;
+
         assert(tty);
 
         if (startswith(tty, "/dev/"))
                 tty += 5;
 
-        if (startswith(tty, "tty") &&
-            tty[3] >= '0' && tty[3] <= '9')
-                return "TERM=linux";
+        /* Resolve where /dev/console is pointing when determining
+         * TERM */
+        if (streq(tty, "console"))
+                if (read_one_line_file("/sys/class/tty/console/active", &active) >= 0) {
+                        truncate_nl(active);
+
+                        /* If multiple log outputs are configured the
+                         * last one is what /dev/console points to */
+                        if ((tty = strrchr(active, ' ')))
+                                tty++;
+                        else
+                                tty = active;
+                }
 
-        /* FIXME: Proper handling of /dev/console would be cool */
+        term = tty_is_vc(tty) ? "TERM=linux" : "TERM=vt100";
+        free(active);
 
-        return "TERM=vt100";
+        return term;
 }
 
 bool running_in_vm(void) {