summaryrefslogtreecommitdiff
path: root/daemon/gdm-wayland-session.c
diff options
context:
space:
mode:
authorIain Lane <iainl@gnome.org>2019-05-07 16:00:14 +0100
committerIain Lane <iain@orangesquash.org.uk>2019-05-29 15:53:35 +0000
commit1c061b84ffc3e874da825982d18d970556ff74bb (patch)
tree64f56c787fdfa6e2a205ea726d589fad546da300 /daemon/gdm-wayland-session.c
parent9496f639715b1b8e31b2b0a5bd37a8b6761249b3 (diff)
downloadgdm-1c061b84ffc3e874da825982d18d970556ff74bb.tar.gz
Allow sessions to register with GDM
Recording when sessions start, for Wayland → Xorg fallback or transitioning to the user session, is currently done with timeouts. This isn't ideal, because on some very slow machines the timeout can be hit before the session has had a chance to fail: if gnome-session takes more than 3 seconds to fail then the session will be considered to have exited rather than failed, and so we don't do Xorg fallback. We can do this more reliably if we allow sessions to optionally register themselves with GDM. Then we will know when they've started, so can shut down the greeter or fall back to Xorg as appropriate. The mechanism is that they specify X-GDM-SessionRegisters=true in their file, and then call RegsterSession on the DisplayManager interface on the bus (added in the previous commit) to say that they've started up. If X-GDM-SessionRegisters is missing or false, GDM will call the same method for them after 10 seconds. Closes: #483
Diffstat (limited to 'daemon/gdm-wayland-session.c')
-rw-r--r--daemon/gdm-wayland-session.c81
1 files changed, 63 insertions, 18 deletions
diff --git a/daemon/gdm-wayland-session.c b/daemon/gdm-wayland-session.c
index 94f49e19..35679b19 100644
--- a/daemon/gdm-wayland-session.c
+++ b/daemon/gdm-wayland-session.c
@@ -45,6 +45,7 @@ typedef struct
GSubprocess *bus_subprocess;
GDBusConnection *bus_connection;
+ GdmDBusManager *display_manager_proxy;
char *bus_address;
char **environment;
@@ -53,6 +54,8 @@ typedef struct
char *session_command;
int session_exit_status;
+ guint register_session_id;
+
GMainLoop *main_loop;
guint32 debug_enabled : 1;
@@ -385,29 +388,14 @@ static gboolean
register_display (State *state,
GCancellable *cancellable)
{
- GdmDBusManager *manager = NULL;
GError *error = NULL;
gboolean registered = FALSE;
GVariantBuilder details;
- manager = gdm_dbus_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- "org.gnome.DisplayManager",
- "/org/gnome/DisplayManager/Manager",
- cancellable,
- &error);
-
- if (!manager) {
- g_debug ("could not contact display manager: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
g_variant_builder_init (&details, G_VARIANT_TYPE ("a{ss}"));
g_variant_builder_add (&details, "{ss}", "session-type", "wayland");
- registered = gdm_dbus_manager_call_register_display_sync (manager,
+ registered = gdm_dbus_manager_call_register_display_sync (state->display_manager_proxy,
g_variant_builder_end (&details),
cancellable,
&error);
@@ -416,8 +404,6 @@ register_display (State *state,
g_error_free (error);
}
-out:
- g_clear_object (&manager);
return registered;
}
@@ -439,6 +425,7 @@ clear_state (State **out_state)
g_clear_object (&state->session_subprocess);
g_clear_pointer (&state->environment, g_strfreev);
g_clear_pointer (&state->main_loop, g_main_loop_unref);
+ g_clear_handle_id (&state->register_session_id, g_source_remove);
*out_state = NULL;
}
@@ -454,6 +441,49 @@ on_sigterm (State *state)
return G_SOURCE_CONTINUE;
}
+static gboolean
+register_session_timeout_cb (gpointer user_data)
+{
+ State *state;
+ GError *error = NULL;
+
+ state = (State *) user_data;
+
+ gdm_dbus_manager_call_register_session_sync (state->display_manager_proxy,
+ g_variant_new ("a{sv}", NULL),
+ state->cancellable,
+ &error);
+
+ if (error != NULL) {
+ g_warning ("Could not register session: %s", error->message);
+ g_error_free (error);
+ }
+
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean
+connect_to_display_manager (State *state)
+{
+ g_autoptr (GError) error = NULL;
+
+ state->display_manager_proxy = gdm_dbus_manager_proxy_new_for_bus_sync (
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ "org.gnome.DisplayManager",
+ "/org/gnome/DisplayManager/Manager",
+ state->cancellable,
+ &error);
+
+ if (state->display_manager_proxy == NULL) {
+ g_printerr ("gdm-wayland-session: could not contact display manager: %s\n",
+ error->message);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
int
main (int argc,
char **argv)
@@ -464,7 +494,10 @@ main (int argc,
gboolean debug = FALSE;
gboolean ret;
int exit_status = EX_OK;
+ static gboolean register_session = FALSE;
+
static GOptionEntry entries [] = {
+ { "register-session", 0, 0, G_OPTION_ARG_NONE, &register_session, "Register session after a delay", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, "", "" },
{ NULL }
};
@@ -528,6 +561,9 @@ main (int argc,
goto out;
}
+ if (!connect_to_display_manager (state))
+ goto out;
+
ret = register_display (state, state->cancellable);
if (!ret) {
@@ -536,6 +572,15 @@ main (int argc,
goto out;
}
+ if (register_session) {
+ g_debug ("gdm-wayland-session: Will register session in %d seconds", REGISTER_SESSION_TIMEOUT);
+ state->register_session_id = g_timeout_add_seconds (REGISTER_SESSION_TIMEOUT,
+ register_session_timeout_cb,
+ state);
+ } else {
+ g_debug ("gdm-wayland-session: Session will register itself");
+ }
+
g_main_loop_run (state->main_loop);
/* Only use exit status of session if we're here because it exit */