diff options
author | Ivan Shapovalov <intelfx100@gmail.com> | 2015-03-07 08:44:52 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-03-07 08:44:57 -0500 |
commit | 6e392c9c45643d106673c6643ac8bf4e65da13c1 (patch) | |
tree | 77cd87fdc7f0e104f2f48fb0ea282111dde94766 /src/core/unit.c | |
parent | 6829cec4dce1b41c895425a120b70d0a3ed677ab (diff) |
core: do not spawn jobs or touch other units during coldplugging
Because the order of coldplugging is not defined, we can reference a
not-yet-coldplugged unit and read its state while it has not yet been
set to a meaningful value.
This way, already active units may get started again.
We fix this by deferring such actions until all units have been at
least somehow coldplugged.
Fixes https://bugs.freedesktop.org/show_bug.cgi?id=88401
Diffstat (limited to 'src/core/unit.c')
-rw-r--r-- | src/core/unit.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/core/unit.c b/src/core/unit.c index b639d686ad..ec4fa82ec1 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2856,27 +2856,34 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) { return 0; } -int unit_coldplug(Unit *u) { +static int unit_add_deserialized_job_coldplug(Unit *u) { + int r; + + r = manager_add_job(u->manager, u->deserialized_job, u, JOB_IGNORE_REQUIREMENTS, false, NULL, NULL); + if (r < 0) + return r; + + u->deserialized_job = _JOB_TYPE_INVALID; + + return 0; +} + +int unit_coldplug(Unit *u, Hashmap *deferred_work) { int r; assert(u); if (UNIT_VTABLE(u)->coldplug) - if ((r = UNIT_VTABLE(u)->coldplug(u)) < 0) + if ((r = UNIT_VTABLE(u)->coldplug(u, deferred_work)) < 0) return r; if (u->job) { r = job_coldplug(u->job); if (r < 0) return r; - } else if (u->deserialized_job >= 0) { + } else if (u->deserialized_job >= 0) /* legacy */ - r = manager_add_job(u->manager, u->deserialized_job, u, JOB_IGNORE_REQUIREMENTS, false, NULL, NULL); - if (r < 0) - return r; - - u->deserialized_job = _JOB_TYPE_INVALID; - } + hashmap_put(deferred_work, u, &unit_add_deserialized_job_coldplug); return 0; } |