Blob Blame History Raw
From 1d225dbe60540867624da8f099852881f28f4293 Mon Sep 17 00:00:00 2001
From: Anita Zhang <the.anitazha@gmail.com>
Date: Mon, 11 Jan 2021 20:04:20 -0800
Subject: [PATCH] core: update setings on the unit and job as the result of
 ExecCondition=

Update ExecCondition= to set Unit->condition_result and return JOB_DONE
in the Job results  if the check fails so as to match the current behavior
of ConditionXYZ= w.r.t units/jobs dependency checks.

Fixes: #18207
---
 src/core/job.c     |  3 +--
 src/core/service.c | 17 ++++++++++-------
 src/core/unit.c    |  2 --
 src/core/unit.h    |  1 -
 4 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/core/job.c b/src/core/job.c
index f3c1a028316..7d5c288ea41 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -882,8 +882,7 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job
                 return;
 
         /* Show condition check message if the job did not actually do anything due to failed condition. */
-        if ((t == JOB_START && result == JOB_DONE && !u->condition_result) ||
-            (t == JOB_START && result == JOB_SKIPPED)) {
+        if (t == JOB_START && result == JOB_DONE && !u->condition_result) {
                 log_struct(LOG_INFO,
                            "MESSAGE=Condition check resulted in %s being skipped.", unit_status_string(u),
                            "JOB_ID=%" PRIu32, job_id,
diff --git a/src/core/service.c b/src/core/service.c
index b1a4d0bf181..93cf711de42 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1105,8 +1105,7 @@ static void service_set_state(Service *s, ServiceState state) {
 
         unit_notify(UNIT(s), table[old_state], table[state],
                     (s->reload_result == SERVICE_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE) |
-                    (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0) |
-                    (s->result == SERVICE_SKIP_CONDITION ? UNIT_NOTIFY_SKIP_CONDITION : 0));
+                    (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0));
 }
 
 static usec_t service_coldplug_timeout(Service *s) {
@@ -3521,10 +3520,6 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         } else if (s->control_pid == pid) {
                 s->control_pid = 0;
 
-                /* ExecCondition= calls that exit with (0, 254] should invoke skip-like behavior instead of failing */
-                if (f == SERVICE_FAILURE_EXIT_CODE && s->state == SERVICE_CONDITION && status < 255)
-                        f = SERVICE_SKIP_CONDITION;
-
                 if (s->control_command) {
                         exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
 
@@ -3532,6 +3527,15 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
                                 f = SERVICE_SUCCESS;
                 }
 
+                /* ExecCondition= calls that exit with (0, 254] should invoke skip-like behavior instead of failing */
+                if (s->state == SERVICE_CONDITION) {
+                        if (f == SERVICE_FAILURE_EXIT_CODE && status < 255) {
+                                UNIT(s)->condition_result = false;
+                                f = SERVICE_SKIP_CONDITION;
+                        } else if (f == SERVICE_SUCCESS)
+                                UNIT(s)->condition_result = true;
+                }
+
                 unit_log_process_exit(
                                 u,
                                 "Control process",
@@ -4576,7 +4580,6 @@ const UnitVTable service_vtable = {
                 },
                 .finished_start_job = {
                         [JOB_FAILED]     = "Failed to start %s.",
-                        [JOB_SKIPPED]    = "Skipped %s.",
                 },
                 .finished_stop_job = {
                         [JOB_DONE]       = "Stopped %s.",
diff --git a/src/core/unit.c b/src/core/unit.c
index e209efd4a66..53273b5984b 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2559,8 +2559,6 @@ static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags)
                         if (UNIT_IS_INACTIVE_OR_FAILED(ns)) {
                                 if (ns == UNIT_FAILED)
                                         result = JOB_FAILED;
-                                else if (FLAGS_SET(flags, UNIT_NOTIFY_SKIP_CONDITION))
-                                        result = JOB_SKIPPED;
                                 else
                                         result = JOB_DONE;
 
diff --git a/src/core/unit.h b/src/core/unit.h
index 02b2b24206f..f040e9dfe6f 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -738,7 +738,6 @@ int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t cont
 typedef enum UnitNotifyFlags {
         UNIT_NOTIFY_RELOAD_FAILURE    = 1 << 0,
         UNIT_NOTIFY_WILL_AUTO_RESTART = 1 << 1,
-        UNIT_NOTIFY_SKIP_CONDITION    = 1 << 2,
 } UnitNotifyFlags;
 
 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags);