[gnome-session/wip/benzea/systemd-user-switch: 11/19] manager: Add initilization synchronization point DBus API



commit 630ac14e92417db72877cc41136c6ccefac17b8b
Author: Benjamin Berg <bberg redhat com>
Date:   Sat Apr 20 01:16:17 2019 +0200

    manager: Add initilization synchronization point DBus API
    
    We need to make sure that any XDG application started by gnome-session
    is started after basic initialization is finished (i.e. environment
    variables are set). Note that we end up with only two synchronization
    points between starting XDG applications and systemd units.
    
    The side effect of this is that XDG applications will begin starting up
    at the same time as g-s-d with the planned systemd unit design.

 gnome-session/gsm-manager.c                | 48 ++++++++++++++++++++++++++++++
 gnome-session/org.gnome.SessionManager.xml |  8 +++++
 2 files changed, 56 insertions(+)
---
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index c9eba1f6..3dc6e2d7 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -126,6 +126,8 @@ struct GsmManagerPrivate
 {
         gboolean                failsafe;
         gboolean                systemd_managed;
+        gboolean                systemd_initialized;
+        gboolean                manager_initialized;
         GsmStore               *clients;
         GsmStore               *inhibitors;
         GsmInhibitorFlag        inhibited_actions;
@@ -534,7 +536,15 @@ end_phase (GsmManager *manager)
         case GSM_MANAGER_PHASE_EARLY_INITIALIZATION:
         case GSM_MANAGER_PHASE_PRE_DISPLAY_SERVER:
         case GSM_MANAGER_PHASE_DISPLAY_SERVER:
+                break;
         case GSM_MANAGER_PHASE_INITIALIZATION:
+                manager->priv->manager_initialized = TRUE;
+                /* Wait for systemd if it isn't initialized yet*/
+                if (manager->priv->systemd_managed && !manager->priv->systemd_initialized) {
+                        sd_notify (0, "STATUS=GNOME Session Manager waiting for 
gnome-session-initialized.target (via signal)");
+                        start_next_phase = FALSE;
+                }
+                break;
         case GSM_MANAGER_PHASE_WINDOW_MANAGER:
         case GSM_MANAGER_PHASE_PANEL:
         case GSM_MANAGER_PHASE_DESKTOP:
@@ -2635,6 +2645,42 @@ gsm_manager_setenv (GsmExportedManager    *skeleton,
         return TRUE;
 }
 
+static gboolean
+gsm_manager_initialized (GsmExportedManager    *skeleton,
+                         GDBusMethodInvocation *invocation,
+                         GsmManager            *manager)
+{
+        /* Signaled by helper when gnome-session-initialized.target is reached. */
+        if (!manager->priv->systemd_managed) {
+                g_dbus_method_invocation_return_error (invocation,
+                                                       GSM_MANAGER_ERROR,
+                                                       GSM_MANAGER_ERROR_GENERAL,
+                                                       "Initialized interface is only available when 
gnome-session is managed by systemd");
+        } else if (manager->priv->systemd_initialized) {
+                g_dbus_method_invocation_return_error (invocation,
+                                                       GSM_MANAGER_ERROR,
+                                                       GSM_MANAGER_ERROR_NOT_IN_INITIALIZATION,
+                                                       "Systemd initialization was already signaled");
+        } else if (manager->priv->phase > GSM_MANAGER_PHASE_INITIALIZATION) {
+                g_dbus_method_invocation_return_error (invocation,
+                                                       GSM_MANAGER_ERROR,
+                                                       GSM_MANAGER_ERROR_NOT_IN_INITIALIZATION,
+                                                       "Initialized interface is only available during 
startup");
+        } else {
+                manager->priv->systemd_initialized = TRUE;
+
+                if (manager->priv->manager_initialized) {
+                        g_assert (manager->priv->phase == GSM_MANAGER_PHASE_INITIALIZATION);
+                        manager->priv->phase++;
+                        start_phase (manager);
+                }
+
+                gsm_exported_manager_complete_initialized (skeleton, invocation);
+        }
+
+        return TRUE;
+}
+
 static gboolean
 is_valid_category (int category)
 {
@@ -3232,6 +3278,8 @@ register_manager (GsmManager *manager)
                           G_CALLBACK (gsm_manager_set_reboot_to_firmware_setup), manager);
         g_signal_connect (skeleton, "handle-setenv",
                           G_CALLBACK (gsm_manager_setenv), manager);
+        g_signal_connect (skeleton, "handle-initialized",
+                          G_CALLBACK (gsm_manager_initialized), manager);
         g_signal_connect (skeleton, "handle-shutdown",
                           G_CALLBACK (gsm_manager_shutdown), manager);
         g_signal_connect (skeleton, "handle-uninhibit",
diff --git a/gnome-session/org.gnome.SessionManager.xml b/gnome-session/org.gnome.SessionManager.xml
index 51eed3a2..00760dfd 100644
--- a/gnome-session/org.gnome.SessionManager.xml
+++ b/gnome-session/org.gnome.SessionManager.xml
@@ -59,6 +59,14 @@
       </doc:doc>
     </method>
 
+    <method name="Initialized">
+      <doc:doc>
+        <doc:description>
+          <doc:para>Run from systemd to signal that gnome-session-initialized.target has been 
reached.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
     <!-- Running phase interfaces -->
 
     <method name="RegisterClient">


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