Blame SOURCES/0042-GdmLocalDisplayFactory-Store-VT-number-not-tty-ident.patch

a1b388
From 3cf5b4b12d3d39fa858ff593adeecfe711cdddaf Mon Sep 17 00:00:00 2001
a1b388
From: Iain Lane <iainl@gnome.org>
a1b388
Date: Tue, 7 May 2019 15:35:23 +0100
a1b388
Subject: [PATCH 42/51] GdmLocalDisplayFactory: Store VT number, not tty
a1b388
 identifier
a1b388
a1b388
This makes the code a fair bit simpler.
a1b388
---
a1b388
 configure.ac                       |  6 ++--
a1b388
 daemon/gdm-local-display-factory.c | 50 ++++++++++++++++--------------
a1b388
 daemon/gdm-server.c                |  2 +-
a1b388
 daemon/gdm-session-worker.c        |  2 +-
a1b388
 4 files changed, 31 insertions(+), 29 deletions(-)
a1b388
a1b388
diff --git a/configure.ac b/configure.ac
a1b388
index c549146ce..0c138ab38 100644
a1b388
--- a/configure.ac
a1b388
+++ b/configure.ac
a1b388
@@ -1477,66 +1477,66 @@ fi
a1b388
 AC_SUBST(DEBUG_CFLAGS)
a1b388
 
a1b388
 #
a1b388
 # Enable Profiling
a1b388
 #
a1b388
 AC_ARG_ENABLE(profiling,
a1b388
               AS_HELP_STRING([--enable-profiling],
a1b388
                              [turn on profiling]),,
a1b388
               enable_profiling=yes)
a1b388
 
a1b388
 if test "$enable_profiling" = "yes"; then
a1b388
     AC_DEFINE(ENABLE_PROFILING,1,[enable profiling])
a1b388
 fi
a1b388
 
a1b388
 #
a1b388
 # Set SHELL to use in scripts.
a1b388
 #
a1b388
 if test x$os_solaris = xyes ; then
a1b388
    XSESSION_SHELL=/bin/ksh
a1b388
 else
a1b388
    XSESSION_SHELL=/bin/sh
a1b388
 fi
a1b388
 
a1b388
 #
a1b388
 # Set VT to use for initial server
a1b388
 #
a1b388
 AC_ARG_WITH(initial-vt,
a1b388
         AS_HELP_STRING([--with-initial-vt=<nr>],
a1b388
                 [Initial virtual terminal to use]))
a1b388
 if ! test -z "$with_initial_vt"; then
a1b388
-        GDM_INITIAL_VT="$with_initial_vt"
a1b388
+        GDM_INITIAL_VT=$with_initial_vt
a1b388
 else
a1b388
-        GDM_INITIAL_VT="1"
a1b388
+        GDM_INITIAL_VT=1
a1b388
 fi
a1b388
 AC_SUBST(GDM_INITIAL_VT)
a1b388
-AC_DEFINE_UNQUOTED(GDM_INITIAL_VT, "$GDM_INITIAL_VT", [Initial Virtual Terminal])
a1b388
+AC_DEFINE_UNQUOTED(GDM_INITIAL_VT, $GDM_INITIAL_VT, [Initial Virtual Terminal])
a1b388
 
a1b388
 # Set configuration choices.
a1b388
 #
a1b388
 AC_SUBST(XSESSION_SHELL)
a1b388
 AC_DEFINE_UNQUOTED(XSESSION_SHELL,"$XSESSION_SHELL",[xsession shell])
a1b388
 AC_SUBST(SOUND_PROGRAM)
a1b388
 AC_DEFINE_UNQUOTED(SOUND_PROGRAM,"$SOUND_PROGRAM",[])
a1b388
 
a1b388
 AC_SUBST(X_PATH)
a1b388
 AC_SUBST(X_SERVER)
a1b388
 AC_SUBST(X_SERVER_PATH)
a1b388
 AC_DEFINE_UNQUOTED(X_SERVER,"$X_SERVER",[])
