unit: disable retroactive starting/stopping of units when deserializing

This commit is contained in:
Lennart Poettering 2010-07-13 19:01:20 +02:00
parent 4c633005ea
commit 9f611ad82e
4 changed files with 28 additions and 9 deletions

View 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);

View file

@ -192,7 +192,7 @@ struct Manager {
bool utmp_reboot_written:1;
bool deserializing:1;
int n_deserializing;
bool show_status;
bool confirm_spawn;

View 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;

View 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))