From: Zbigniew Jędrzejewski-Szmek Date: Tue, 1 Oct 2019 12:58:55 +0000 (+0200) Subject: core: add helper function to check job status X-Git-Tag: v244-rc1~234^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28a2dfe8014327a884bef36667c1cf94f547e716;p=thirdparty%2Fsystemd.git core: add helper function to check job status Since job.h includes unit.h, and unit.h includes job.h, imports need to be adjusted to make sure unit.h is included first if the helper is used. --- diff --git a/src/core/dbus-job.h b/src/core/dbus-job.h index c9f6fc71871..380e117fca9 100644 --- a/src/core/dbus-job.h +++ b/src/core/dbus-job.h @@ -4,7 +4,7 @@ #include "sd-bus.h" #include "sd-bus-vtable.h" -#include "job.h" +#include "unit.h" extern const sd_bus_vtable bus_job_vtable[]; diff --git a/src/core/dbus-unit.h b/src/core/dbus-unit.h index 24abf3c088e..91711311a78 100644 --- a/src/core/dbus-unit.h +++ b/src/core/dbus-unit.h @@ -4,7 +4,6 @@ #include "sd-bus.h" #include "sd-bus-vtable.h" -#include "job.h" #include "unit.h" extern const sd_bus_vtable bus_unit_vtable[]; diff --git a/src/core/service.c b/src/core/service.c index 71befcddc83..8e313f8e902 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -2245,7 +2245,7 @@ static void service_enter_restart(Service *s) { assert(s); - if (UNIT(s)->job && UNIT(s)->job->type == JOB_STOP) { + if (unit_has_job_type(UNIT(s), JOB_STOP)) { /* Don't restart things if we are going down anyway */ log_unit_info(UNIT(s), "Stop job pending for unit, delaying automatic restart."); diff --git a/src/core/unit.c b/src/core/unit.c index b9fb7dbc0e1..71fe7a6e236 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -4022,7 +4022,7 @@ bool unit_stop_pending(Unit *u) { * different from unit_inactive_or_pending() which checks both * the current state and for a queued job. */ - return u->job && u->job->type == JOB_STOP; + return unit_has_job_type(u, JOB_STOP); } bool unit_inactive_or_pending(Unit *u) { @@ -4057,12 +4057,7 @@ bool unit_active_or_pending(Unit *u) { bool unit_will_restart_default(Unit *u) { assert(u); - if (!u->job) - return false; - if (u->job->type == JOB_START) - return true; - - return false; + return unit_has_job_type(u, JOB_START); } bool unit_will_restart(Unit *u) { diff --git a/src/core/unit.h b/src/core/unit.h index 3b0042a9ebe..793ee638a6a 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -842,6 +842,10 @@ const char *unit_label_path(Unit *u); int unit_pid_attachable(Unit *unit, pid_t pid, sd_bus_error *error); +static inline bool unit_has_job_type(Unit *u, JobType type) { + return u && u->job && u->job->type == type; +} + /* unit_log_skip is for cases like ExecCondition= where a unit is considered "done" * after some execution, rather than succeeded or failed. */ void unit_log_skip(Unit *u, const char *result); diff --git a/src/test/test-engine.c b/src/test/test-engine.c index 633cc425345..10648114971 100644 --- a/src/test/test-engine.c +++ b/src/test/test-engine.c @@ -106,9 +106,9 @@ int main(int argc, char *argv[]) { printf("Test11: (Start/stop job ordering, execution cycle)\n"); assert_se(manager_add_job(m, JOB_START, i, JOB_FAIL, NULL, NULL, &j) == 0); - assert_se(a->job && a->job->type == JOB_STOP); - assert_se(d->job && d->job->type == JOB_STOP); - assert_se(b->job && b->job->type == JOB_START); + assert_se(unit_has_job_type(a, JOB_STOP)); + assert_se(unit_has_job_type(d, JOB_STOP)); + assert_se(unit_has_job_type(b, JOB_START)); manager_dump_jobs(m, stdout, "\t"); printf("Load6:\n"); diff --git a/src/test/test-job-type.c b/src/test/test-job-type.c index d51e0d94fd3..33a95c6b52e 100644 --- a/src/test/test-job-type.c +++ b/src/test/test-job-type.c @@ -2,7 +2,6 @@ #include -#include "job.h" #include "service.h" #include "unit.h"