[gnome-session/wip/benzea/systemd-user-switch: 30/31] main: Enable systemd usage



commit c8166f609ec92dc5124f55a5bd9611d03394518a
Author: Benjamin Berg <bberg redhat com>
Date:   Sat Apr 20 01:29:18 2019 +0200

    main: Enable systemd usage
    
    This flips the switch and enables systemd usage in gnome-session.

 gnome-session/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/gnome-session/main.c b/gnome-session/main.c
index 1de0db50..524ef88b 100644
--- a/gnome-session/main.c
+++ b/gnome-session/main.c
@@ -49,6 +49,7 @@
 
 #define GSM_DBUS_NAME "org.gnome.SessionManager"
 
+static gboolean systemd = USE_SYSTEMD_SESSION;
 static gboolean failsafe = FALSE;
 static gboolean show_version = FALSE;
 static gboolean debug = FALSE;
@@ -139,7 +140,7 @@ create_manager (void)
         GsmStore *client_store;
 
         client_store = gsm_store_new ();
-        manager = gsm_manager_new (client_store, failsafe, FALSE);
+        manager = gsm_manager_new (client_store, failsafe, systemd);
         g_object_unref (client_store);
 
         g_unix_signal_add (SIGTERM, term_or_int_signal_cb, manager);
@@ -384,6 +385,11 @@ main (int argc, char **argv)
         guint             name_owner_id;
         GOptionContext   *options;
         static GOptionEntry entries[] = {
+#ifdef ENABLE_SYSTEMD_SESSION
+                { "systemd-service", 0, 0, G_OPTION_ARG_NONE, &systemd, N_("Running as systemd service"), 
NULL },
+                { "systemd", 0, 0, G_OPTION_ARG_NONE, &systemd, N_("Use systemd session management"), NULL },
+#endif
+                { "builtin", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &systemd, N_("Use builtin session 
management (rather than the systemd based one)"), NULL },
                 { "autostart", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &override_autostart_dirs, N_("Override 
standard autostart directories"), N_("AUTOSTART_DIR") },
                 { "session", 0, 0, G_OPTION_ARG_STRING, &opt_session_name, N_("Session to use"), 
N_("SESSION_NAME") },
                 { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
@@ -452,7 +458,12 @@ main (int argc, char **argv)
         gdm_log_init ();
         gdm_log_set_debug (debug);
 
-        if (disable_acceleration_check) {
+        if (systemd) {
+                /* XXX: This is an optimization, but we actually need to do
+                 *      it right now as the DISPLAY environment might leak
+                 *      into the new session from an old run. */
+                g_debug ("hardware acceleration already done if needed");
+        } else if (disable_acceleration_check) {
                 g_debug ("hardware acceleration check is disabled");
         } else {
                 /* Check GL, if it doesn't work out then force software fallback */
@@ -511,10 +522,40 @@ main (int argc, char **argv)
 
         gsm_util_export_activation_environment (NULL);
 
+        session_name = opt_session_name;
+
 #ifdef HAVE_SYSTEMD
         gsm_util_export_user_environment (NULL);
 #endif
 
+#ifdef ENABLE_SYSTEMD_SESSION
+        if (!systemd) {
+                g_autoptr(GError) error = NULL;
+                g_autofree gchar *gnome_session_target;
+                const gchar *session_type;
+
+                session_type = g_getenv ("XDG_SESSION_TYPE");
+
+                /* We really need to resolve the session name at this point,
+                 * which requires talking to GSettings internally. */
+                if (IS_STRING_EMPTY (session_name)) {
+                        session_name = _gsm_manager_get_default_session (NULL);
+                }
+
+                /* We don't escape the name (i.e. we leave any '-' intact). */
+                gnome_session_target = g_strdup_printf ("gnome-session-%s@%s.target", session_type, 
session_name);
+                if (gsm_util_start_systemd_unit (gnome_session_target, "fail", &error)) {
+                        /* We started the unit, open fifo and sleep forever. */
+                        systemd_leader_run ();
+                        exit(0);
+                }
+
+                /* We could not start the unit, fall back. */
+                 g_warning ("Falling back to non-systemd startup procedure due to error: %s", 
error->message);
+                 systemd = FALSE;
+        }
+#endif /* ENABLE_SYSTEMD_SESSION */
+
         {
                 gchar *ibus_path;
 


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