chiark / gitweb /
unit: disable retroactive starting/stopping of units when deserializing
authorLennart Poettering <lennart@poettering.net>
Tue, 13 Jul 2010 17:01:20 +0000 (19:01 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 13 Jul 2010 17:01:20 +0000 (19:01 +0200)
src/manager.c
src/manager.h
src/snapshot.c
src/unit.c

index 9667e29..cdcd693 100644 (file)
@@ -544,6 +544,12 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
 
         manager_build_unit_path_cache(m);
 
+        /* If we will deserialize make sure that during enumeration
+         * this is already known, so we increase the counter here
+         * already */
+        if (serialization)
+                m->n_deserializing ++;
+
         /* First, enumerate what we can from all config files */
         r = manager_enumerate(m);
 
@@ -556,6 +562,11 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
         if ((q = manager_coldplug(m)) < 0)
                 r = q;
 
+        if (serialization) {
+                assert(m->n_deserializing > 0);
+                m->n_deserializing --;
+        }
+
         /* Now that the initial devices are available, let's see if we
          * can write the utmp file */
         manager_write_utmp_reboot(m);
@@ -2334,7 +2345,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
 
         log_debug("Deserializing state...");
 
-        m->deserializing = true;
+        m->n_deserializing ++;
 
         for (;;) {
                 Unit *u;
@@ -2366,7 +2377,8 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
         r = 0;
 
 finish:
-        m->deserializing = false;
+        assert(m->n_deserializing > 0);
+        m->n_deserializing --;
 
         return r;
 }
@@ -2402,6 +2414,8 @@ int manager_reload(Manager *m) {
         if ((q = lookup_paths_init(&m->lookup_paths, m->running_as)) < 0)
                 r = q;
 
+        m->n_deserializing ++;
+
         /* First, enumerate what we can from all config files */
         if ((q = manager_enumerate(m)) < 0)
                 r = q;
@@ -2417,6 +2431,9 @@ int manager_reload(Manager *m) {
         if ((q = manager_coldplug(m)) < 0)
                 r = q;
 
+        assert(m->n_deserializing > 0);
+        m->n_deserializing ++;
+
 finish:
         if (f)
                 fclose(f);
index 0eceab9..32fbacc 100644 (file)
@@ -192,7 +192,7 @@ struct Manager {
 
         bool utmp_reboot_written:1;
 
-        bool deserializing:1;
+        int n_deserializing;
 
         bool show_status;
         bool confirm_spawn;
index 11e7c3e..e158338 100644 (file)
@@ -56,7 +56,7 @@ static int snapshot_load(Unit *u) {
 
         /* Make sure that only snapshots created via snapshot_create()
          * can be loaded */
-        if (!s->by_snapshot_create && !s->meta.manager->deserializing)
+        if (!s->by_snapshot_create && s->meta.manager->n_deserializing <= 0)
                 return -ENOENT;
 
         u->meta.load_state = UNIT_LOADED;
index 3f42f0f..0c92756 100644 (file)
@@ -1043,14 +1043,16 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
                         assert_not_reached("Job type unknown");
                 }
 
-                /* If this state change happened without being
-                 * requested by a job, then let's retroactively start
-                 * or stop dependencies */
-
         } else
                 unexpected = true;
 
-        if (unexpected) {
+        /* If this state change happened without being requested by a
+         * job, then let's retroactively start or stop
+         * dependencies. We skip that step when deserializing, since
+         * we don't want to create any additional jobs just because
+         * something is already activated. */
+
+        if (unexpected && u->meta.manager->n_deserializing <= 0) {
                 if (UNIT_IS_INACTIVE_OR_DEACTIVATING(os) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns))
                         retroactively_start_dependencies(u);
                 else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))