richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
c2dfb7
From ab9c835796a27f0fbaee75a90f0311ec456941d8 Mon Sep 17 00:00:00 2001
c2dfb7
From: Anita Zhang <the.anitazha@gmail.com>
c2dfb7
Date: Fri, 28 Jun 2019 17:02:30 -0700
c2dfb7
Subject: [PATCH] core: ExecCondition= for services
c2dfb7
c2dfb7
Closes #10596
c2dfb7
c2dfb7
(cherry picked from commit 31cd5f63ce86a0784c4ef869c4d323a11ff14adc)
c2dfb7
c2dfb7
Resolves: #1737283
c2dfb7
---
c2dfb7
 TODO                                          |  2 -
c2dfb7
 catalog/systemd.catalog.in                    |  7 ++
c2dfb7
 doc/TRANSIENT-SETTINGS.md                     |  1 +
c2dfb7
 man/systemd.service.xml                       | 20 ++++
c2dfb7
 src/basic/unit-def.c                          |  1 +
c2dfb7
 src/basic/unit-def.h                          |  1 +
c2dfb7
 src/core/dbus-service.c                       |  1 +
c2dfb7
 src/core/job.c                                |  3 +-
c2dfb7
 src/core/job.h                                |  2 +-
c2dfb7
 src/core/load-fragment-gperf.gperf.m4         |  1 +
c2dfb7
 src/core/service.c                            | 93 ++++++++++++++++---
c2dfb7
 src/core/service.h                            |  2 +
c2dfb7
 src/core/unit.c                               | 25 ++++-
c2dfb7
 src/core/unit.h                               |  4 +
c2dfb7
 src/shared/bus-unit-util.c                    |  2 +-
c2dfb7
 src/systemd/sd-messages.h                     |  2 +
c2dfb7
 src/test/test-execute.c                       | 50 +++++++++-
c2dfb7
 test/fuzz/fuzz-unit-file/directives.service   |  1 +
c2dfb7
 test/meson.build                              |  2 +
c2dfb7
 .../exec-condition-failed.service             | 11 +++
c2dfb7
 test/test-execute/exec-condition-skip.service | 15 +++
c2dfb7
 21 files changed, 222 insertions(+), 24 deletions(-)
c2dfb7
 create mode 100644 test/test-execute/exec-condition-failed.service
c2dfb7
 create mode 100644 test/test-execute/exec-condition-skip.service
c2dfb7
c2dfb7
diff --git a/TODO b/TODO
c2dfb7
index ff1008accf..8f78000089 100644
c2dfb7
--- a/TODO
c2dfb7
+++ b/TODO
c2dfb7
@@ -626,8 +626,6 @@ Features:
c2dfb7
 
c2dfb7
 * merge unit_kill_common() and unit_kill_context()
c2dfb7
 
c2dfb7
-* introduce ExecCondition= in services
c2dfb7
-
c2dfb7
 * EFI:
c2dfb7
   - honor language efi variables for default language selection (if there are any?)
c2dfb7
   - honor timezone efi variables for default timezone selection (if there are any?)
c2dfb7
diff --git a/catalog/systemd.catalog.in b/catalog/systemd.catalog.in
c2dfb7
index 2492ad2028..dc44414f9d 100644
c2dfb7
--- a/catalog/systemd.catalog.in
c2dfb7
+++ b/catalog/systemd.catalog.in
c2dfb7
@@ -358,6 +358,13 @@ Support: %SUPPORT_URL%
c2dfb7
 
c2dfb7
 The unit @UNIT@ has entered the 'failed' state with result '@UNIT_RESULT@'.
c2dfb7
 
c2dfb7
+-- 0e4284a0caca4bfc81c0bb6786972673
c2dfb7
+Subject: Unit skipped
c2dfb7
+Defined-By: systemd
c2dfb7
+Support: %SUPPORT_URL%
c2dfb7
+
c2dfb7
+The unit @UNIT@ was skipped and has entered the 'dead' state with result '@UNIT_RESULT@'.
c2dfb7
+
c2dfb7
 -- 50876a9db00f4c40bde1a2ad381c3a1b
c2dfb7
 Subject: The system is configured in a way that might cause problems
c2dfb7
 Defined-By: systemd
c2dfb7
diff --git a/doc/TRANSIENT-SETTINGS.md b/doc/TRANSIENT-SETTINGS.md
c2dfb7
index 0b2ad66dcb..23fe84e4d1 100644
c2dfb7
--- a/doc/TRANSIENT-SETTINGS.md
c2dfb7
+++ b/doc/TRANSIENT-SETTINGS.md
c2dfb7
@@ -267,6 +267,7 @@ Most service unit settings are available for transient units.
c2dfb7
 
c2dfb7
 ```
c2dfb7
 ✓ PIDFile=
c2dfb7
+✓ ExecCondition=
c2dfb7
 ✓ ExecStartPre=
c2dfb7
 ✓ ExecStart=
c2dfb7
 ✓ ExecStartPost=
c2dfb7
diff --git a/man/systemd.service.xml b/man/systemd.service.xml
c2dfb7
index 315b80e704..54586d1948 100644
c2dfb7
--- a/man/systemd.service.xml
c2dfb7
+++ b/man/systemd.service.xml
c2dfb7
@@ -414,6 +414,26 @@
c2dfb7
         </listitem>
c2dfb7
       </varlistentry>
c2dfb7
 
c2dfb7
+      <varlistentry>
c2dfb7
+        <term><varname>ExecCondition=</varname></term>
c2dfb7
+        <listitem><para>Optional commands that are executed before the command(s) in <varname>ExecStartPre=</varname>.
c2dfb7
+        Syntax is the same as for <varname>ExecStart=</varname>, except that multiple command lines are allowed and the
c2dfb7
+        commands are executed one after the other, serially.</para>
c2dfb7
+
c2dfb7
+        <para>The behavior is like an <varname>ExecStartPre=</varname> and condition check hybrid: when an
c2dfb7
+        <varname>ExecCondition=</varname> command exits with exit code 1 through 254 (inclusive), the remaining
c2dfb7
+        commands are skipped and the unit is <emphasis>not</emphasis> marked as failed. However, if an
c2dfb7
+        <varname>ExecCondition=</varname> command exits with 255 or abnormally (e.g. timeout, killed by a
c2dfb7
+        signal, etc.), the unit will be considered failed (and remaining commands will be skipped). Exit code of 0 or
c2dfb7
+        those matching <varname>SuccessExitStatus=</varname> will continue execution to the next command(s).</para>
c2dfb7
+
c2dfb7
+        <para>The same recommendations about not running long-running processes in <varname>ExecStartPre=</varname>
c2dfb7
+        also applies to <varname>ExecCondition=</varname>. <varname>ExecCondition=</varname> will also run the commands
c2dfb7
+        in <varname>ExecStopPost=</varname>, as part of stopping the service, in the case of any non-zero or abnormal
c2dfb7
+        exits, like the ones described above.</para>
c2dfb7
+        </listitem>
c2dfb7
+      </varlistentry>
c2dfb7
+
c2dfb7
       <varlistentry>
c2dfb7
         <term><varname>ExecReload=</varname></term>
c2dfb7
         <listitem><para>Commands to execute to trigger a configuration
c2dfb7
diff --git a/src/basic/unit-def.c b/src/basic/unit-def.c
c2dfb7
index ac6a9b37e8..46593f6e65 100644
c2dfb7
--- a/src/basic/unit-def.c
c2dfb7
+++ b/src/basic/unit-def.c
c2dfb7
@@ -162,6 +162,7 @@ DEFINE_STRING_TABLE_LOOKUP(scope_state, ScopeState);
c2dfb7
 
c2dfb7
 static const char* const service_state_table[_SERVICE_STATE_MAX] = {
c2dfb7
         [SERVICE_DEAD] = "dead",
c2dfb7
+        [SERVICE_CONDITION] = "condition",
c2dfb7
         [SERVICE_START_PRE] = "start-pre",
c2dfb7
         [SERVICE_START] = "start",
c2dfb7
         [SERVICE_START_POST] = "start-post",
c2dfb7
diff --git a/src/basic/unit-def.h b/src/basic/unit-def.h
c2dfb7
index d7e2d74669..db397a31ed 100644
c2dfb7
--- a/src/basic/unit-def.h
c2dfb7
+++ b/src/basic/unit-def.h
c2dfb7
@@ -101,6 +101,7 @@ typedef enum ScopeState {
c2dfb7
 
c2dfb7
 typedef enum ServiceState {
c2dfb7
         SERVICE_DEAD,
c2dfb7
+        SERVICE_CONDITION,
c2dfb7
         SERVICE_START_PRE,
c2dfb7
         SERVICE_START,
c2dfb7
         SERVICE_START_POST,
c2dfb7
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
c2dfb7
index 1b4c98c7d2..5f768a77c8 100644
c2dfb7
--- a/src/core/dbus-service.c
c2dfb7
+++ b/src/core/dbus-service.c
c2dfb7
@@ -127,6 +127,7 @@ const sd_bus_vtable bus_service_vtable[] = {
c2dfb7
         SD_BUS_PROPERTY("NRestarts", "u", bus_property_get_unsigned, offsetof(Service, n_restarts), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
c2dfb7
 
c2dfb7
         BUS_EXEC_STATUS_VTABLE("ExecMain", offsetof(Service, main_exec_status), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
c2dfb7
+        BUS_EXEC_COMMAND_LIST_VTABLE("ExecCondition", offsetof(Service, exec_command[SERVICE_EXEC_CONDITION]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
c2dfb7
         BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
c2dfb7
         BUS_EXEC_COMMAND_LIST_VTABLE("ExecStart", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
c2dfb7
         BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPost", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
c2dfb7
diff --git a/src/core/job.c b/src/core/job.c
c2dfb7
index b9eee91cf3..870ec0a387 100644
c2dfb7
--- a/src/core/job.c
c2dfb7
+++ b/src/core/job.c
c2dfb7
@@ -870,7 +870,8 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job
c2dfb7
                 return;
c2dfb7
 
c2dfb7
         /* Show condition check message if the job did not actually do anything due to failed condition. */
c2dfb7
-        if (t == JOB_START && result == JOB_DONE && !u->condition_result) {
c2dfb7
+        if ((t == JOB_START && result == JOB_DONE && !u->condition_result) ||
c2dfb7
+            (t == JOB_START && result == JOB_SKIPPED)) {
c2dfb7
                 log_struct(LOG_INFO,
c2dfb7
                            "MESSAGE=Condition check resulted in %s being skipped.", unit_description(u),
c2dfb7
                            "JOB_ID=%" PRIu32, job_id,
c2dfb7
diff --git a/src/core/job.h b/src/core/job.h
c2dfb7
index 2f5f3f3989..189fea20ca 100644
c2dfb7
--- a/src/core/job.h
c2dfb7
+++ b/src/core/job.h
c2dfb7
@@ -85,7 +85,7 @@ enum JobResult {
c2dfb7
         JOB_TIMEOUT,             /* Job timeout elapsed */
c2dfb7
         JOB_FAILED,              /* Job failed */
c2dfb7
         JOB_DEPENDENCY,          /* A required dependency job did not result in JOB_DONE */
c2dfb7
-        JOB_SKIPPED,             /* Negative result of JOB_VERIFY_ACTIVE */
c2dfb7
+        JOB_SKIPPED,             /* Negative result of JOB_VERIFY_ACTIVE or skip due to ExecCondition= */
c2dfb7
         JOB_INVALID,             /* JOB_RELOAD of inactive unit */
c2dfb7
         JOB_ASSERT,              /* Couldn't start a unit, because an assert didn't hold */
c2dfb7
         JOB_UNSUPPORTED,         /* Couldn't start a unit, because the unit type is not supported on the system */
c2dfb7
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
c2dfb7
index 161c5a2c82..8883818ff2 100644
c2dfb7
--- a/src/core/load-fragment-gperf.gperf.m4
c2dfb7
+++ b/src/core/load-fragment-gperf.gperf.m4
c2dfb7
@@ -291,6 +291,7 @@ Unit.AssertNull,                 config_parse_unit_condition_null,   0,
c2dfb7
 Unit.CollectMode,                config_parse_collect_mode,          0,                             offsetof(Unit, collect_mode)
c2dfb7
 m4_dnl
c2dfb7
 Service.PIDFile,                 config_parse_unit_path_printf,      0,                             offsetof(Service, pid_file)
c2dfb7
+Service.ExecCondition,           config_parse_exec,                  SERVICE_EXEC_CONDITION,        offsetof(Service, exec_command)
c2dfb7
 Service.ExecStartPre,            config_parse_exec,                  SERVICE_EXEC_START_PRE,        offsetof(Service, exec_command)
c2dfb7
 Service.ExecStart,               config_parse_exec,                  SERVICE_EXEC_START,            offsetof(Service, exec_command)
c2dfb7
 Service.ExecStartPost,           config_parse_exec,                  SERVICE_EXEC_START_POST,       offsetof(Service, exec_command)
c2dfb7
diff --git a/src/core/service.c b/src/core/service.c
c2dfb7
index 2c31e70ef6..92be4280f6 100644
c2dfb7
--- a/src/core/service.c
c2dfb7
+++ b/src/core/service.c
c2dfb7
@@ -41,6 +41,7 @@
c2dfb7
 
c2dfb7
 static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
c2dfb7
         [SERVICE_DEAD] = UNIT_INACTIVE,
c2dfb7
+        [SERVICE_CONDITION] = UNIT_ACTIVATING,
c2dfb7
         [SERVICE_START_PRE] = UNIT_ACTIVATING,
c2dfb7
         [SERVICE_START] = UNIT_ACTIVATING,
c2dfb7
         [SERVICE_START_POST] = UNIT_ACTIVATING,
c2dfb7
@@ -62,6 +63,7 @@ static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
c2dfb7
  * consider idle jobs active as soon as we start working on them */
c2dfb7
 static const UnitActiveState state_translation_table_idle[_SERVICE_STATE_MAX] = {
c2dfb7
         [SERVICE_DEAD] = UNIT_INACTIVE,
c2dfb7
+        [SERVICE_CONDITION] = UNIT_ACTIVE,
c2dfb7
         [SERVICE_START_PRE] = UNIT_ACTIVE,
c2dfb7
         [SERVICE_START] = UNIT_ACTIVE,
c2dfb7
         [SERVICE_START_POST] = UNIT_ACTIVE,
c2dfb7
@@ -1024,7 +1026,7 @@ static void service_set_state(Service *s, ServiceState state) {
c2dfb7
         service_unwatch_pid_file(s);
c2dfb7
 
c2dfb7
         if (!IN_SET(state,
c2dfb7
-                    SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
+                    SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
                     SERVICE_RUNNING,
c2dfb7
                     SERVICE_RELOAD,
c2dfb7
                     SERVICE_STOP, SERVICE_STOP_SIGABRT, SERVICE_STOP_SIGTERM, SERVICE_STOP_SIGKILL, SERVICE_STOP_POST,
c2dfb7
@@ -1042,7 +1044,7 @@ static void service_set_state(Service *s, ServiceState state) {
c2dfb7
         }
c2dfb7
 
c2dfb7
         if (!IN_SET(state,
c2dfb7
-                    SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
+                    SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
                     SERVICE_RELOAD,
c2dfb7
                     SERVICE_STOP, SERVICE_STOP_SIGABRT, SERVICE_STOP_SIGTERM, SERVICE_STOP_SIGKILL, SERVICE_STOP_POST,
c2dfb7
                     SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL)) {
c2dfb7
@@ -1057,7 +1059,7 @@ static void service_set_state(Service *s, ServiceState state) {
c2dfb7
         }
c2dfb7
 
c2dfb7
         if (!IN_SET(state,
c2dfb7
-                    SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
+                    SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
                     SERVICE_RUNNING, SERVICE_RELOAD,
c2dfb7
                     SERVICE_STOP, SERVICE_STOP_SIGABRT, SERVICE_STOP_SIGTERM, SERVICE_STOP_SIGKILL, SERVICE_STOP_POST,
c2dfb7
                     SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL) &&
c2dfb7
@@ -1080,7 +1082,8 @@ static void service_set_state(Service *s, ServiceState state) {
c2dfb7
 
c2dfb7
         unit_notify(UNIT(s), table[old_state], table[state],
c2dfb7
                     (s->reload_result == SERVICE_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE) |
c2dfb7
-                    (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0));
c2dfb7
+                    (s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0) |
c2dfb7
+                    (s->result == SERVICE_SKIP_CONDITION ? UNIT_NOTIFY_SKIP_CONDITION : 0));
c2dfb7
 }
c2dfb7
 
c2dfb7
 static usec_t service_coldplug_timeout(Service *s) {
c2dfb7
@@ -1088,6 +1091,7 @@ static usec_t service_coldplug_timeout(Service *s) {
c2dfb7
 
c2dfb7
         switch (s->deserialized_state) {
c2dfb7
 
c2dfb7
+        case SERVICE_CONDITION:
c2dfb7
         case SERVICE_START_PRE:
c2dfb7
         case SERVICE_START:
c2dfb7
         case SERVICE_START_POST:
c2dfb7
@@ -1143,7 +1147,7 @@ static int service_coldplug(Unit *u) {
c2dfb7
         if (s->control_pid > 0 &&
c2dfb7
             pid_is_unwaited(s->control_pid) &&
c2dfb7
             IN_SET(s->deserialized_state,
c2dfb7
-                   SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
+                   SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST,
c2dfb7
                    SERVICE_RELOAD,
c2dfb7
                    SERVICE_STOP, SERVICE_STOP_SIGABRT, SERVICE_STOP_SIGTERM, SERVICE_STOP_SIGKILL, SERVICE_STOP_POST,
c2dfb7
                    SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL)) {
c2dfb7
@@ -1667,6 +1671,7 @@ static bool service_will_restart(Unit *u) {
c2dfb7
 }
c2dfb7
 
c2dfb7
 static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) {
c2dfb7
+        ServiceState end_state;
c2dfb7
         int r;
c2dfb7
 
c2dfb7
         assert(s);
c2dfb7
@@ -1679,10 +1684,16 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
c2dfb7
         if (s->result == SERVICE_SUCCESS)
c2dfb7
                 s->result = f;
c2dfb7
 
c2dfb7
-        if (s->result == SERVICE_SUCCESS)
c2dfb7
+        if (s->result == SERVICE_SUCCESS) {
c2dfb7
                 unit_log_success(UNIT(s));
c2dfb7
-        else
c2dfb7
+                end_state = SERVICE_DEAD;
c2dfb7
+        } else if (s->result == SERVICE_SKIP_CONDITION) {
c2dfb7
+                unit_log_skip(UNIT(s), service_result_to_string(s->result));
c2dfb7
+                end_state = SERVICE_DEAD;
c2dfb7
+        } else {
c2dfb7
                 unit_log_failure(UNIT(s), service_result_to_string(s->result));
c2dfb7
+                end_state = SERVICE_FAILED;
c2dfb7
+        }
c2dfb7
 
c2dfb7
         if (allow_restart && service_shall_restart(s))
c2dfb7
                 s->will_auto_restart = true;
c2dfb7
@@ -1691,7 +1702,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
c2dfb7
          * SERVICE_FAILED/SERVICE_DEAD before entering into SERVICE_AUTO_RESTART. */
c2dfb7
         s->n_keep_fd_store ++;
c2dfb7
 
c2dfb7
-        service_set_state(s, s->result != SERVICE_SUCCESS ? SERVICE_FAILED : SERVICE_DEAD);
c2dfb7
+        service_set_state(s, end_state);
c2dfb7
 
c2dfb7
         if (s->will_auto_restart) {
c2dfb7
                 s->will_auto_restart = false;
c2dfb7
@@ -2110,6 +2121,40 @@ fail:
c2dfb7
         service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
c2dfb7
 }
c2dfb7
 
c2dfb7
+static void service_enter_condition(Service *s) {
c2dfb7
+        int r;
c2dfb7
+
c2dfb7
+        assert(s);
c2dfb7
+
c2dfb7
+        service_unwatch_control_pid(s);
c2dfb7
+
c2dfb7
+        s->control_command = s->exec_command[SERVICE_EXEC_CONDITION];
c2dfb7
+        if (s->control_command) {
c2dfb7
+
c2dfb7
+                unit_warn_leftover_processes(UNIT(s));
c2dfb7
+
c2dfb7
+                s->control_command_id = SERVICE_EXEC_CONDITION;
c2dfb7
+
c2dfb7
+                r = service_spawn(s,
c2dfb7
+                                  s->control_command,
c2dfb7
+                                  s->timeout_start_usec,
c2dfb7
+                                  EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_IS_CONTROL|EXEC_APPLY_TTY_STDIN,
c2dfb7
+                                  &s->control_pid);
c2dfb7
+
c2dfb7
+                if (r < 0)
c2dfb7
+                        goto fail;
c2dfb7
+
c2dfb7
+                service_set_state(s, SERVICE_CONDITION);
c2dfb7
+        } else
c2dfb7
+                service_enter_start_pre(s);
c2dfb7
+
c2dfb7
+        return;
c2dfb7
+
c2dfb7
+fail:
c2dfb7
+        log_unit_warning_errno(UNIT(s), r, "Failed to run 'exec-condition' task: %m");
c2dfb7
+        service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
c2dfb7
+}
c2dfb7
+
c2dfb7
 static void service_enter_restart(Service *s) {
c2dfb7
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
c2dfb7
         int r;
c2dfb7
@@ -2222,7 +2267,7 @@ static void service_run_next_control(Service *s) {
c2dfb7
         s->control_command = s->control_command->command_next;
c2dfb7
         service_unwatch_control_pid(s);
c2dfb7
 
c2dfb7
-        if (IN_SET(s->state, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD))
c2dfb7
+        if (IN_SET(s->state, SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD))
c2dfb7
                 timeout = s->timeout_start_usec;
c2dfb7
         else
c2dfb7
                 timeout = s->timeout_stop_usec;
c2dfb7
@@ -2231,7 +2276,7 @@ static void service_run_next_control(Service *s) {
c2dfb7
                           s->control_command,
c2dfb7
                           timeout,
c2dfb7
                           EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_IS_CONTROL|
c2dfb7
-                          (IN_SET(s->control_command_id, SERVICE_EXEC_START_PRE, SERVICE_EXEC_STOP_POST) ? EXEC_APPLY_TTY_STDIN : 0)|
c2dfb7
+                          (IN_SET(s->control_command_id, SERVICE_EXEC_CONDITION, SERVICE_EXEC_START_PRE, SERVICE_EXEC_STOP_POST) ? EXEC_APPLY_TTY_STDIN : 0)|
c2dfb7
                           (IN_SET(s->control_command_id, SERVICE_EXEC_STOP, SERVICE_EXEC_STOP_POST) ? EXEC_SETENV_RESULT : 0),
c2dfb7
                           &s->control_pid);
c2dfb7
         if (r < 0)
c2dfb7
@@ -2242,7 +2287,7 @@ static void service_run_next_control(Service *s) {
c2dfb7
 fail:
c2dfb7
         log_unit_warning_errno(UNIT(s), r, "Failed to run next control task: %m");
c2dfb7
 
c2dfb7
-        if (IN_SET(s->state, SERVICE_START_PRE, SERVICE_START_POST, SERVICE_STOP))
c2dfb7
+        if (IN_SET(s->state, SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START_POST, SERVICE_STOP))
c2dfb7
                 service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_RESOURCES);
c2dfb7
         else if (s->state == SERVICE_STOP_POST)
c2dfb7
                 service_enter_dead(s, SERVICE_FAILURE_RESOURCES, true);
c2dfb7
@@ -2296,7 +2341,7 @@ static int service_start(Unit *u) {
c2dfb7
                 return -EAGAIN;
c2dfb7
 
c2dfb7
         /* Already on it! */
c2dfb7
-        if (IN_SET(s->state, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST))
c2dfb7
+        if (IN_SET(s->state, SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST))
c2dfb7
                 return 0;
c2dfb7
 
c2dfb7
         /* A service that will be restarted must be stopped first to
c2dfb7
@@ -2344,7 +2389,9 @@ static int service_start(Unit *u) {
c2dfb7
                 s->flush_n_restarts = false;
c2dfb7
         }
c2dfb7
 
c2dfb7
-        service_enter_start_pre(s);
c2dfb7
+        u->reset_accounting = true;
c2dfb7
+
c2dfb7
+        service_enter_condition(s);
c2dfb7
         return 1;
c2dfb7
 }
c2dfb7
 
c2dfb7
@@ -2370,7 +2417,7 @@ static int service_stop(Unit *u) {
c2dfb7
 
c2dfb7
         /* If there's already something running we go directly into
c2dfb7
          * kill mode. */
c2dfb7
-        if (IN_SET(s->state, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST, SERVICE_RELOAD)) {
c2dfb7
+        if (IN_SET(s->state, SERVICE_CONDITION, SERVICE_START_PRE, SERVICE_START, SERVICE_START_POST, SERVICE_RELOAD)) {
c2dfb7
                 service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_SUCCESS);
c2dfb7
                 return 0;
c2dfb7
         }
c2dfb7
@@ -3303,6 +3350,10 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
c2dfb7
         } else if (s->control_pid == pid) {
c2dfb7
                 s->control_pid = 0;
c2dfb7
 
c2dfb7
+                /* ExecCondition= calls that exit with (0, 254] should invoke skip-like behavior instead of failing */
c2dfb7
+                if (f == SERVICE_FAILURE_EXIT_CODE && s->state == SERVICE_CONDITION && status < 255)
c2dfb7
+                        f = SERVICE_SKIP_CONDITION;
c2dfb7
+
c2dfb7
                 if (s->control_command) {
c2dfb7
                         exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
c2dfb7
 
c2dfb7
@@ -3338,6 +3389,13 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
c2dfb7
 
c2dfb7
                         switch (s->state) {
c2dfb7
 
c2dfb7
+                        case SERVICE_CONDITION:
c2dfb7
+                                if (f == SERVICE_SUCCESS)
c2dfb7
+                                        service_enter_start_pre(s);
c2dfb7
+                                else
c2dfb7
+                                        service_enter_signal(s, SERVICE_STOP_SIGTERM, f);
c2dfb7
+                                break;
c2dfb7
+
c2dfb7
                         case SERVICE_START_PRE:
c2dfb7
                                 if (f == SERVICE_SUCCESS)
c2dfb7
                                         service_enter_start(s);
c2dfb7
@@ -3462,9 +3520,10 @@ static int service_dispatch_timer(sd_event_source *source, usec_t usec, void *us
c2dfb7
 
c2dfb7
         switch (s->state) {
c2dfb7
 
c2dfb7
+        case SERVICE_CONDITION:
c2dfb7
         case SERVICE_START_PRE:
c2dfb7
         case SERVICE_START:
c2dfb7
-                log_unit_warning(UNIT(s), "%s operation timed out. Terminating.", s->state == SERVICE_START ? "Start" : "Start-pre");
c2dfb7
+                log_unit_warning(UNIT(s), "%s operation timed out. Terminating.", service_state_to_string(s->state));
c2dfb7
                 service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_TIMEOUT);
c2dfb7
                 break;
c2dfb7
 
c2dfb7
@@ -3975,6 +4034,7 @@ static bool service_needs_console(Unit *u) {
c2dfb7
                 return false;
c2dfb7
 
c2dfb7
         return IN_SET(s->state,
c2dfb7
+                      SERVICE_CONDITION,
c2dfb7
                       SERVICE_START_PRE,
c2dfb7
                       SERVICE_START,
c2dfb7
                       SERVICE_START_POST,
c2dfb7
@@ -4014,6 +4074,7 @@ static const char* const service_type_table[_SERVICE_TYPE_MAX] = {
c2dfb7
 DEFINE_STRING_TABLE_LOOKUP(service_type, ServiceType);
c2dfb7
 
c2dfb7
 static const char* const service_exec_command_table[_SERVICE_EXEC_COMMAND_MAX] = {
c2dfb7
+        [SERVICE_EXEC_CONDITION] = "ExecCondition",
c2dfb7
         [SERVICE_EXEC_START_PRE] = "ExecStartPre",
c2dfb7
         [SERVICE_EXEC_START] = "ExecStart",
c2dfb7
         [SERVICE_EXEC_START_POST] = "ExecStartPost",
c2dfb7
@@ -4043,6 +4104,7 @@ static const char* const service_result_table[_SERVICE_RESULT_MAX] = {
c2dfb7
         [SERVICE_FAILURE_CORE_DUMP] = "core-dump",
c2dfb7
         [SERVICE_FAILURE_WATCHDOG] = "watchdog",
c2dfb7
         [SERVICE_FAILURE_START_LIMIT_HIT] = "start-limit-hit",
c2dfb7
+        [SERVICE_SKIP_CONDITION] = "exec-condition",
c2dfb7
 };
c2dfb7
 
c2dfb7
 DEFINE_STRING_TABLE_LOOKUP(service_result, ServiceResult);
c2dfb7
@@ -4118,6 +4180,7 @@ const UnitVTable service_vtable = {
c2dfb7
                 .finished_start_job = {
c2dfb7
                         [JOB_DONE]       = "Started %s.",
c2dfb7
                         [JOB_FAILED]     = "Failed to start %s.",
c2dfb7
+                        [JOB_SKIPPED]    = "Skipped %s.",
c2dfb7
                 },
c2dfb7
                 .finished_stop_job = {
c2dfb7
                         [JOB_DONE]       = "Stopped %s.",
c2dfb7
diff --git a/src/core/service.h b/src/core/service.h
c2dfb7
index 1206e3cdda..62b78cadf1 100644
c2dfb7
--- a/src/core/service.h
c2dfb7
+++ b/src/core/service.h
c2dfb7
@@ -36,6 +36,7 @@ typedef enum ServiceType {
c2dfb7
 } ServiceType;
c2dfb7
 
c2dfb7
 typedef enum ServiceExecCommand {
c2dfb7
+        SERVICE_EXEC_CONDITION,
c2dfb7
         SERVICE_EXEC_START_PRE,
c2dfb7
         SERVICE_EXEC_START,
c2dfb7
         SERVICE_EXEC_START_POST,
c2dfb7
@@ -67,6 +68,7 @@ typedef enum ServiceResult {
c2dfb7
         SERVICE_FAILURE_CORE_DUMP,
c2dfb7
         SERVICE_FAILURE_WATCHDOG,
c2dfb7
         SERVICE_FAILURE_START_LIMIT_HIT,
c2dfb7
+        SERVICE_SKIP_CONDITION,
c2dfb7
         _SERVICE_RESULT_MAX,
c2dfb7
         _SERVICE_RESULT_INVALID = -1
c2dfb7
 } ServiceResult;
c2dfb7
diff --git a/src/core/unit.c b/src/core/unit.c
c2dfb7
index ccb0106719..61799bf9e3 100644
c2dfb7
--- a/src/core/unit.c
c2dfb7
+++ b/src/core/unit.c
c2dfb7
@@ -2227,6 +2227,7 @@ static void unit_update_on_console(Unit *u) {
c2dfb7
 
c2dfb7
 static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags) {
c2dfb7
         bool unexpected = false;
c2dfb7
+        JobResult result;
c2dfb7
 
c2dfb7
         assert(j);
c2dfb7
 
c2dfb7
@@ -2249,8 +2250,16 @@ static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags)
c2dfb7
                 else if (j->state == JOB_RUNNING && ns != UNIT_ACTIVATING) {
c2dfb7
                         unexpected = true;
c2dfb7
 
c2dfb7
-                        if (UNIT_IS_INACTIVE_OR_FAILED(ns))
c2dfb7
-                                job_finish_and_invalidate(j, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true, false);
c2dfb7
+                        if (UNIT_IS_INACTIVE_OR_FAILED(ns)) {
c2dfb7
+                                if (ns == UNIT_FAILED)
c2dfb7
+                                        result = JOB_FAILED;
c2dfb7
+                                else if (FLAGS_SET(flags, UNIT_NOTIFY_SKIP_CONDITION))
c2dfb7
+                                        result = JOB_SKIPPED;
c2dfb7
+                                else
c2dfb7
+                                        result = JOB_DONE;
c2dfb7
+
c2dfb7
+                                job_finish_and_invalidate(j, result, true, false);
c2dfb7
+                        }
c2dfb7
                 }
c2dfb7
 
c2dfb7
                 break;
c2dfb7
@@ -5484,6 +5493,18 @@ void unit_log_failure(Unit *u, const char *result) {
c2dfb7
                    "UNIT_RESULT=%s", result);
c2dfb7
 }
c2dfb7
 
c2dfb7
+void unit_log_skip(Unit *u, const char *result) {
c2dfb7
+        assert(u);
c2dfb7
+        assert(result);
c2dfb7
+
c2dfb7
+        log_struct(LOG_INFO,
c2dfb7
+                   "MESSAGE_ID=" SD_MESSAGE_UNIT_SKIPPED_STR,
c2dfb7
+                   LOG_UNIT_ID(u),
c2dfb7
+                   LOG_UNIT_INVOCATION_ID(u),
c2dfb7
+                   LOG_UNIT_MESSAGE(u, "Skipped due to '%s'.", result),
c2dfb7
+                   "UNIT_RESULT=%s", result);
c2dfb7
+}
c2dfb7
+
c2dfb7
 static const char* const collect_mode_table[_COLLECT_MODE_MAX] = {
c2dfb7
         [COLLECT_INACTIVE] = "inactive",
c2dfb7
         [COLLECT_INACTIVE_OR_FAILED] = "inactive-or-failed",
c2dfb7
diff --git a/src/core/unit.h b/src/core/unit.h
c2dfb7
index 4ae1b38624..39179f5fd4 100644
c2dfb7
--- a/src/core/unit.h
c2dfb7
+++ b/src/core/unit.h
c2dfb7
@@ -658,6 +658,7 @@ int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t cont
c2dfb7
 typedef enum UnitNotifyFlags {
c2dfb7
         UNIT_NOTIFY_RELOAD_FAILURE    = 1 << 0,
c2dfb7
         UNIT_NOTIFY_WILL_AUTO_RESTART = 1 << 1,
c2dfb7
+        UNIT_NOTIFY_SKIP_CONDITION    = 1 << 2,
c2dfb7
 } UnitNotifyFlags;
c2dfb7
 
c2dfb7
 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags);
c2dfb7
@@ -806,6 +807,9 @@ int unit_pid_attachable(Unit *unit, pid_t pid, sd_bus_error *error);
c2dfb7
 
c2dfb7
 void unit_log_success(Unit *u);
c2dfb7
 void unit_log_failure(Unit *u, const char *result);
c2dfb7
+/* unit_log_skip is for cases like ExecCondition= where a unit is considered "done"
c2dfb7
+ * after some execution, rather than succeeded or failed. */
c2dfb7
+void unit_log_skip(Unit *u, const char *result);
c2dfb7
 
c2dfb7
 /* Macros which append UNIT= or USER_UNIT= to the message */
c2dfb7
 
c2dfb7
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
c2dfb7
index 8f3b463c6b..e0b2cfb170 100644
c2dfb7
--- a/src/shared/bus-unit-util.c
c2dfb7
+++ b/src/shared/bus-unit-util.c
c2dfb7
@@ -1334,7 +1334,7 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
c2dfb7
                 return bus_append_safe_atou(m, field, eq);
c2dfb7
 
c2dfb7
         if (STR_IN_SET(field,
c2dfb7
-                       "ExecStartPre", "ExecStart", "ExecStartPost",
c2dfb7
+                       "ExecCondition", "ExecStartPre", "ExecStart", "ExecStartPost",
c2dfb7
                        "ExecReload", "ExecStop", "ExecStopPost"))
c2dfb7
 
c2dfb7
                 return bus_append_exec_command(m, field, eq);
c2dfb7
diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h
c2dfb7
index e7ef81b597..bdd4fd3974 100644
c2dfb7
--- a/src/systemd/sd-messages.h
c2dfb7
+++ b/src/systemd/sd-messages.h
c2dfb7
@@ -111,6 +111,8 @@ _SD_BEGIN_DECLARATIONS;
c2dfb7
 #define SD_MESSAGE_UNIT_FAILURE_RESULT    SD_ID128_MAKE(d9,b3,73,ed,55,a6,4f,eb,82,42,e0,2d,be,79,a4,9c)
c2dfb7
 #define SD_MESSAGE_UNIT_FAILURE_RESULT_STR \
c2dfb7
                                           SD_ID128_MAKE_STR(d9,b3,73,ed,55,a6,4f,eb,82,42,e0,2d,be,79,a4,9c)
c2dfb7
+#define SD_MESSAGE_UNIT_SKIPPED           SD_ID128_MAKE(0e,42,84,a0,ca,ca,4b,fc,81,c0,bb,67,86,97,26,73)
c2dfb7
+#define SD_MESSAGE_UNIT_SKIPPED_STR       SD_ID128_MAKE_STR(0e,42,84,a0,ca,ca,4b,fc,81,c0,bb,67,86,97,26,73)
c2dfb7
 
c2dfb7
 #define SD_MESSAGE_SPAWN_FAILED           SD_ID128_MAKE(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7)
c2dfb7
 #define SD_MESSAGE_SPAWN_FAILED_STR       SD_ID128_MAKE_STR(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7)
c2dfb7
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
c2dfb7
index e42d0d30a8..882e866ea9 100644
c2dfb7
--- a/src/test/test-execute.c
c2dfb7
+++ b/src/test/test-execute.c
c2dfb7
@@ -30,7 +30,7 @@
c2dfb7
 
c2dfb7
 typedef void (*test_function_t)(Manager *m);
c2dfb7
 
c2dfb7
-static void check(const char *func, Manager *m, Unit *unit, int status_expected, int code_expected) {
c2dfb7
+static void wait_for_service_finish(Manager *m, Unit *unit) {
c2dfb7
         Service *service = NULL;
c2dfb7
         usec_t ts;
c2dfb7
         usec_t timeout = 2 * USEC_PER_MINUTE;
c2dfb7
@@ -55,6 +55,17 @@ static void check(const char *func, Manager *m, Unit *unit, int status_expected,
c2dfb7
                         exit(EXIT_FAILURE);
c2dfb7
                 }
c2dfb7
         }
c2dfb7
+}
c2dfb7
+
c2dfb7
+static void check_main_result(const char *func, Manager *m, Unit *unit, int status_expected, int code_expected) {
c2dfb7
+        Service *service = NULL;
c2dfb7
+
c2dfb7
+        assert_se(m);
c2dfb7
+        assert_se(unit);
c2dfb7
+
c2dfb7
+        wait_for_service_finish(m, unit);
c2dfb7
+
c2dfb7
+        service = SERVICE(unit);
c2dfb7
         exec_status_dump(&service->main_exec_status, stdout, "\t");
c2dfb7
         if (service->main_exec_status.status != status_expected) {
c2dfb7
                 log_error("%s: %s: exit status %d, expected %d",
c2dfb7
@@ -70,6 +81,25 @@ static void check(const char *func, Manager *m, Unit *unit, int status_expected,
c2dfb7
         }
c2dfb7
 }
c2dfb7
 
c2dfb7
+static void check_service_result(const char *func, Manager *m, Unit *unit, ServiceResult result_expected) {
c2dfb7
+        Service *service = NULL;
c2dfb7
+
c2dfb7
+        assert_se(m);
c2dfb7
+        assert_se(unit);
c2dfb7
+
c2dfb7
+        wait_for_service_finish(m, unit);
c2dfb7
+
c2dfb7
+        service = SERVICE(unit);
c2dfb7
+
c2dfb7
+        if (service->result != result_expected) {
c2dfb7
+                log_error("%s: %s: service end result %s, expected %s",
c2dfb7
+                          func, unit->id,
c2dfb7
+                          service_result_to_string(service->result),
c2dfb7
+                          service_result_to_string(result_expected));
c2dfb7
+                abort();
c2dfb7
+        }
c2dfb7
+}
c2dfb7
+
c2dfb7
 static bool check_nobody_user_and_group(void) {
c2dfb7
         static int cache = -1;
c2dfb7
         struct passwd *p;
c2dfb7
@@ -140,7 +170,17 @@ static void test(const char *func, Manager *m, const char *unit_name, int status
c2dfb7
 
c2dfb7
         assert_se(manager_load_startable_unit_or_warn(m, unit_name, NULL, &unit) >= 0);
c2dfb7
         assert_se(unit_start(unit) >= 0);
c2dfb7
-        check(func, m, unit, status_expected, code_expected);
c2dfb7
+        check_main_result(func, m, unit, status_expected, code_expected);
c2dfb7
+}
c2dfb7
+
c2dfb7
+static void test_service(const char *func, Manager *m, const char *unit_name, ServiceResult result_expected) {
c2dfb7
+        Unit *unit;
c2dfb7
+
c2dfb7
+        assert_se(unit_name);
c2dfb7
+
c2dfb7
+        assert_se(manager_load_startable_unit_or_warn(m, unit_name, NULL, &unit) >= 0);
c2dfb7
+        assert_se(unit_start(unit) >= 0);
c2dfb7
+        check_service_result(func, m, unit, result_expected);
c2dfb7
 }
c2dfb7
 
c2dfb7
 static void test_exec_bindpaths(Manager *m) {
c2dfb7
@@ -669,6 +709,11 @@ static void test_exec_standardoutput_append(Manager *m) {
c2dfb7
         test(__func__, m, "exec-standardoutput-append.service", 0, CLD_EXITED);
c2dfb7
 }
c2dfb7
 
c2dfb7
+static void test_exec_condition(Manager *m) {
c2dfb7
+        test_service(__func__, m, "exec-condition-failed.service", SERVICE_FAILURE_EXIT_CODE);
c2dfb7
+        test_service(__func__, m, "exec-condition-skip.service", SERVICE_SKIP_CONDITION);
c2dfb7
+}
c2dfb7
+
c2dfb7
 typedef struct test_entry {
c2dfb7
         test_function_t f;
c2dfb7
         const char *name;
c2dfb7
@@ -709,6 +754,7 @@ int main(int argc, char *argv[]) {
c2dfb7
                 entry(test_exec_ambientcapabilities),
c2dfb7
                 entry(test_exec_bindpaths),
c2dfb7
                 entry(test_exec_capabilityboundingset),
c2dfb7
+                entry(test_exec_condition),
c2dfb7
                 entry(test_exec_cpuaffinity),
c2dfb7
                 entry(test_exec_environment),
c2dfb7
                 entry(test_exec_environmentfile),
c2dfb7
diff --git a/test/fuzz/fuzz-unit-file/directives.service b/test/fuzz/fuzz-unit-file/directives.service
c2dfb7
index eab1820e20..9d0530df72 100644
c2dfb7
--- a/test/fuzz/fuzz-unit-file/directives.service
c2dfb7
+++ b/test/fuzz/fuzz-unit-file/directives.service
c2dfb7
@@ -83,6 +83,7 @@ DirectoryNotEmpty=
c2dfb7
 Documentation=
c2dfb7
 DynamicUser=
c2dfb7
 ExecReload=
c2dfb7
+ExecCondition=
c2dfb7
 ExecStart=
c2dfb7
 ExecStartPost=
c2dfb7
 ExecStartPre=
c2dfb7
diff --git a/test/meson.build b/test/meson.build
c2dfb7
index 4d1c51048c..070731c4a9 100644
c2dfb7
--- a/test/meson.build
c2dfb7
+++ b/test/meson.build
c2dfb7
@@ -42,6 +42,8 @@ test_data_files = '''
c2dfb7
         test-execute/exec-capabilityboundingset-merge.service
c2dfb7
         test-execute/exec-capabilityboundingset-reset.service
c2dfb7
         test-execute/exec-capabilityboundingset-simple.service
c2dfb7
+        test-execute/exec-condition-failed.service
c2dfb7
+        test-execute/exec-condition-skip.service
c2dfb7
         test-execute/exec-cpuaffinity1.service
c2dfb7
         test-execute/exec-cpuaffinity2.service
c2dfb7
         test-execute/exec-cpuaffinity3.service
c2dfb7
diff --git a/test/test-execute/exec-condition-failed.service b/test/test-execute/exec-condition-failed.service
c2dfb7
new file mode 100644
c2dfb7
index 0000000000..4a406dc17f
c2dfb7
--- /dev/null
c2dfb7
+++ b/test/test-execute/exec-condition-failed.service
c2dfb7
@@ -0,0 +1,11 @@
c2dfb7
+[Unit]
c2dfb7
+Description=Test for exec condition that fails the unit
c2dfb7
+
c2dfb7
+[Service]
c2dfb7
+Type=oneshot
c2dfb7
+
c2dfb7
+# exit 255 will fail the unit
c2dfb7
+ExecCondition=/bin/sh -c 'exit 255'
c2dfb7
+
c2dfb7
+# This should not get run
c2dfb7
+ExecStart=/bin/sh -c 'true'
c2dfb7
diff --git a/test/test-execute/exec-condition-skip.service b/test/test-execute/exec-condition-skip.service
c2dfb7
new file mode 100644
c2dfb7
index 0000000000..9450e8442a
c2dfb7
--- /dev/null
c2dfb7
+++ b/test/test-execute/exec-condition-skip.service
c2dfb7
@@ -0,0 +1,15 @@
c2dfb7
+[Unit]
c2dfb7
+Description=Test for exec condition that triggers skipping
c2dfb7
+
c2dfb7
+[Service]
c2dfb7
+Type=oneshot
c2dfb7
+
c2dfb7
+# exit codes [1, 254] will result in skipping the rest of execution
c2dfb7
+ExecCondition=/bin/sh -c 'exit 0'
c2dfb7
+ExecCondition=/bin/sh -c 'exit 254'
c2dfb7
+
c2dfb7
+# This would normally fail the unit but will not get run due to the skip above
c2dfb7
+ExecCondition=/bin/sh -c 'exit 255'
c2dfb7
+
c2dfb7
+# This should not get run
c2dfb7
+ExecStart=/bin/sh -c 'true'