X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=job.c;h=1d59bcb27f7d99504a3bfbfed9b305e0eca32214;hp=4784d9c05dbc200ae81853b9b026129690b0af8b;hb=64c1b5bf9c5777261bdf4058b6cd1cb5de193d5b;hpb=a7334b0952ab66c17ee787e36e6d2c5ceb387de6 diff --git a/job.c b/job.c index 4784d9c05..1d59bcb27 100644 --- a/job.c +++ b/job.c @@ -29,6 +29,7 @@ #include "load-fragment.h" #include "load-dropin.h" #include "log.h" +#include "dbus-job.h" Job* job_new(Manager *m, JobType type, Unit *unit) { Job *j; @@ -55,15 +56,25 @@ void job_free(Job *j) { /* Detach from next 'bigger' objects */ if (j->installed) { - if (j->unit->meta.job == j) + bus_job_send_removed_signal(j); + + if (j->unit->meta.job == j) { j->unit->meta.job = NULL; + unit_add_to_gc_queue(j->unit); + } hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id)); j->installed = false; } /* Detach from next 'smaller' objects */ - manager_transaction_unlink_job(j->manager, j); + manager_transaction_unlink_job(j->manager, j, true); + + if (j->in_run_queue) + LIST_REMOVE(Job, run_queue, j->manager->run_queue, j); + + if (j->in_dbus_queue) + LIST_REMOVE(Job, dbus_queue, j->manager->dbus_job_queue, j); free(j); } @@ -139,14 +150,14 @@ void job_dump(Job *j, FILE*f, const char *prefix) { assert(f); fprintf(f, - "%s→ Job %u:\n" - "%s\tAction: %s → %s\n" + "%s-> Job %u:\n" + "%s\tAction: %s -> %s\n" "%s\tState: %s\n" "%s\tForced: %s\n", prefix, j->id, - prefix, unit_id(j->unit), job_type_to_string(j->type), + prefix, j->unit->meta.id, job_type_to_string(j->type), prefix, job_state_to_string(j->state), - prefix, yes_no(j->forced)); + prefix, yes_no(j->override)); } bool job_is_anchor(Job *j) { @@ -257,6 +268,45 @@ bool job_type_is_conflicting(JobType a, JobType b) { return (a == JOB_STOP) != (b == JOB_STOP); } +bool job_type_is_redundant(JobType a, UnitActiveState b) { + switch (a) { + + case JOB_START: + return + b == UNIT_ACTIVE || + b == UNIT_ACTIVE_RELOADING; + + case JOB_STOP: + return + b == UNIT_INACTIVE; + + case JOB_VERIFY_ACTIVE: + return + b == UNIT_ACTIVE || + b == UNIT_ACTIVE_RELOADING; + + case JOB_RELOAD: + return + b == UNIT_ACTIVE_RELOADING; + + case JOB_RELOAD_OR_START: + return + b == UNIT_ACTIVATING || + b == UNIT_ACTIVE_RELOADING; + + case JOB_RESTART: + return + b == UNIT_ACTIVATING; + + case JOB_TRY_RESTART: + return + b == UNIT_ACTIVATING; + + default: + assert_not_reached("Invalid job type"); + } +} + bool job_is_runnable(Job *j) { Iterator i; Unit *other; @@ -326,6 +376,7 @@ int job_run_and_invalidate(Job *j) { return -EAGAIN; j->state = JOB_RUNNING; + job_add_to_dbus_queue(j); switch (j->type) { @@ -401,25 +452,26 @@ int job_run_and_invalidate(Job *j) { int job_finish_and_invalidate(Job *j, bool success) { Unit *u; Unit *other; - UnitType t; + JobType t; Iterator i; assert(j); assert(j->installed); - log_debug("Job %s/%s finished, success=%s", unit_id(j->unit), job_type_to_string(j->type), yes_no(success)); + log_debug("Job %s/%s finished, success=%s", j->unit->meta.id, job_type_to_string(j->type), yes_no(success)); + job_add_to_dbus_queue(j); /* Patch restart jobs so that they become normal start jobs */ if (success && (j->type == JOB_RESTART || j->type == JOB_TRY_RESTART)) { - log_debug("Converting job %s/%s → %s/%s", - unit_id(j->unit), job_type_to_string(j->type), - unit_id(j->unit), job_type_to_string(JOB_START)); + log_debug("Converting job %s/%s -> %s/%s", + j->unit->meta.id, job_type_to_string(j->type), + j->unit->meta.id, job_type_to_string(JOB_START)); j->state = JOB_RUNNING; j->type = JOB_START; - job_schedule_run(j); + job_add_to_run_queue(j); return 0; } @@ -436,26 +488,26 @@ int job_finish_and_invalidate(Job *j, bool success) { SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i) if (other->meta.job && - (other->meta.type == JOB_START || - other->meta.type == JOB_VERIFY_ACTIVE || - other->meta.type == JOB_RELOAD_OR_START)) + (other->meta.job->type == JOB_START || + other->meta.job->type == JOB_VERIFY_ACTIVE || + other->meta.job->type == JOB_RELOAD_OR_START)) job_finish_and_invalidate(other->meta.job, false); - SET_FOREACH(other, u->meta.dependencies[UNIT_SOFT_REQUIRED_BY], i) + SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i) if (other->meta.job && - !other->meta.job->forced && - (other->meta.type == JOB_START || - other->meta.type == JOB_VERIFY_ACTIVE || - other->meta.type == JOB_RELOAD_OR_START)) + !other->meta.job->override && + (other->meta.job->type == JOB_START || + other->meta.job->type == JOB_VERIFY_ACTIVE || + other->meta.job->type == JOB_RELOAD_OR_START)) job_finish_and_invalidate(other->meta.job, false); } else if (t == JOB_STOP) { SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i) if (other->meta.job && - (t == JOB_START || - t == JOB_VERIFY_ACTIVE || - t == JOB_RELOAD_OR_START)) + (other->meta.job->type == JOB_START || + other->meta.job->type == JOB_VERIFY_ACTIVE || + other->meta.job->type == JOB_RELOAD_OR_START)) job_finish_and_invalidate(other->meta.job, false); } } @@ -463,15 +515,15 @@ int job_finish_and_invalidate(Job *j, bool success) { /* Try to start the next jobs that can be started */ SET_FOREACH(other, u->meta.dependencies[UNIT_AFTER], i) if (other->meta.job) - job_schedule_run(other->meta.job); + job_add_to_run_queue(other->meta.job); SET_FOREACH(other, u->meta.dependencies[UNIT_BEFORE], i) if (other->meta.job) - job_schedule_run(other->meta.job); + job_add_to_run_queue(other->meta.job); return 0; } -void job_schedule_run(Job *j) { +void job_add_to_run_queue(Job *j) { assert(j); assert(j->installed); @@ -482,6 +534,17 @@ void job_schedule_run(Job *j) { j->in_run_queue = true; } +void job_add_to_dbus_queue(Job *j) { + assert(j); + assert(j->installed); + + if (j->in_dbus_queue) + return; + + LIST_PREPEND(Job, dbus_queue, j->manager->dbus_job_queue, j); + j->in_dbus_queue = true; +} + char *job_dbus_path(Job *j) { char *p; @@ -514,7 +577,8 @@ DEFINE_STRING_TABLE_LOOKUP(job_type, JobType); static const char* const job_mode_table[_JOB_MODE_MAX] = { [JOB_FAIL] = "fail", - [JOB_REPLACE] = "replace" + [JOB_REPLACE] = "replace", + [JOB_ISOLATE] = "isolate" }; DEFINE_STRING_TABLE_LOOKUP(job_mode, JobMode);