From 6e64994d690ccc0359a4a9d20fbead2dbfe23836 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 14 Nov 2018 11:38:51 +0100 Subject: [PATCH] core: make unit_start() return a distinguishable error code in case conditions didn't hold Ideally we'd even propagate this all the way to the client, by having a separate JobType enum value for this. But it's hard to add this without breaking compat, hence for now let's at least internally propagate this case differently from the case "already on it". This is then used to call job_finish_and_invalidate() slightly differently, with the already= parameter false, as in the failed condition case no message was likely produced so far. --- src/core/job.c | 4 +++- src/core/manager.c | 2 +- src/core/unit.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/job.c b/src/core/job.c index 48d60af82b..fc3d8d8308 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -714,8 +714,10 @@ int job_run_and_invalidate(Job *j) { if (j) { if (r == -EAGAIN) job_set_state(j, JOB_WAITING); /* Hmm, not ready after all, let's return to JOB_WAITING state */ - else if (r == -EALREADY) + else if (r == -EALREADY) /* already being executed */ r = job_finish_and_invalidate(j, JOB_DONE, true, true); + else if (r == -ECOMM) /* condition failed, but all is good */ + r = job_finish_and_invalidate(j, JOB_DONE, true, false); else if (r == -EBADR) r = job_finish_and_invalidate(j, JOB_SKIPPED, true, false); else if (r == -ENOEXEC) diff --git a/src/core/manager.c b/src/core/manager.c index 3150740e05..11c353076c 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2138,7 +2138,7 @@ static int manager_dispatch_run_queue(sd_event_source *source, void *userdata) { assert(j->installed); assert(j->in_run_queue); - job_run_and_invalidate(j); + (void) job_run_and_invalidate(j); } if (m->n_running_jobs > 0) diff --git a/src/core/unit.c b/src/core/unit.c index c4d55dc2d3..ab057ada87 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1726,7 +1726,7 @@ int unit_start(Unit *u) { if (state != UNIT_ACTIVATING && !unit_condition_test(u)) { log_unit_debug(u, "Starting requested but condition failed. Not starting unit."); - return -EALREADY; + return -ECOMM; } /* If the asserts failed, fail the entire job */ -- 2.25.1