From 49f3fffd94591bdf2bd6c2233a9300daeab79566 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 6 Aug 2015 16:50:54 +0300 Subject: 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. --- src/machine/machined.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/machine/machined.c') diff --git a/src/machine/machined.c b/src/machine/machined.c index 9bfe2add54..1eeeaf17a5 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -247,8 +247,16 @@ void manager_gc(Manager *m, bool drop_not_started) { LIST_REMOVE(gc_queue, m->machine_gc_queue, machine); machine->in_gc_queue = false; - if (!machine_check_gc(machine, drop_not_started)) { + /* First, if we are not closing yet, initiate stopping */ + if (!machine_check_gc(machine, drop_not_started) && + machine_get_state(machine) != MACHINE_CLOSING) machine_stop(machine); + + /* Now, the stop stop probably made this referenced + * again, but if it didn't, then it's time to let it + * go entirely. */ + if (!machine_check_gc(machine, drop_not_started)) { + machine_finalize(machine); machine_free(machine); } } -- cgit v1.2.3-54-g00ecf