a1b388
 AC_DEFINE_UNQUOTED(X_SERVER_PATH,"$X_SERVER_PATH",[])
a1b388
 
a1b388
 ## Stuff for debian/changelog.in
a1b388
 #if test -e "debian/changelog"; then
a1b388
 #  DEBIAN_DATESTAMP=`head -1 debian/changelog| sed -e 's/.*cvs.//' -e 's/).*//'`
a1b388
 #  DEBIAN_DATE=`grep '^ --' debian/changelog | head -1 | sed -e 's/.*  //'`
a1b388
 #else
a1b388
 #  DEBIAN_DATESTAMP=`date +%Y%m%d%H%M%s`
a1b388
 #  DEBIAN_DATE=`date -R`
a1b388
 #fi
a1b388
 #
a1b388
 #AC_SUBST(DEBIAN_DATESTAMP)
a1b388
 #AC_SUBST(DEBIAN_DATE)
a1b388
 
a1b388
 AC_CONFIG_FILES([
a1b388
 Makefile
a1b388
 pam-extensions/Makefile
a1b388
 pam-extensions/gdm-pam-extensions.pc
a1b388
diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
a1b388
index d999596b5..7a013c694 100644
a1b388
--- a/daemon/gdm-local-display-factory.c
a1b388
+++ b/daemon/gdm-local-display-factory.c
a1b388
@@ -37,61 +37,61 @@
a1b388
 #include "gdm-local-display-factory-glue.h"
a1b388
 
a1b388
 #include "gdm-settings-keys.h"
a1b388
 #include "gdm-settings-direct.h"
a1b388
 #include "gdm-display-store.h"
a1b388
 #include "gdm-local-display.h"
a1b388
 #include "gdm-legacy-display.h"
a1b388
 
a1b388
 #define GDM_LOCAL_DISPLAY_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_LOCAL_DISPLAY_FACTORY, GdmLocalDisplayFactoryPrivate))
a1b388
 
a1b388
 #define GDM_DBUS_PATH                       "/org/gnome/DisplayManager"
a1b388
 #define GDM_LOCAL_DISPLAY_FACTORY_DBUS_PATH GDM_DBUS_PATH "/LocalDisplayFactory"
a1b388
 #define GDM_MANAGER_DBUS_NAME               "org.gnome.DisplayManager.LocalDisplayFactory"
a1b388
 
a1b388
 #define MAX_DISPLAY_FAILURES 5
a1b388
 #define WAIT_TO_FINISH_TIMEOUT 10 /* seconds */
a1b388
 
a1b388
 struct GdmLocalDisplayFactoryPrivate
a1b388
 {
a1b388
         GdmDBusLocalDisplayFactory *skeleton;
a1b388
         GDBusConnection *connection;
a1b388
         GHashTable      *used_display_numbers;
a1b388
 
a1b388
         /* FIXME: this needs to be per seat? */
a1b388
         guint            num_failures;
a1b388
 
a1b388
         guint            seat_new_id;
a1b388
         guint            seat_removed_id;
a1b388
 
a1b388
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
a1b388
-        char            *tty_of_active_vt;
a1b388
+        unsigned int     active_vt;
a1b388
         guint            active_vt_watch_id;
a1b388
         guint            wait_to_finish_timeout_id;
a1b388
 #endif
a1b388
 };
a1b388
 
a1b388
 enum {
a1b388
         PROP_0,
a1b388
 };
a1b388
 
a1b388
 static void     gdm_local_display_factory_class_init    (GdmLocalDisplayFactoryClass *klass);
a1b388
 static void     gdm_local_display_factory_init          (GdmLocalDisplayFactory      *factory);
a1b388
 static void     gdm_local_display_factory_finalize      (GObject                     *object);
a1b388
 
a1b388
 static GdmDisplay *create_display                       (GdmLocalDisplayFactory      *factory,
a1b388
                                                          const char                  *seat_id,
a1b388
                                                          const char                  *session_type,
a1b388
                                                          gboolean                    initial_display);
a1b388
 
a1b388
 static void     on_display_status_changed               (GdmDisplay                  *display,
a1b388
                                                          GParamSpec                  *arg1,
a1b388
                                                          GdmLocalDisplayFactory      *factory);
a1b388
 
a1b388
 static gboolean gdm_local_display_factory_sync_seats    (GdmLocalDisplayFactory *factory);
a1b388
 static gpointer local_display_factory_object = NULL;
a1b388
 static gboolean lookup_by_session_id (const char *id,
a1b388
                                       GdmDisplay *display,
a1b388
                                       gpointer    user_data);
a1b388
 
a1b388
 G_DEFINE_TYPE (GdmLocalDisplayFactory, gdm_local_display_factory, GDM_TYPE_DISPLAY_FACTORY)
a1b388
 
a1b388
@@ -641,157 +641,161 @@ maybe_stop_greeter_in_background (GdmLocalDisplayFactory *factory,
a1b388
                 g_debug ("GdmLocalDisplayFactory: login window is performing initial-setup, so ignoring");
a1b388
                 return;
a1b388
         }
a1b388
 
a1b388
         /* we can only stop greeter for wayland sessions, since
a1b388
          * X server would jump back on exit */
a1b388
         if (g_strcmp0 (display_session_type, "wayland") != 0) {
a1b388
                 g_debug ("GdmLocalDisplayFactory: login window is running on Xorg, so ignoring");
a1b388
                 return;
a1b388
         }
a1b388
 
a1b388
         g_debug ("GdmLocalDisplayFactory: killing login window once its unused");
a1b388
         g_object_set (G_OBJECT (display), "status", GDM_DISPLAY_WAITING_TO_FINISH, NULL);
a1b388
 
a1b388
         /* We stop the greeter after a timeout to avoid flicker */
a1b388
         if (factory->priv->wait_to_finish_timeout_id != 0)
a1b388
                 g_source_remove (factory->priv->wait_to_finish_timeout_id);
a1b388
 
a1b388
         factory->priv->wait_to_finish_timeout_id =
a1b388
                 g_timeout_add_seconds (WAIT_TO_FINISH_TIMEOUT,
a1b388
                                        (GSourceFunc)wait_to_finish_timeout,
a1b388
                                        factory);
a1b388
 }
a1b388
 
a1b388
 static gboolean
a1b388
 on_vt_changed (GIOChannel    *source,
a1b388
                GIOCondition   condition,
a1b388
                GdmLocalDisplayFactory *factory)
a1b388
 {
a1b388
         GIOStatus status;
a1b388
-        static const char *tty_of_initial_vt = "tty" GDM_INITIAL_VT;
a1b388
-        g_autofree char *tty_of_previous_vt = NULL;
a1b388
         g_autofree char *tty_of_active_vt = NULL;
a1b388
         g_autofree char *login_session_id = NULL;
a1b388
         g_autofree char *active_session_id = NULL;
a1b388
+        unsigned int previous_vt, new_vt;
a1b388
         const char *session_type = NULL;
a1b388
-        int ret;
a1b388
+        int ret, n_returned;
a1b388
 
a1b388
         g_debug ("GdmLocalDisplayFactory: received VT change event");
a1b388
         g_io_channel_seek_position (source, 0, G_SEEK_SET, NULL);
a1b388
 
a1b388
         if (condition & G_IO_PRI) {
a1b388
                 g_autoptr (GError) error = NULL;
a1b388
                 status = g_io_channel_read_line (source, &tty_of_active_vt, NULL, NULL, &error);
a1b388
 
a1b388
                 if (error != NULL) {
a1b388
                         g_warning ("could not read active VT from kernel: %s", error->message);
a1b388
                 }
a1b388
                 switch (status) {
a1b388
                         case G_IO_STATUS_ERROR:
a1b388
                             return G_SOURCE_REMOVE;
a1b388
                         case G_IO_STATUS_EOF:
a1b388
                             return G_SOURCE_REMOVE;
a1b388
                         case G_IO_STATUS_AGAIN:
a1b388
                             return G_SOURCE_CONTINUE;
a1b388
                         case G_IO_STATUS_NORMAL:
a1b388
                             break;
a1b388
                 }
a1b388
         }
a1b388
 
a1b388
         if ((condition & G_IO_ERR) || (condition & G_IO_HUP)) {
a1b388
                 g_debug ("GdmLocalDisplayFactory: kernel hung up active vt watch");
a1b388
                 return G_SOURCE_REMOVE;
a1b388
         }
a1b388
 
a1b388
         if (tty_of_active_vt == NULL) {
a1b388
                 g_debug ("GdmLocalDisplayFactory: unable to read active VT from kernel");
a1b388
                 return G_SOURCE_CONTINUE;
a1b388
         }
a1b388
 
a1b388
         g_strchomp (tty_of_active_vt);
a1b388
 
a1b388
+        errno = 0;
a1b388
+        n_returned = sscanf (tty_of_active_vt, "tty%u", &new_vt);
a1b388
+
a1b388
+        if (n_returned != 1 || errno != 0) {
a1b388
+                g_critical ("GdmLocalDisplayFactory: Couldn't read active VT (got '%s')",
a1b388
+                            tty_of_active_vt);
a1b388
+                return G_SOURCE_CONTINUE;
a1b388
+        }
a1b388
+
a1b388
         /* don't do anything if we're on the same VT we were before */
a1b388
-        if (g_strcmp0 (tty_of_active_vt, factory->priv->tty_of_active_vt) == 0) {
a1b388
+        if (new_vt == factory->priv->active_vt) {
a1b388
                 g_debug ("GdmLocalDisplayFactory: VT changed to the same VT, ignoring");
a1b388
                 return G_SOURCE_CONTINUE;
a1b388
         }
a1b388
 
a1b388
-        tty_of_previous_vt = g_steal_pointer (&factory->priv->tty_of_active_vt);
a1b388
-        factory->priv->tty_of_active_vt = g_steal_pointer (&tty_of_active_vt);
a1b388
+        previous_vt = factory->priv->active_vt;
a1b388
+        factory->priv->active_vt = new_vt;
a1b388
 
a1b388
         /* don't do anything at start up */
a1b388
-        if (tty_of_previous_vt == NULL) {
a1b388
-                g_debug ("GdmLocalDisplayFactory: VT is %s at startup",
a1b388
-                         factory->priv->tty_of_active_vt);
a1b388
+        if (previous_vt == 0) {
a1b388
+                g_debug ("GdmLocalDisplayFactory: VT is %u at startup",
a1b388
+                         factory->priv->active_vt);
a1b388
                 return G_SOURCE_CONTINUE;
a1b388
         }
a1b388
 
a1b388
-        g_debug ("GdmLocalDisplayFactory: VT changed from %s to %s",
a1b388
-                 tty_of_previous_vt, factory->priv->tty_of_active_vt);
a1b388
+        g_debug ("GdmLocalDisplayFactory: VT changed from %u to %u",
a1b388
+                 previous_vt, factory->priv->active_vt);
a1b388
 
a1b388
         /* if the old VT was running a wayland login screen kill it
a1b388
          */
a1b388
         if (gdm_get_login_window_session_id ("seat0", &login_session_id)) {
a1b388
-                unsigned int vt;
a1b388
+                unsigned int login_window_vt;
a1b388
 
a1b388
-                ret = sd_session_get_vt (login_session_id, &vt;;
a1b388
-                if (ret == 0 && vt != 0) {
a1b388
-                        g_autofree char *tty_of_login_window_vt = NULL;
a1b388
-
a1b388
-                        tty_of_login_window_vt = g_strdup_printf ("tty%u", vt);
a1b388
-
a1b388
-                        g_debug ("GdmLocalDisplayFactory: tty of login window is %s", tty_of_login_window_vt);
a1b388
-                        if (g_strcmp0 (tty_of_login_window_vt, tty_of_previous_vt) == 0) {
a1b388
+                ret = sd_session_get_vt (login_session_id, &login_window_vt);
a1b388
+                if (ret == 0 && login_window_vt != 0) {
a1b388
+                        g_debug ("GdmLocalDisplayFactory: VT of login window is %u", login_window_vt);
a1b388
+                        if (login_window_vt == previous_vt) {
a1b388
                                 GdmDisplayStore *store;
a1b388
                                 GdmDisplay *display;
a1b388
 
a1b388
                                 g_debug ("GdmLocalDisplayFactory: VT switched from login window");
a1b388
 
a1b388
                                 store = gdm_display_factory_get_display_store (GDM_DISPLAY_FACTORY (factory));
a1b388
                                 display = gdm_display_store_find (store,
a1b388
                                                                   lookup_by_session_id,
a1b388
                                                                   (gpointer) login_session_id);
a1b388
 
a1b388
                                 if (display != NULL)
a1b388
                                         maybe_stop_greeter_in_background (factory, display);
a1b388
                         } else {
a1b388
                                 g_debug ("GdmLocalDisplayFactory: VT not switched from login window");
a1b388
                         }
a1b388
                 }
a1b388
         }
a1b388
 
a1b388
         /* if user jumped back to initial vt and it's empty put a login screen
a1b388
          * on it (unless a login screen is already running elsewhere, then
a1b388
          * jump to that login screen)
a1b388
          */
a1b388
-        if (strcmp (factory->priv->tty_of_active_vt, tty_of_initial_vt) != 0) {
a1b388
+        if (factory->priv->active_vt != GDM_INITIAL_VT) {
a1b388
                 g_debug ("GdmLocalDisplayFactory: active VT is not initial VT, so ignoring");
a1b388
                 return G_SOURCE_CONTINUE;
a1b388
         }
a1b388
 
a1b388
         if (gdm_local_display_factory_use_wayland ())
a1b388
                 session_type = "wayland";
a1b388
 
a1b388
         g_debug ("GdmLocalDisplayFactory: creating new display on seat0 because of VT change");
a1b388
 
a1b388
         create_display (factory, "seat0", session_type, TRUE);
a1b388
 
a1b388
         return G_SOURCE_CONTINUE;
a1b388
 }
a1b388
 #endif
a1b388
 
a1b388
 static void
a1b388
 gdm_local_display_factory_start_monitor (GdmLocalDisplayFactory *factory)
a1b388
 {
a1b388
         g_autoptr (GIOChannel) io_channel = NULL;
a1b388
 
a1b388
         factory->priv->seat_new_id = g_dbus_connection_signal_subscribe (factory->priv->connection,
a1b388
                                                                          "org.freedesktop.login1",
a1b388
                                                                          "org.freedesktop.login1.Manager",
a1b388
                                                                          "SeatNew",
a1b388
                                                                          "/org/freedesktop/login1",
a1b388
                                                                          NULL,
a1b388
                                                                          G_DBUS_SIGNAL_FLAGS_NONE,
a1b388
                                                                          on_seat_new,
a1b388
                                                                          g_object_ref (factory),
a1b388
                                                                          g_object_unref);
a1b388
@@ -815,62 +819,60 @@ gdm_local_display_factory_start_monitor (GdmLocalDisplayFactory *factory)
a1b388
                                         G_IO_PRI,
a1b388
                                         (GIOFunc)
a1b388
                                         on_vt_changed,
a1b388
                                         factory);
a1b388
         }
a1b388
 #endif
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 gdm_local_display_factory_stop_monitor (GdmLocalDisplayFactory *factory)
a1b388
 {
a1b388
         if (factory->priv->seat_new_id) {
a1b388
                 g_dbus_connection_signal_unsubscribe (factory->priv->connection,
a1b388
                                                       factory->priv->seat_new_id);
a1b388
                 factory->priv->seat_new_id = 0;
a1b388
         }
a1b388
         if (factory->priv->seat_removed_id) {
a1b388
                 g_dbus_connection_signal_unsubscribe (factory->priv->connection,
a1b388
                                                       factory->priv->seat_removed_id);
a1b388
                 factory->priv->seat_removed_id = 0;
a1b388
         }
a1b388
 #if defined(ENABLE_WAYLAND_SUPPORT) && defined(ENABLE_USER_DISPLAY_SERVER)
a1b388
         if (factory->priv->wait_to_finish_timeout_id != 0) {
a1b388
                 g_source_remove (factory->priv->wait_to_finish_timeout_id);
a1b388
                 factory->priv->wait_to_finish_timeout_id = 0;
a1b388
         }
a1b388
         if (factory->priv->active_vt_watch_id) {
a1b388
                 g_source_remove (factory->priv->active_vt_watch_id);
a1b388
                 factory->priv->active_vt_watch_id = 0;
a1b388
         }
a1b388
-
a1b388
-        g_clear_pointer (&factory->priv->tty_of_active_vt, g_free);
a1b388
 #endif
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 on_display_added (GdmDisplayStore        *display_store,
a1b388
                   const char             *id,
a1b388
                   GdmLocalDisplayFactory *factory)
a1b388
 {
a1b388
         GdmDisplay *display;
a1b388
 
a1b388
         display = gdm_display_store_lookup (display_store, id);
a1b388
 
a1b388
         if (display != NULL) {
a1b388
                 g_signal_connect_object (display, "notify::status",
a1b388
                                          G_CALLBACK (on_display_status_changed),
a1b388
                                          factory,
a1b388
                                          0);
a1b388
 
a1b388
                 g_object_weak_ref (G_OBJECT (display), (GWeakNotify)on_display_disposed, factory);
a1b388
         }
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 on_display_removed (GdmDisplayStore        *display_store,
a1b388
                     GdmDisplay             *display,
a1b388
                     GdmLocalDisplayFactory *factory)
a1b388
 {
a1b388
         g_signal_handlers_disconnect_by_func (display, G_CALLBACK (on_display_status_changed), factory);
a1b388
         g_object_weak_unref (G_OBJECT (display), (GWeakNotify)on_display_disposed, factory);
a1b388
 }
a1b388
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
a1b388
index 83fba99c8..04406a61a 100644
a1b388
--- a/daemon/gdm-server.c
a1b388
+++ b/daemon/gdm-server.c
a1b388
@@ -726,61 +726,61 @@ gdm_server_spawn (GdmServer    *server,
a1b388
                                                           (GChildWatchFunc)server_child_watch,
a1b388
                                                           server);
a1b388
 
a1b388
         ret = TRUE;
a1b388
  out:
a1b388
         g_strfreev (argv);
a1b388
         if (env) {
a1b388
                 g_ptr_array_foreach (env, (GFunc)g_free, NULL);
a1b388
                 g_ptr_array_free (env, TRUE);
a1b388
         }
a1b388
         return ret;
a1b388
 }
a1b388
 
a1b388
 /**
a1b388
  * gdm_server_start:
a1b388
  * @disp: Pointer to a GdmDisplay structure
a1b388
  *
a1b388
  * Starts a local X server. Handles retries and fatal errors properly.
a1b388
  */
a1b388
 
a1b388
 gboolean
a1b388
 gdm_server_start (GdmServer *server)
a1b388
 {
a1b388
         gboolean res = FALSE;
a1b388
         const char *vtarg = NULL;
a1b388
         GError *local_error = NULL;
a1b388
         GError **error = &local_error;
a1b388
 
a1b388
         /* Hardcode the VT for the initial X server, but nothing else */
a1b388
         if (server->priv->is_initial) {
a1b388
-                vtarg = "vt" GDM_INITIAL_VT;
a1b388
+                vtarg = "vt" G_STRINGIFY (GDM_INITIAL_VT);
a1b388
         }
a1b388
 
a1b388
         /* fork X server process */
a1b388
         if (!gdm_server_spawn (server, vtarg, error)) {
a1b388
                 goto out;
a1b388
         }
a1b388
 
a1b388
         res = TRUE;
a1b388
  out:
a1b388
         if (local_error) {
a1b388
                 g_printerr ("%s\n", local_error->message);
a1b388
                 g_clear_error (&local_error);
a1b388
         }
a1b388
         return res;
a1b388
 }
a1b388
 
a1b388
 static void
a1b388
 server_died (GdmServer *server)
a1b388
 {
a1b388
         int exit_status;
a1b388
 
a1b388
         g_debug ("GdmServer: Waiting on process %d", server->priv->pid);
a1b388
         exit_status = gdm_wait_on_pid (server->priv->pid);
a1b388
 
a1b388
         if (WIFEXITED (exit_status) && (WEXITSTATUS (exit_status) != 0)) {
a1b388
                 g_debug ("GdmServer: Wait on child process failed");
a1b388
         } else {
a1b388
                 /* exited normally */
a1b388
         }
a1b388
 
a1b388
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
a1b388
index 7ed2789da..b4befaa83 100644
a1b388
--- a/daemon/gdm-session-worker.c
a1b388
+++ b/daemon/gdm-session-worker.c
a1b388
@@ -2202,61 +2202,61 @@ gdm_session_worker_start_session (GdmSessionWorker  *worker,
a1b388
 
a1b388
         g_debug ("GdmSessionWorker: state SESSION_STARTED");
a1b388
         gdm_session_worker_set_state (worker, GDM_SESSION_WORKER_STATE_SESSION_STARTED);
a1b388
 
a1b388
         gdm_session_worker_watch_child (worker);
a1b388
 
a1b388
  out:
a1b388
         if (error_code != PAM_SUCCESS) {
a1b388
                 gdm_session_worker_uninitialize_pam (worker, error_code);
a1b388
                 return FALSE;
a1b388
         }
a1b388
 
a1b388
         return TRUE;
a1b388
 }
a1b388
 
a1b388
 static gboolean
a1b388
 set_up_for_new_vt (GdmSessionWorker *worker)
a1b388
 {
a1b388
         int fd;
a1b388
         char vt_string[256], tty_string[256];
a1b388
         int session_vt = 0;
a1b388
 
a1b388
         fd = open ("/dev/tty0", O_RDWR | O_NOCTTY);
a1b388
 
a1b388
         if (fd < 0) {
a1b388
                 g_debug ("GdmSessionWorker: couldn't open VT master: %m");
a1b388
                 return FALSE;
a1b388
         }
a1b388
 
a1b388
         if (worker->priv->display_is_initial) {
a1b388
-                session_vt = atoi (GDM_INITIAL_VT);
a1b388
+                session_vt = GDM_INITIAL_VT;
a1b388
         } else {
a1b388
                 if (ioctl(fd, VT_OPENQRY, &session_vt) < 0) {
a1b388
                         g_debug ("GdmSessionWorker: couldn't open new VT: %m");
a1b388
                         goto fail;
a1b388
                 }
a1b388
         }
a1b388
 
a1b388
         worker->priv->session_vt = session_vt;
a1b388
 
a1b388
         close (fd);
a1b388
         fd = -1;
a1b388
 
a1b388
         g_assert (session_vt > 0);
a1b388
 
a1b388
         g_snprintf (vt_string, sizeof (vt_string), "%d", session_vt);
a1b388
 
a1b388
         /* Set the VTNR. This is used by logind to configure a session in
a1b388
          * the logind-managed case, but it doesn't hurt to set it always.
a1b388
          * When logind gains support for XDG_VTNR=auto, we can make the
a1b388
          * OPENQRY and this whole path only used by the new VT code. */
a1b388
         gdm_session_worker_set_environment_variable (worker,
a1b388
                                                      "XDG_VTNR",
a1b388
                                                      vt_string);
a1b388
 
a1b388
         g_snprintf (tty_string, 256, "/dev/tty%d", session_vt);
a1b388
         worker->priv->session_tty_fd = open (tty_string, O_RDWR | O_NOCTTY);
a1b388
         pam_set_item (worker->priv->pam_handle, PAM_TTY, tty_string);
a1b388
 
a1b388
         return TRUE;
a1b388
 
a1b388
-- 
a1b388
2.27.0
a1b388