Start the boot manager D-Bus services in main()
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Wed, 25 Jul 2012 13:45:44 +0000 (14:45 +0100)
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>
Wed, 25 Jul 2012 14:03:00 +0000 (15:03 +0100)
Before we started them in boot_manager_application_constructed() but
that meant that we could not react to errors properly. We now log a
fatal error using the DLT framework and exit if we can't bring up the
D-Bus services.

boot-manager/boot-manager-application.c
boot-manager/la-handler-service.c
boot-manager/main.c

index d78b7f8..ba617e1 100644 (file)
@@ -242,37 +242,17 @@ boot_manager_application_constructed (GObject *object)
   GError                 *error = NULL;
   gchar                  *log_text;
 
-  /* get a bus name on the given connection */
-  application->bus_name_id =
-    g_bus_own_name_on_connection (application->connection, "org.genivi.BootManager1",
-                                  G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL);
-
   /* instantiate the LUC starter */
   application->luc_starter = luc_starter_new (application->job_manager,
                                               application->boot_manager_service);
 
-  /* attempt to start the boot manager service */
-  if (!boot_manager_service_start_up (application->boot_manager_service, &error))
-    {
-      log_text = g_strdup_printf ("Failed to start the boot manager service: %s",
-                                  error->message);
-      DLT_LOG (boot_manager_context, DLT_LOG_ERROR, DLT_STRING (log_text));
-      g_free (log_text);
-      g_clear_error (&error);
-    }
-
   /* restore the LUC if desired */
   luc_starter_start_groups (application->luc_starter);
 
-  /* start the legacy app handler */
-  if (!la_handler_service_start (application->la_handler, &error))
-    {
-      log_text = g_strdup_printf ("Failed to start the legacy app handler service: %s",
-                                  error->message);
-      DLT_LOG (boot_manager_context, DLT_LOG_ERROR, DLT_STRING (log_text));
-      g_free (log_text);
-      g_clear_error (&error);
-    }
+  /* get a bus name on the given connection */
+  application->bus_name_id =
+    g_bus_own_name_on_connection (application->connection, "org.genivi.BootManager1",
+                                  G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL);
 
   /* create a shutdown consumer and implement its LifecycleRequest method */
   application->consumer = shutdown_consumer_skeleton_new ();
index cbe985b..59c3dda 100644 (file)
@@ -537,7 +537,7 @@ la_handler_service_new (GDBusConnection *connection,
 
 gboolean
 la_handler_service_start (LAHandlerService *service,
-                           GError           **error)
+                           GError         **error)
 {
   g_return_val_if_fail (LA_HANDLER_IS_SERVICE (service), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
index 312cb41..1fe4766 100644 (file)
@@ -57,6 +57,7 @@ main (int    argc,
   JobManager             *job_manager;
   GMainLoop              *main_loop;
   GError                 *error = NULL;
+  gchar                  *msg;
 
   /* register the application and context in DLT */
   DLT_REGISTER_APP ("BMGR", "GENIVI Boot Manager");
@@ -77,7 +78,9 @@ main (int    argc,
   connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
   if (connection == NULL)
     {
-      g_warning ("Failed to connect to the system bus: %s", error->message);
+      msg = g_strdup_printf ("Failed to connect to the system bus: %s", error->message);
+      DLT_LOG (boot_manager_context, DLT_LOG_FATAL, DLT_STRING (msg));
+      g_free (msg);
 
       /* clean up */
       g_error_free (error);
@@ -94,7 +97,10 @@ main (int    argc,
                                             NULL, &error);
   if (systemd_manager == NULL)
     {
-      g_warning ("Failed to connect to the systemd manager: %s", error->message);
+      msg = g_strdup_printf ("Failed to connect to the systemd manager: %s",
+                             error->message);
+      DLT_LOG (boot_manager_context, DLT_LOG_FATAL, DLT_STRING (msg));
+      g_free (msg);
 
       /* clean up */
       g_error_free (error);
@@ -106,7 +112,10 @@ main (int    argc,
   /* subscribe to the systemd manager */
   if (!systemd_manager_call_subscribe_sync (systemd_manager, NULL, &error))
     {
-      g_warning ("Failed to subscribe to the systemd manager: %s", error->message);
+      msg = g_strdup_printf ("Failed to subscribe to the systemd manager: %s",
+                             error->message);
+      DLT_LOG (boot_manager_context, DLT_LOG_FATAL, DLT_STRING (msg));
+      g_free (msg);
 
       /* clean up */
       g_error_free (error);
@@ -118,18 +127,54 @@ main (int    argc,
   /* instantiate the boot manager service implementation */
   boot_manager_service = boot_manager_service_new (connection);
 
+  /* attempt to start the boot manager service */
+  if (!boot_manager_service_start_up (boot_manager_service, &error))
+    {
+      msg = g_strdup_printf ("Failed to start the boot manager service: %s",
+                             error->message);
+      DLT_LOG (boot_manager_context, DLT_LOG_ERROR, DLT_STRING (msg));
+      g_free (msg);
+
+      /* clean up */
+      g_error_free (error);
+      g_object_unref (boot_manager_service);
+      g_object_unref (systemd_manager);
+      g_object_unref (connection);
+
+      return EXIT_FAILURE;
+    }
+
   /* instantiate the job manager */
   job_manager = job_manager_new (connection, systemd_manager);
 
-  /* start up the target startup monitor */
-  target_startup_monitor = target_startup_monitor_new (systemd_manager);
-
   /* instantiate the legacy app handler */
   la_handler_service = la_handler_service_new (connection, job_manager);
 
+  /* start the legacy app handler */
+  if (!la_handler_service_start (la_handler_service, &error))
+    {
+      msg = g_strdup_printf ("Failed to start the legacy app handler service: %s",
+                             error->message);
+      DLT_LOG (boot_manager_context, DLT_LOG_ERROR, DLT_STRING (msg));
+      g_free (msg);
+
+      /* clean up */
+      g_clear_error (&error);
+      g_object_unref (la_handler_service);
+      g_object_unref (job_manager);
+      g_object_unref (boot_manager_service);
+      g_object_unref (systemd_manager);
+      g_object_unref (connection);
+
+      return EXIT_FAILURE;
+    }
+
   /* create the main loop */
   main_loop = g_main_loop_new (NULL, FALSE);
 
+  /* create the target startup monitor */
+  target_startup_monitor = target_startup_monitor_new (systemd_manager);
+
   /* create and run the main application */
   application = boot_manager_application_new (main_loop, connection, job_manager,
                                               la_handler_service, boot_manager_service);