Remove the list of units and create D-Bus proxy only for wanted targets
authorFrancisco Redondo Marchena <francisco.marchena@codethink.co.uk>
Thu, 9 Aug 2012 14:40:47 +0000 (15:40 +0100)
committerJonathan Maw <jonathan.maw@codethink.co.uk>
Thu, 9 Aug 2012 16:13:47 +0000 (17:13 +0100)
Remove the list of units which is not longer used.
When the TargetStarterMonitor receives a "job-removed" signal it
creates a D-Bus proxy to monitor the unit and check if the state
changes to "active". If it does the TargetStartupMonitor sets the node
state.

The TargetStarterMonitor is only interested in monitoring
"focussed.target", "unfocussed.target" and "lazy.target" units. To
avoid creating the D-Bus proxy for unneeded units, it should check in
target_startup_monitor_job_removed if the unit is a unit which has to be
monitored.

NEWS
node-startup-controller/target-startup-monitor.c

diff --git a/NEWS b/NEWS
index f564bf5..34f355b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ x.y.z
   Universal (CC0 1.0)
 * Fixed NodeStartupControllerApplication's SIGINT handler redundantly
   quitting the application and not cancelling the LUCStarter.
+* The TargetStartupMonitor now only monitors its targets, not every
+  unit whose state changes.
 
 0.9.1
 =====
index 33cf463..1b5db78 100644 (file)
@@ -110,9 +110,6 @@ struct _TargetStartupMonitor
 
   NSMLifecycleControl *nsm_lifecycle_control;
 
-  /* list of systemd units for the targets we are interested in */
-  GList               *units;
-
   /* map of systemd target names to corresponding node states */
   GHashTable          *targets_to_states;
 };
@@ -206,18 +203,6 @@ static void
 target_startup_monitor_finalize (GObject *object)
 {
   TargetStartupMonitor *monitor = TARGET_STARTUP_MONITOR (object);
-  GList                *lp;
-
-  /* disconnect from all the unit proxies and release them */
-  for (lp = monitor->units; lp != NULL; lp = lp->next)
-    {
-      g_signal_handlers_disconnect_matched (lp->data, G_SIGNAL_MATCH_DATA,
-                                            0, 0, NULL, NULL, monitor);
-      g_object_unref (lp->data);
-    }
-
-  /* release the list of systemd units */
-  g_list_free (monitor->units);
 
   /* release the mapping of systemd targets to node states */
   g_hash_table_destroy (monitor->targets_to_states);
@@ -294,16 +279,18 @@ target_startup_monitor_job_removed (SystemdManager       *manager,
   g_return_if_fail (result != NULL && *result != '\0');
   g_return_if_fail (IS_TARGET_STARTUP_MONITOR (monitor));
 
-  /* create a temporary struct to bundle information about the unit */
-  data = g_slice_new0 (GetUnitData);
-  data->monitor = g_object_ref (monitor);
-  data->unit_name = g_strdup (unit);
-
-  /* ask systemd to return the object path for this unit */
-  systemd_manager_call_get_unit (monitor->systemd_manager, unit, NULL,
-                                 target_startup_monitor_get_unit_finish, data);
-
-
+  /* check if the unit corresponds to one which has to be monitored */
+  if (g_hash_table_lookup_extended (monitor->targets_to_states, unit, NULL, NULL))
+    {
+      /* create a temporary struct to bundle information about the unit */
+      data = g_slice_new0 (GetUnitData);
+      data->monitor = g_object_ref (monitor);
+      data->unit_name = g_strdup (unit);
+
+      /* ask systemd to return the object path for this unit */
+      systemd_manager_call_get_unit (monitor->systemd_manager, unit, NULL,
+                                     target_startup_monitor_get_unit_finish, data);
+    }
 }