[mutter] launcher: Pass fallback session/seat ID when in test mode



commit 1cc786ffd3c429a883f61467dfb8a7afcc231008
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Sat Dec 11 00:28:37 2021 +0100

    launcher: Pass fallback session/seat ID when in test mode
    
    When we test, we might not have a systemd session to rely on, and this
    may cause some API we depend on to get various session related data to
    not work properly. Avoid this issue by passing fallback values for these
    when we're running in test mode.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2151>

 src/backends/native/meta-backend-native.c | 18 +++++++++++-
 src/backends/native/meta-launcher.c       | 49 ++++++++++++++++++++++++-------
 src/backends/native/meta-launcher.h       |  4 ++-
 3 files changed, 59 insertions(+), 12 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 432d2c2aa8..e3d2c5ab03 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -605,7 +605,23 @@ meta_backend_native_initable_init (GInitable     *initable,
 
   if (!meta_backend_is_headless (backend))
     {
-      native->launcher = meta_launcher_new (error);
+      const char *session_id = NULL;
+      const char *seat_id = NULL;
+
+      switch (native->mode)
+        {
+        case META_BACKEND_NATIVE_MODE_DEFAULT:
+          break;
+        case META_BACKEND_NATIVE_MODE_HEADLESS:
+          g_assert_not_reached ();
+          break;
+        case META_BACKEND_NATIVE_MODE_TEST:
+          session_id = "dummy";
+          seat_id = "seat0";
+          break;
+        }
+
+      native->launcher = meta_launcher_new (session_id, seat_id, error);
       if (!native->launcher)
         return FALSE;
     }
diff --git a/src/backends/native/meta-launcher.c b/src/backends/native/meta-launcher.c
index e87a66af80..2d2f14dcf5 100644
--- a/src/backends/native/meta-launcher.c
+++ b/src/backends/native/meta-launcher.c
@@ -221,8 +221,9 @@ find_systemd_session (gchar **session_id,
 }
 
 static MetaDbusLogin1Session *
-get_session_proxy (GCancellable *cancellable,
-                   GError      **error)
+get_session_proxy (const char    *fallback_session_id,
+                   GCancellable  *cancellable,
+                   GError       **error)
 {
   g_autofree char *proxy_path = NULL;
   g_autofree char *session_id = NULL;
@@ -232,10 +233,21 @@ get_session_proxy (GCancellable *cancellable,
 
   if (!find_systemd_session (&session_id, &local_error))
     {
-      g_propagate_prefixed_error (error,
-                                  g_steal_pointer (&local_error),
-                                  "Could not get session ID: ");
-      return NULL;
+      if (fallback_session_id)
+        {
+          meta_topic (META_DEBUG_BACKEND,
+                      "Failed to get seat ID: %s, using fallback (%s)",
+                      local_error->message, fallback_session_id);
+          g_clear_error (&local_error);
+          session_id = g_strdup (fallback_session_id);
+        }
+      else
+        {
+          g_propagate_prefixed_error (error,
+                                      g_steal_pointer (&local_error),
+                                      "Could not get session ID: ");
+          return NULL;
+        }
     }
 
   proxy_path = get_escaped_dbus_path ("/org/freedesktop/login1/session", session_id);
@@ -340,15 +352,18 @@ meta_launcher_get_session_proxy (MetaLauncher *launcher)
 }
 
 MetaLauncher *
-meta_launcher_new (GError **error)
+meta_launcher_new (const char  *fallback_session_id,
+                   const char  *fallback_seat_id,
+                   GError     **error)
 {
   MetaLauncher *self = NULL;
   g_autoptr (MetaDbusLogin1Session) session_proxy = NULL;
   g_autoptr (MetaDbusLogin1Seat) seat_proxy = NULL;
+  g_autoptr (GError) local_error = NULL;
   g_autofree char *seat_id = NULL;
   gboolean have_control = FALSE;
 
-  session_proxy = get_session_proxy (NULL, error);
+  session_proxy = get_session_proxy (fallback_session_id, NULL, error);
   if (!session_proxy)
     goto fail;
 
@@ -363,9 +378,23 @@ meta_launcher_new (GError **error)
 
   have_control = TRUE;
 
-  seat_id = get_seat_id (error);
+  seat_id = get_seat_id (&local_error);
   if (!seat_id)
-    goto fail;
+    {
+      if (fallback_seat_id)
+        {
+          meta_topic (META_DEBUG_BACKEND,
+                      "Failed to get seat ID: %s, using fallback (%s)",
+                      local_error->message, fallback_seat_id);
+          g_clear_error (&local_error);
+          seat_id = g_strdup (fallback_seat_id);
+        }
+      else
+        {
+          g_propagate_error (error, local_error);
+          goto fail;
+        }
+    }
 
   seat_proxy = get_seat_proxy (seat_id, NULL, error);
   if (!seat_proxy)
diff --git a/src/backends/native/meta-launcher.h b/src/backends/native/meta-launcher.h
index 267b68337f..670699a4bd 100644
--- a/src/backends/native/meta-launcher.h
+++ b/src/backends/native/meta-launcher.h
@@ -25,7 +25,9 @@
 typedef struct _MetaLauncher MetaLauncher;
 typedef struct _MetaDbusLogin1Session MetaDbusLogin1Session;
 
-MetaLauncher     *meta_launcher_new                     (GError       **error);
+MetaLauncher     *meta_launcher_new                     (const char    *session_id,
+                                                         const char    *custom_seat_id,
+                                                         GError       **error);
 void              meta_launcher_free                    (MetaLauncher  *self);
 
 gboolean          meta_launcher_activate_vt             (MetaLauncher  *self,


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