From: Lennart Poettering Date: Wed, 14 Nov 2018 10:38:51 +0000 (+0100) Subject: core: make unit_start() return a distinguishable error code in case conditions didn... X-Git-Tag: v240~301^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e64994d690ccc0359a4a9d20fbead2dbfe23836;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/core/job.c b/src/core/job.c index 48d60af82bb..fc3d8d8308a 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 3150740e05a..11c353076c7 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 c4d55dc2d3b..ab057ada879 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 */