]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: add helper function to check job status
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Oct 2019 12:58:55 +0000 (14:58 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Oct 2019 13:05:27 +0000 (15:05 +0200)
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.

src/core/dbus-job.h
src/core/dbus-unit.h
src/core/service.c
src/core/unit.c
src/core/unit.h
src/test/test-engine.c
src/test/test-job-type.c

index c9f6fc718719861cd6e8fae308843fcb17fc1003..380e117fca9141418c1ee14cd4f1f352a5a38ede 100644 (file)
@@ -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[];
 
index 24abf3c088e9226f2bdb9a37abc5b9bc29bb2292..91711311a7836b9f7aae865dd7a798a41b3c0569 100644 (file)
@@ -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[];
index 71befcddc835404f0fd59518f534f6a53977d716..8e313f8e902a91ccb897491938816d87e45d9d9a 100644 (file)
@@ -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.");
 
index b9fb7dbc0e134cd94b9b6610d4c83e3b26a99ecb..71fe7a6e2367486cbdce1b6b427c8f71c61c25fa 100644 (file)
@@ -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) {
index 3b0042a9ebe91d9468b254bc1ff572507a833320..793ee638a6ace5697b6429d10efb66d79f39fee8 100644 (file)
@@ -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);
index 633cc425345d8d8bc7e0da8ef5797d58480e0583..10648114971c0bd42b5de145b10fe6739ce40083 100644 (file)
@@ -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");
index d51e0d94fd36a1438e72e5f271ba4e63653b8aff..33a95c6b52ebfa104f706b97e2b0139793887918 100644 (file)
@@ -2,7 +2,6 @@
 
 #include <stdio.h>
 
-#include "job.h"
 #include "service.h"
 #include "unit.h"