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.
This commit is contained in:
+1
-1
@@ -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[];
|
||||
|
||||
|
||||
@@ -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[];
|
||||
|
||||
+1
-1
@@ -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.");
|
||||
|
||||
|
||||
+2
-7
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "job.h"
|
||||
#include "service.h"
|
||||
#include "unit.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user