X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjob.c;h=8e944b35dbf983f982e4e658bd7d84cd7b65a5c5;hb=a985a8f5477330f79313436a6582154b08192612;hp=e57286fe89171a01a080c3e277d37bfd2608a817;hpb=ac155bb885f9ea8aac3979a6b2686f0c8a9cc6e3;p=elogind.git diff --git a/src/job.c b/src/job.c index e57286fe8..8e944b35d 100644 --- a/src/job.c +++ b/src/job.c @@ -355,6 +355,14 @@ bool job_is_runnable(Job *j) { return true; } +static void job_change_type(Job *j, JobType newtype) { + log_debug("Converting job %s/%s -> %s/%s", + j->unit->id, job_type_to_string(j->type), + j->unit->id, job_type_to_string(newtype)); + + j->type = newtype; +} + int job_run_and_invalidate(Job *j) { int r; uint32_t id; @@ -387,14 +395,21 @@ int job_run_and_invalidate(Job *j) { switch (j->type) { + case JOB_RELOAD_OR_START: + if (unit_active_state(j->unit) == UNIT_ACTIVE) { + job_change_type(j, JOB_RELOAD); + r = unit_reload(j->unit); + break; + } + job_change_type(j, JOB_START); + /* fall through */ + case JOB_START: r = unit_start(j->unit); - /* If this unit cannot be started, then simply - * wait */ + /* If this unit cannot be started, then simply wait */ if (r == -EBADR) r = 0; - break; case JOB_VERIFY_ACTIVE: { @@ -408,11 +423,19 @@ int job_run_and_invalidate(Job *j) { break; } + case JOB_TRY_RESTART: + if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(j->unit))) { + r = -ENOEXEC; + break; + } + job_change_type(j, JOB_RESTART); + /* fall through */ + case JOB_STOP: + case JOB_RESTART: r = unit_stop(j->unit); - /* If this unit cannot stopped, then simply - * wait. */ + /* If this unit cannot stopped, then simply wait. */ if (r == -EBADR) r = 0; break; @@ -421,43 +444,6 @@ int job_run_and_invalidate(Job *j) { r = unit_reload(j->unit); break; - case JOB_RELOAD_OR_START: - if (unit_active_state(j->unit) == UNIT_ACTIVE) { - j->type = JOB_RELOAD; - r = unit_reload(j->unit); - } else { - j->type = JOB_START; - r = unit_start(j->unit); - - if (r == -EBADR) - r = 0; - } - break; - - case JOB_RESTART: { - UnitActiveState t = unit_active_state(j->unit); - if (t == UNIT_INACTIVE || t == UNIT_FAILED || t == UNIT_ACTIVATING) { - j->type = JOB_START; - r = unit_start(j->unit); - } else - r = unit_stop(j->unit); - break; - } - - case JOB_TRY_RESTART: { - UnitActiveState t = unit_active_state(j->unit); - if (t == UNIT_INACTIVE || t == UNIT_FAILED || t == UNIT_DEACTIVATING) - r = -ENOEXEC; - else if (t == UNIT_ACTIVATING) { - j->type = JOB_START; - r = unit_start(j->unit); - } else { - j->type = JOB_RESTART; - r = unit_stop(j->unit); - } - break; - } - default: assert_not_reached("Unknown job type"); } @@ -536,14 +522,10 @@ int job_finish_and_invalidate(Job *j, JobResult result) { job_add_to_dbus_queue(j); /* Patch restart jobs so that they become normal start jobs */ - if (result == JOB_DONE && (j->type == JOB_RESTART || j->type == JOB_TRY_RESTART)) { - - log_debug("Converting job %s/%s -> %s/%s", - j->unit->id, job_type_to_string(j->type), - j->unit->id, job_type_to_string(JOB_START)); + if (result == JOB_DONE && j->type == JOB_RESTART) { + job_change_type(j, JOB_START); j->state = JOB_WAITING; - j->type = JOB_START; job_add_to_run_queue(j);