]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Use /dev/tty0 instead of /dev/console.
authorRobert Ancell <robert.ancell@canonical.com>
Mon, 4 Apr 2016 23:57:40 +0000 (11:57 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Mon, 4 Apr 2016 23:57:40 +0000 (11:57 +1200)
For some unknown reason /dev/console doesn't seem to be working in Ubuntu 16.04.
Use /dev/tty0 as that is what logind / GDM are using.

src/vt.c
tests/src/libsystem.c

index 921589023349888d326991b818d27b144f952633..8d31f78b25ece779c2901670b58051c9ceb6342a 100644 (file)
--- a/src/vt.c
+++ b/src/vt.c
 static GList *used_vts = NULL;
 
 static gint
-open_console (void)
+open_tty (void)
 {
     int fd;
 
-    fd = g_open ("/dev/console", O_RDONLY | O_NOCTTY, 0);
+    fd = g_open ("/dev/tty0", O_RDONLY | O_NOCTTY, 0);
     if (fd < 0)
-        g_warning ("Error opening /dev/console: %s", strerror (errno));
+        g_warning ("Error opening /dev/tty0: %s", strerror (errno));
     return fd;
 }
 
@@ -41,11 +41,7 @@ vt_can_multi_seat (void)
 {
     /* Quick check to see if we can multi seat.  This is intentionally the
        same check logind does, just without actually reading from the files.
-       Existence will prove whether we have CONFIG_VT built into the kernel.
-       (Reading /dev/console like the rest of the code in this file isn't
-       sufficient -- it may still exist if tty0 doesn't and it may not work
-       in situations where tty0 does exist and thus logind will think we are
-       multi seat.) */
+       Existence will prove whether we have CONFIG_VT built into the kernel. */
     return access ("/dev/tty0", F_OK) == 0 &&
            access ("/sys/class/tty/tty0/active", F_OK) == 0;
 }
@@ -54,22 +50,22 @@ gint
 vt_get_active (void)
 {
 #ifdef __linux__
-    gint console_fd;
+    gint tty_fd;
     gint active = -1;
 
     /* Pretend always active */
     if (getuid () != 0)
         return 1;
 
-    console_fd = open_console ();
-    if (console_fd >= 0)
+    tty_fd = open_tty ();
+    if (tty_fd >= 0)
     {
-        struct vt_stat console_state = { 0 };
-        if (ioctl (console_fd, VT_GETSTATE, &console_state) < 0)
-            g_warning ("Error using VT_GETSTATE on /dev/console: %s", strerror (errno));
+        struct vt_stat vt_state = { 0 };
+        if (ioctl (tty_fd, VT_GETSTATE, &vt_state) < 0)
+            g_warning ("Error using VT_GETSTATE on /dev/tty0: %s", strerror (errno));
         else
-            active = console_state.v_active;
-        close (console_fd);
+            active = vt_state.v_active;
+        close (tty_fd);
     }
 
     return active;
@@ -82,7 +78,7 @@ void
 vt_set_active (gint number)
 {
 #ifdef __linux__
-    gint console_fd;
+    gint tty_fd;
 
     g_debug ("Activating VT %d", number);
 
@@ -90,21 +86,21 @@ vt_set_active (gint number)
     if (getuid () != 0)
         return;
 
-    console_fd = open_console ();
-    if (console_fd >= 0)
+    tty_fd = open_tty ();
+    if (tty_fd >= 0)
     {
         int n = number;
 
-        if (ioctl (console_fd, VT_ACTIVATE, n) < 0)
-            g_warning ("Error using VT_ACTIVATE %d on /dev/console: %s", n, strerror (errno));
+        if (ioctl (tty_fd, VT_ACTIVATE, n) < 0)
+            g_warning ("Error using VT_ACTIVATE %d on /dev/tty0: %s", n, strerror (errno));
 
         /* Wait for the VT to become active to avoid a suspected
          * race condition somewhere between LightDM, X, ConsoleKit and the kernel.
          * See https://bugs.launchpad.net/bugs/851612 */
-        if (ioctl (console_fd, VT_WAITACTIVE) < 0)
-            g_warning ("Error using VT_WAITACTIVE %d on /dev/console: %s", n, strerror (errno));
+        if (ioctl (tty_fd, VT_WAITACTIVE) < 0)
+            g_warning ("Error using VT_WAITACTIVE %d on /dev/tty0: %s", n, strerror (errno));
 
-        close (console_fd);
+        close (tty_fd);
     }
 #endif
 }
index 38c00ea99f9b9c3a621c662563d7bc8751f0d4e8..734f52b2049f43d3c33ce66397328f3b97a148ae 100644 (file)
@@ -36,7 +36,7 @@
 
 #define LOGIN_PROMPT "login:"
 
-static int console_fd = -1;
+static int tty_fd = -1;
 
 static GList *user_entries = NULL;
 static GList *getpwent_link = NULL;
@@ -234,14 +234,14 @@ open_wrapper (const char *func, const char *pathname, int flags, mode_t mode)
 
     _open = (int (*)(const char *pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, func);
 
-    if (strcmp (pathname, "/dev/console") == 0)
+    if (strcmp (pathname, "/dev/tty0") == 0)
     {
-        if (console_fd < 0)
+        if (tty_fd < 0)
         {
-            console_fd = _open ("/dev/null", flags, mode);
-            fcntl (console_fd, F_SETFD, FD_CLOEXEC);
+            tty_fd = _open ("/dev/null", flags, mode);
+            fcntl (tty_fd, F_SETFD, FD_CLOEXEC);
         }
-        return console_fd;
+        return tty_fd;
     }
 
     new_path = redirect_path (pathname);
@@ -521,9 +521,9 @@ ioctl (int d, unsigned long request, ...)
     int (*_ioctl) (int d, int request, ...);
 
     _ioctl = (int (*)(int d, int request, ...)) dlsym (RTLD_NEXT, "ioctl");
-    if (d > 0 && d == console_fd)
+    if (d > 0 && d == tty_fd)
     {
-        struct vt_stat *console_state;
+        struct vt_stat *vt_state;
         int vt;
         va_list ap;
 
@@ -531,9 +531,9 @@ ioctl (int d, unsigned long request, ...)
         {
         case VT_GETSTATE:
             va_start (ap, request);
-            console_state = va_arg (ap, struct vt_stat *);
+            vt_state = va_arg (ap, struct vt_stat *);
             va_end (ap);
-            console_state->v_active = active_vt;
+            vt_state->v_active = active_vt;
             break;
         case VT_ACTIVATE:
             va_start (ap, request);
@@ -750,7 +750,7 @@ close (int fd)
 {
     int (*_close) (int fd);
 
-    if (fd > 0 && fd == console_fd)
+    if (fd > 0 && fd == tty_fd)
         return 0;
 
     _close = (int (*)(int fd)) dlsym (RTLD_NEXT, "close");