diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-06 16:50:54 +0300 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-06 16:54:00 +0300 |
commit | 49f3fffd94591bdf2bd6c2233a9300daeab79566 (patch) | |
tree | e5e43f4adaa79a86e6cd808241a32f53746cf1be /src/machine/machine.c | |
parent | e5a840c93ac8a175a61fc5944d260127ff2247cc (diff) |
machined: rework state tracking logic for machines
This splits up the stopping logic for machines into two steps: first on
machine_stop() we begin with the shutdown of a machine by queuing the
stop method call for it. Then, in machine_finalize() we actually remove
the rest of its runtime context. This mimics closely how sessions are
handled in logind.
This also reworks the GC logic to strictly check the current state of
the machine unit, rather than shortcutting a few cases, like for example
assuming that UnitRemoved really means a machine is gone (which it isn't
since Reloading might trigger it, see #376).
Fixes #376.
Diffstat (limited to 'src/machine/machine.c')
-rw-r--r-- | src/machine/machine.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/machine/machine.c b/src/machine/machine.c index 4fd56a11ae..f045159d41 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -419,7 +419,19 @@ static int machine_stop_scope(Machine *m) { } int machine_stop(Machine *m) { - int r = 0, k; + int r; + assert(m); + + r = machine_stop_scope(m); + + m->stopping = true; + + machine_save(m); + + return r; +} + +int machine_finalize(Machine *m) { assert(m); if (m->started) @@ -430,20 +442,15 @@ int machine_stop(Machine *m) { LOG_MESSAGE("Machine %s terminated.", m->name), NULL); - /* Kill cgroup */ - k = machine_stop_scope(m); - if (k < 0) - r = k; - machine_unlink(m); machine_add_to_gc_queue(m); - if (m->started) + if (m->started) { machine_send_signal(m, false); + m->started = false; + } - m->started = false; - - return r; + return 0; } bool machine_check_gc(Machine *m, bool drop_not_started) { @@ -474,8 +481,11 @@ void machine_add_to_gc_queue(Machine *m) { MachineState machine_get_state(Machine *s) { assert(s); + if (s->stopping) + return MACHINE_CLOSING; + if (s->scope_job) - return s->started ? MACHINE_OPENING : MACHINE_CLOSING; + return MACHINE_OPENING; return MACHINE_RUNNING; } |