diff options
Diffstat (limited to 'src/core/job.c')
-rw-r--r-- | src/core/job.c | 85 |
1 files changed, 40 insertions, 45 deletions
diff --git a/src/core/job.c b/src/core/job.c index 9ad1f735f0..8a047df0c3 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -388,38 +388,38 @@ bool job_type_is_redundant(JobType a, UnitActiveState b) { } } -void job_type_collapse(JobType *t, Unit *u) { +JobType job_type_collapse(JobType t, Unit *u) { UnitActiveState s; - switch (*t) { + switch (t) { case JOB_TRY_RESTART: s = unit_active_state(u); if (UNIT_IS_INACTIVE_OR_DEACTIVATING(s)) - *t = JOB_NOP; - else - *t = JOB_RESTART; - break; + return JOB_NOP; + + return JOB_RESTART; case JOB_RELOAD_OR_START: s = unit_active_state(u); if (UNIT_IS_INACTIVE_OR_DEACTIVATING(s)) - *t = JOB_START; - else - *t = JOB_RELOAD; - break; + return JOB_START; + + return JOB_RELOAD; default: - ; + return t; } } int job_type_merge_and_collapse(JobType *a, JobType b, Unit *u) { - JobType t = job_type_lookup_merge(*a, b); + JobType t; + + t = job_type_lookup_merge(*a, b); if (t < 0) return -EEXIST; - *a = t; - job_type_collapse(a, u); + + *a = job_type_collapse(t, u); return 0; } @@ -790,6 +790,24 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) { NULL); } +static void job_fail_dependencies(Unit *u, UnitDependency d) { + Unit *other; + Iterator i; + + assert(u); + + SET_FOREACH(other, u->dependencies[d], i) { + Job *j = other->job; + + if (!j) + continue; + if (!IN_SET(j->type, JOB_START, JOB_VERIFY_ACTIVE)) + continue; + + job_finish_and_invalidate(j, JOB_DEPENDENCY, true); + } +} + int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) { Unit *u; Unit *other; @@ -831,37 +849,14 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) { /* Fail depending jobs on failure */ if (result != JOB_DONE && recursive) { - - if (t == JOB_START || - t == JOB_VERIFY_ACTIVE) { - - SET_FOREACH(other, u->dependencies[UNIT_REQUIRED_BY], i) - if (other->job && - (other->job->type == JOB_START || - other->job->type == JOB_VERIFY_ACTIVE)) - job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true); - - SET_FOREACH(other, u->dependencies[UNIT_BOUND_BY], i) - if (other->job && - (other->job->type == JOB_START || - other->job->type == JOB_VERIFY_ACTIVE)) - job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true); - - SET_FOREACH(other, u->dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i) - if (other->job && - !other->job->override && - (other->job->type == JOB_START || - other->job->type == JOB_VERIFY_ACTIVE)) - job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true); - - } else if (t == JOB_STOP) { - - SET_FOREACH(other, u->dependencies[UNIT_CONFLICTED_BY], i) - if (other->job && - (other->job->type == JOB_START || - other->job->type == JOB_VERIFY_ACTIVE)) - job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true); - } + if (IN_SET(t, JOB_START, JOB_VERIFY_ACTIVE)) { + job_fail_dependencies(u, UNIT_REQUIRED_BY); + job_fail_dependencies(u, UNIT_REQUISITE_OF); + job_fail_dependencies(u, UNIT_BOUND_BY); + job_fail_dependencies(u, UNIT_REQUIRED_BY_OVERRIDABLE); + job_fail_dependencies(u, UNIT_REQUISITE_OF_OVERRIDABLE); + } else if (t == JOB_STOP) + job_fail_dependencies(u, UNIT_CONFLICTED_BY); } /* Trigger OnFailure dependencies that are not generated by |