naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
6c7d9c
From 1d225dbe60540867624da8f099852881f28f4293 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
6c7d9c
Subject: [PATCH] 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
6c7d9c
index f3c1a028316..7d5c288ea41 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
6c7d9c
index b1a4d0bf181..93cf711de42 100644
505ca8
--- a/src/core/service.c
505ca8
+++ b/src/core/service.c
6c7d9c
@@ -1105,8 +1105,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) {
6c7d9c
@@ -3521,10 +3520,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
 
6c7d9c
@@ -3532,6 +3527,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",
6c7d9c
@@ -4576,7 +4580,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
6c7d9c
index e209efd4a66..53273b5984b 100644
505ca8
--- a/src/core/unit.c
505ca8
+++ b/src/core/unit.c
6c7d9c
@@ -2559,8 +2559,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
6c7d9c
index 02b2b24206f..f040e9dfe6f 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);