Add 'luc-groups-started' signal to send sd_notify(READY=1) to systemd
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Fri, 27 Jul 2012 11:29:43 +0000 (12:29 +0100)
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Fri, 27 Jul 2012 11:29:43 +0000 (12:29 +0100)
We need to notify systemd when the boot manager process has finished
starting the LUC. What we did so far was to call sd_notify() while
constructing the BootManagerApplication. This commit adds a
'luc-groups-started' signal to LUCStarter. BootManagerApplication now
connects to that in order to call sd_notify() at the right time.

boot-manager/boot-manager-application.c
boot-manager/luc-starter.c

index 09db1b7..0b278e0 100644 (file)
@@ -73,6 +73,8 @@ static void boot_manager_application_set_property                 (GObject
                                                                    guint                   prop_id,
                                                                    const GValue           *value,
                                                                    GParamSpec             *pspec);
+static void boot_manager_application_luc_groups_started           (LUCStarter             *starter,
+                                                                   BootManagerApplication *application);
 
 
 
@@ -264,6 +266,12 @@ boot_manager_application_constructed (GObject *object)
   application->luc_starter = luc_starter_new (application->job_manager,
                                               application->boot_manager_service);
 
+  /* be notified when LUC groups have started so that we can hand
+   * control over to systemd again */
+  g_signal_connect (application->luc_starter, "luc-groups-started",
+                    G_CALLBACK (boot_manager_application_luc_groups_started),
+                    application);
+
   /* restore the LUC if desired */
   luc_starter_start_groups (application->luc_starter);
 
@@ -304,9 +312,6 @@ boot_manager_application_constructed (GObject *object)
                                               boot_manager_application_handle_register_finish,
                                               NULL);
 
-  /* inform systemd that this process has started */
-  sd_notify (0, "READY=1");
-
   /* release the shutdown consumer */
   g_object_unref (consumer);
 }
@@ -508,6 +513,21 @@ boot_manager_application_set_property (GObject      *object,
 
 
 
+static void
+boot_manager_application_luc_groups_started (LUCStarter             *starter,
+                                             BootManagerApplication *application)
+{
+  g_return_if_fail (IS_LUC_STARTER (starter));
+  g_return_if_fail (BOOT_MANAGER_IS_APPLICATION (application));
+
+  /* notify systemd that we have finished starting the LUC and
+   * that it can take over control to start unfocused.target,
+   * lazy.target etc. */
+  sd_notify (0, "READY=1");
+}
+
+
+
 BootManagerApplication *
 boot_manager_application_new (GMainLoop          *main_loop,
                               GDBusConnection    *connection,
index e48980c..48e04b4 100644 (file)
@@ -32,6 +32,15 @@ DLT_IMPORT_CONTEXT (boot_manager_context);
 
 
 
+/* signal identifiers */
+enum
+{
+  SIGNAL_LUC_GROUPS_STARTED,
+  LAST_SIGNAL,
+};
+
+
+
 /* property identifiers */
 enum
 {
@@ -95,6 +104,10 @@ struct _LUCStarter
 
 
 
+static guint luc_starter_signals[LAST_SIGNAL];
+
+
+
 G_DEFINE_TYPE (LUCStarter, luc_starter, G_TYPE_OBJECT);
 
 
@@ -130,6 +143,14 @@ luc_starter_class_init (LUCStarterClass *klass)
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_STRINGS));
+
+  luc_starter_signals[SIGNAL_LUC_GROUPS_STARTED] =
+    g_signal_new ("luc-groups-started",
+                  TYPE_LUC_STARTER,
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 }
 
 
@@ -414,9 +435,18 @@ luc_starter_start_app_finish (JobManager  *manager,
           g_hash_table_remove (starter->start_groups, GINT_TO_POINTER (group));
           g_array_remove_index (starter->start_order, 0);
 
-          /* start the next group if there are any left */
+          /* check if we have more groups to start */
           if (starter->start_order->len > 0)
-            luc_starter_start_next_group (starter);
+            {
+              /* we do, so start the next group now */
+              luc_starter_start_next_group (starter);
+            }
+          else
+            {
+              /* no, we are finished; notify others */
+              g_signal_emit (starter, luc_starter_signals[SIGNAL_LUC_GROUPS_STARTED],
+                             0, NULL);
+            }
         }
     }
 
@@ -487,6 +517,12 @@ luc_starter_check_luc_required_finish (GObject      *object,
           /* LUC is not required, log this information */
           DLT_LOG (boot_manager_context, DLT_LOG_INFO,
                    DLT_STRING ("LUC is not required"));
+
+          /* notify others that we have started the LUC groups; we haven't
+           * in this case but the call of luc_starter_start_groups() may
+           * still want to be notified that the call has been processed */
+          g_signal_emit (starter, luc_starter_signals[SIGNAL_LUC_GROUPS_STARTED],
+                         0, NULL);
         }
     }
 }