From 1cc786ffd3c429a883f61467dfb8a7afcc231008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Sat, 11 Dec 2021 00:28:37 +0100 Subject: [PATCH] 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: --- 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 432d2c2aa..e3d2c5ab0 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 e87a66af8..2d2f14dcf 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 267b68337..670699a4b 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,