[gdm/x-gdm-sessionregisters: 1/4] GdmLocalDisplayFactory: Store VT number, not tty identifier



commit 8673a232da35070b1ef8ebc242319801c62578d2
Author: Iain Lane <iainl gnome org>
Date:   Tue May 7 15:35:23 2019 +0100

    GdmLocalDisplayFactory: Store VT number, not tty identifier
    
    This makes the code a fair bit simpler.

 configure.ac                       |  6 ++---
 daemon/gdm-local-display-factory.c | 50 ++++++++++++++++++++------------------
 daemon/gdm-server.c                |  2 +-
 daemon/gdm-session-worker.c        |  2 +-
 4 files changed, 31 insertions(+), 29 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e54017f2..0a1c6c19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1416,12 +1416,12 @@ AC_ARG_WITH(initial-vt,
         AS_HELP_STRING([--with-initial-vt=<nr>],
                 [Initial virtual terminal to use]))
 if ! test -z "$with_initial_vt"; then
-        GDM_INITIAL_VT="$with_initial_vt"
+        GDM_INITIAL_VT=$with_initial_vt
 else
-        GDM_INITIAL_VT="1"
+        GDM_INITIAL_VT=1
 fi
 AC_SUBST(GDM_INITIAL_VT)
-AC_DEFINE_UNQUOTED(GDM_INITIAL_VT, "$GDM_INITIAL_VT", [Initial Virtual Terminal])
+AC_DEFINE_UNQUOTED(GDM_INITIAL_VT, $GDM_INITIAL_VT, [Initial Virtual Terminal])
 
 # Set configuration choices.
 #
diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
index 98daca48..7dd74a62 100644
--- a/daemon/gdm-local-display-factory.c
+++ b/daemon/gdm-local-display-factory.c
@@ -64,7 +64,7 @@ struct _GdmLocalDisplayFactory
         guint            seat_removed_id;
 
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
-        char            *tty_of_active_vt;
+        unsigned int     active_vt;
         guint            active_vt_watch_id;
         guint            wait_to_finish_timeout_id;
 #endif
@@ -661,13 +661,12 @@ on_vt_changed (GIOChannel    *source,
                GdmLocalDisplayFactory *factory)
 {
         GIOStatus status;
-        static const char *tty_of_initial_vt = "tty" GDM_INITIAL_VT;
-        g_autofree char *tty_of_previous_vt = NULL;
         g_autofree char *tty_of_active_vt = NULL;
         g_autofree char *login_session_id = NULL;
         g_autofree char *active_session_id = NULL;
+        unsigned int previous_vt, new_vt;
         const char *session_type = NULL;
-        int ret;
+        int ret, n_returned;
 
         g_debug ("GdmLocalDisplayFactory: received VT change event");
         g_io_channel_seek_position (source, 0, G_SEEK_SET, NULL);
@@ -703,38 +702,43 @@ on_vt_changed (GIOChannel    *source,
 
         g_strchomp (tty_of_active_vt);
 
+        errno = 0;
+        n_returned = sscanf (tty_of_active_vt, "tty%u", &new_vt);
+
+        if (n_returned != 1 || errno != 0) {
+                g_critical ("GdmLocalDisplayFactory: Couldn't read active VT (got '%s')",
+                            tty_of_active_vt);
+                return G_SOURCE_CONTINUE;
+        }
+
         /* don't do anything if we're on the same VT we were before */
-        if (g_strcmp0 (tty_of_active_vt, factory->tty_of_active_vt) == 0) {
+        if (new_vt == factory->active_vt) {
                 g_debug ("GdmLocalDisplayFactory: VT changed to the same VT, ignoring");
                 return G_SOURCE_CONTINUE;
         }
 
-        tty_of_previous_vt = g_steal_pointer (&factory->tty_of_active_vt);
-        factory->tty_of_active_vt = g_steal_pointer (&tty_of_active_vt);
+        previous_vt = factory->active_vt;
+        factory->active_vt = new_vt;
 
         /* don't do anything at start up */
-        if (tty_of_previous_vt == NULL) {
-                g_debug ("GdmLocalDisplayFactory: VT is %s at startup",
-                         factory->tty_of_active_vt);
+        if (previous_vt == 0) {
+                g_debug ("GdmLocalDisplayFactory: VT is %u at startup",
+                         factory->active_vt);
                 return G_SOURCE_CONTINUE;
         }
 
-        g_debug ("GdmLocalDisplayFactory: VT changed from %s to %s",
-                 tty_of_previous_vt, factory->tty_of_active_vt);
+        g_debug ("GdmLocalDisplayFactory: VT changed from %u to %u",
+                 previous_vt, factory->active_vt);
 
         /* if the old VT was running a wayland login screen kill it
          */
         if (gdm_get_login_window_session_id ("seat0", &login_session_id)) {
-                unsigned int vt;
+                unsigned int login_window_vt;
 
-                ret = sd_session_get_vt (login_session_id, &vt);
-                if (ret == 0 && vt != 0) {
-                        g_autofree char *tty_of_login_window_vt = NULL;
-
-                        tty_of_login_window_vt = g_strdup_printf ("tty%u", vt);
-
-                        g_debug ("GdmLocalDisplayFactory: tty of login window is %s", 
tty_of_login_window_vt);
-                        if (g_strcmp0 (tty_of_login_window_vt, tty_of_previous_vt) == 0) {
+                ret = sd_session_get_vt (login_session_id, &login_window_vt);
+                if (ret == 0 && login_window_vt != 0) {
+                        g_debug ("GdmLocalDisplayFactory: VT of login window is %u", login_window_vt);
+                        if (login_window_vt == previous_vt) {
                                 GdmDisplayStore *store;
                                 GdmDisplay *display;
 
@@ -757,7 +761,7 @@ on_vt_changed (GIOChannel    *source,
          * on it (unless a login screen is already running elsewhere, then
          * jump to that login screen)
          */
-        if (strcmp (factory->tty_of_active_vt, tty_of_initial_vt) != 0) {
+        if (factory->active_vt != GDM_INITIAL_VT) {
                 g_debug ("GdmLocalDisplayFactory: active VT is not initial VT, so ignoring");
                 return G_SOURCE_CONTINUE;
         }
@@ -835,8 +839,6 @@ gdm_local_display_factory_stop_monitor (GdmLocalDisplayFactory *factory)
                 g_source_remove (factory->active_vt_watch_id);
                 factory->active_vt_watch_id = 0;
         }
-
-        g_clear_pointer (&factory->tty_of_active_vt, g_free);
 #endif
 }
 
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
index 7962de22..1ba00d45 100644
--- a/daemon/gdm-server.c
+++ b/daemon/gdm-server.c
@@ -753,7 +753,7 @@ gdm_server_start (GdmServer *server)
 
         /* Hardcode the VT for the initial X server, but nothing else */
         if (server->is_initial) {
-                vtarg = "vt" GDM_INITIAL_VT;
+                vtarg = "vt" G_STRINGIFY (GDM_INITIAL_VT);
         }
 
         /* fork X server process */
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index 640cdbb6..a5f90c4b 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -2224,7 +2224,7 @@ set_up_for_new_vt (GdmSessionWorker *worker)
         }
 
         if (worker->priv->display_is_initial) {
-                session_vt = atoi (GDM_INITIAL_VT);
+                session_vt = GDM_INITIAL_VT;
         } else {
                 if (ioctl(fd, VT_OPENQRY, &session_vt) < 0) {
                         g_debug ("GdmSessionWorker: couldn't open new VT: %m");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]