|
|
505ca8 |
From 51f14e78a2ae0a971af1ce3cfcbbf8ca8250ca22 Mon Sep 17 00:00:00 2001
|
|
|
505ca8 |
From: Anita Zhang <the.anitazha@gmail.com>
|
|
|
505ca8 |
Date: Mon, 11 Jan 2021 20:04:20 -0800
|
|
|
505ca8 |
Subject: [PATCH 1/3] core: update setings on the unit and job as the result of
|
|
|
505ca8 |
ExecCondition=
|
|
|
505ca8 |
|
|
|
505ca8 |
Update ExecCondition= to set Unit->condition_result and return JOB_DONE
|
|
|
505ca8 |
in the Job results if the check fails so as to match the current behavior
|
|
|
505ca8 |
of ConditionXYZ= w.r.t units/jobs dependency checks.
|
|
|
505ca8 |
|
|
|
505ca8 |
Fixes: #18207
|
|
|
505ca8 |
---
|
|
|
505ca8 |
src/core/job.c | 3 +--
|
|
|
505ca8 |
src/core/service.c | 17 ++++++++++-------
|
|
|
505ca8 |
src/core/unit.c | 2 --
|
|
|
505ca8 |
src/core/unit.h | 1 -
|
|
|
505ca8 |
4 files changed, 11 insertions(+), 12 deletions(-)
|
|
|
505ca8 |
|
|
|
505ca8 |
diff --git a/src/core/job.c b/src/core/job.c
|
|
|
505ca8 |
index f3c1a02831..7d5c288ea4 100644
|
|
|
505ca8 |
--- a/src/core/job.c
|
|
|
505ca8 |
+++ b/src/core/job.c
|
|
|
505ca8 |
@@ -882,8 +882,7 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job
|
|
|
505ca8 |
return;
|
|
|
505ca8 |
|
|
|
505ca8 |
/* Show condition check message if the job did not actually do anything due to failed condition. */
|
|
|
505ca8 |
- if ((t == JOB_START && result == JOB_DONE && !u->condition_result) ||
|
|
|
505ca8 |
- (t == JOB_START && result == JOB_SKIPPED)) {
|
|
|
505ca8 |
+ if (t == JOB_START && result == JOB_DONE && !u->condition_result) {
|
|
|
505ca8 |
log_struct(LOG_INFO,
|
|
|
505ca8 |
"MESSAGE=Condition check resulted in %s being skipped.", unit_status_string(u),
|
|
|
505ca8 |
"JOB_ID=%" PRIu32, job_id,
|
|
|
505ca8 |
diff --git a/src/core/service.c b/src/core/service.c
|
|
|
505ca8 |
index d7bdeb7cca..3b144153f4 100644
|
|
|
505ca8 |
--- a/src/core/service.c
|
|
|
505ca8 |
+++ b/src/core/service.c
|
|
|
505ca8 |
@@ -1129,8 +1129,7 @@ static void service_set_state(Service *s, ServiceState state) {
|
|
|
505ca8 |
|
|
|
505ca8 |
unit_notify(UNIT(s), table[old_state], table[state],
|
|
|
505ca8 |
(s->reload_result == SERVICE_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE) |
|
|
|
505ca8 |
- (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0) |
|
|
|
505ca8 |
- (s->result == SERVICE_SKIP_CONDITION ? UNIT_NOTIFY_SKIP_CONDITION : 0));
|
|
|
505ca8 |
+ (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0));
|
|
|
505ca8 |
}
|
|
|
505ca8 |
|
|
|
505ca8 |
static usec_t service_coldplug_timeout(Service *s) {
|
|
|
505ca8 |
@@ -3546,10 +3545,6 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
505ca8 |
} else if (s->control_pid == pid) {
|
|
|
505ca8 |
s->control_pid = 0;
|
|
|
505ca8 |
|
|
|
505ca8 |
- /* ExecCondition= calls that exit with (0, 254] should invoke skip-like behavior instead of failing */
|
|
|
505ca8 |
- if (f == SERVICE_FAILURE_EXIT_CODE && s->state == SERVICE_CONDITION && status < 255)
|
|
|
505ca8 |
- f = SERVICE_SKIP_CONDITION;
|
|
|
505ca8 |
-
|
|
|
505ca8 |
if (s->control_command) {
|
|
|
505ca8 |
exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
|
|
|
505ca8 |
|
|
|
505ca8 |
@@ -3557,6 +3552,15 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
505ca8 |
f = SERVICE_SUCCESS;
|
|
|
505ca8 |
}
|
|
|
505ca8 |
|
|
|
505ca8 |
+ /* ExecCondition= calls that exit with (0, 254] should invoke skip-like behavior instead of failing */
|
|
|
505ca8 |
+ if (s->state == SERVICE_CONDITION) {
|
|
|
505ca8 |
+ if (f == SERVICE_FAILURE_EXIT_CODE && status < 255) {
|
|
|
505ca8 |
+ UNIT(s)->condition_result = false;
|
|
|
505ca8 |
+ f = SERVICE_SKIP_CONDITION;
|
|
|
505ca8 |
+ } else if (f == SERVICE_SUCCESS)
|
|
|
505ca8 |
+ UNIT(s)->condition_result = true;
|
|
|
505ca8 |
+ }
|
|
|
505ca8 |
+
|
|
|
505ca8 |
unit_log_process_exit(
|
|
|
505ca8 |
u,
|
|
|
505ca8 |
"Control process",
|
|
|
505ca8 |
@@ -4601,7 +4605,6 @@ const UnitVTable service_vtable = {
|
|
|
505ca8 |
},
|
|
|
505ca8 |
.finished_start_job = {
|
|
|
505ca8 |
[JOB_FAILED] = "Failed to start %s.",
|
|
|
505ca8 |
- [JOB_SKIPPED] = "Skipped %s.",
|
|
|
505ca8 |
},
|
|
|
505ca8 |
.finished_stop_job = {
|
|
|
505ca8 |
[JOB_DONE] = "Stopped %s.",
|
|
|
505ca8 |
diff --git a/src/core/unit.c b/src/core/unit.c
|
|
|
505ca8 |
index 45a417a090..9614fb84aa 100644
|
|
|
505ca8 |
--- a/src/core/unit.c
|
|
|
505ca8 |
+++ b/src/core/unit.c
|
|
|
505ca8 |
@@ -2561,8 +2561,6 @@ static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags)
|
|
|
505ca8 |
if (UNIT_IS_INACTIVE_OR_FAILED(ns)) {
|
|
|
505ca8 |
if (ns == UNIT_FAILED)
|
|
|
505ca8 |
result = JOB_FAILED;
|
|
|
505ca8 |
- else if (FLAGS_SET(flags, UNIT_NOTIFY_SKIP_CONDITION))
|
|
|
505ca8 |
- result = JOB_SKIPPED;
|
|
|
505ca8 |
else
|
|
|
505ca8 |
result = JOB_DONE;
|
|
|
505ca8 |
|
|
|
505ca8 |
diff --git a/src/core/unit.h b/src/core/unit.h
|
|
|
505ca8 |
index 02b2b24206..f040e9dfe6 100644
|
|
|
505ca8 |
--- a/src/core/unit.h
|
|
|
505ca8 |
+++ b/src/core/unit.h
|
|
|
505ca8 |
@@ -738,7 +738,6 @@ int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t cont
|
|
|
505ca8 |
typedef enum UnitNotifyFlags {
|
|
|
505ca8 |
UNIT_NOTIFY_RELOAD_FAILURE = 1 << 0,
|
|
|
505ca8 |
UNIT_NOTIFY_WILL_AUTO_RESTART = 1 << 1,
|
|
|
505ca8 |
- UNIT_NOTIFY_SKIP_CONDITION = 1 << 2,
|
|
|
505ca8 |
} UnitNotifyFlags;
|
|
|
505ca8 |
|
|
|
505ca8 |
void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags);
|
|
|
505ca8 |
--
|
|
|
505ca8 |
2.29.2
|
|
|
505ca8 |
|