1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

core: when isolating to a unit, also keep units running that are triggered by units we keep running

Inspired by: #26364

(this might even "fix" #26364, but without debug logs it's hard to make
such claims)

Fixes: #23055
(cherry picked from commit 32d6707dd1)
(cherry picked from commit c973e2295c)
(cherry picked from commit bfe6d1d197)
This commit is contained in:
Lennart Poettering 2023-02-10 13:38:08 +01:00 committed by Luca Boccassi
parent dde473ed45
commit 54b580e1a7

View File

@ -1097,6 +1097,20 @@ fail:
return r; return r;
} }
static bool shall_stop_on_isolate(Transaction *tr, Unit *u) {
assert(tr);
assert(u);
if (u->ignore_on_isolate)
return false;
/* Is there already something listed for this? */
if (hashmap_get(tr->jobs, u))
return false;
return true;
}
int transaction_add_isolate_jobs(Transaction *tr, Manager *m) { int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
Unit *u; Unit *u;
char *k; char *k;
@ -1106,20 +1120,27 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
assert(m); assert(m);
HASHMAP_FOREACH_KEY(u, k, m->units) { HASHMAP_FOREACH_KEY(u, k, m->units) {
Unit *o;
/* ignore aliases */ /* Ignore aliases */
if (u->id != k) if (u->id != k)
continue; continue;
if (u->ignore_on_isolate) /* No need to stop inactive units */
continue;
/* No need to stop inactive jobs */
if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job) if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
continue; continue;
/* Is there already something listed for this? */ if (!shall_stop_on_isolate(tr, u))
if (hashmap_get(tr->jobs, u)) continue;
/* Keep units that are triggered by units we want to keep around. */
bool keep = false;
UNIT_FOREACH_DEPENDENCY(o, u, UNIT_ATOM_TRIGGERED_BY)
if (!shall_stop_on_isolate(tr, o)) {
keep = true;
break;
}
if (keep)
continue; continue;
r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, true, false, false, false, NULL); r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, true, false, false, false, NULL);