]> err.no Git - systemd/commitdiff
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 9667e299f3f299faa195c4443c98af9eb442a6f4..cdcd6935cdfe5e6d5b3483b5d82d3437781db114 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 0eceab99eaf8037ba4582e47d09a7b69f0357d36..32fbacc4615e1a1094b27a29b63e9c1b2f8e4cc2 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 11e7c3e28d9a7b0a9541de5ed31715520af8d667..e1583384cd8baac11fa0fe5713158ffdbf32a7bf 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 3f42f0fa1172ef5c23c86dbf9f9c7728fc780447..0c92756cb7f7deb93aa2ace3f1a3bd60c10d53cc 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))