]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/service: ensure we don't restart on SERVICE_SKIP_CONDITION
authorMike Yuan <me@yhndnzj.com>
Sat, 30 Mar 2024 13:16:49 +0000 (21:16 +0800)
committerMike Yuan <me@yhndnzj.com>
Mon, 1 Apr 2024 11:14:15 +0000 (19:14 +0800)
service_shall_restart() always returns false if result
is SERVICE_SKIP_CONDITION, so drop unreachable code.

src/core/service.c

index a6e7af2a9a848f89a641487ab33bfa22d564d4d5..0a3717e34e95a055bfb86938af2420297b4e0326 100644 (file)
@@ -1992,7 +1992,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
         } else if (s->result == SERVICE_SKIP_CONDITION) {
                 unit_log_skip(UNIT(s), service_result_to_string(s->result));
                 end_state = service_determine_dead_state(s);
-                restart_state = SERVICE_DEAD_BEFORE_AUTO_RESTART;
+                restart_state = _SERVICE_STATE_INVALID; /* Never restart if skipped due to condition failure */
         } else {
                 unit_log_failure(UNIT(s), service_result_to_string(s->result));
                 end_state = SERVICE_FAILED;
@@ -2014,6 +2014,8 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
         if (allow_restart) {
                 usec_t restart_usec_next;
 
+                assert(restart_state >= 0 && restart_state < _SERVICE_STATE_MAX);
+
                 /* We make two state changes here: one that maps to the high-level UNIT_INACTIVE/UNIT_FAILED
                  * state (i.e. a state indicating deactivation), and then one that that maps to the
                  * high-level UNIT_STARTING state (i.e. a state indicating activation). We do this so that
@@ -2513,7 +2515,6 @@ static void service_enter_condition(Service *s) {
                                   service_exec_flags(s->control_command_id, /* cred_flag = */ 0),
                                   s->timeout_start_usec,
                                   &s->control_pid);
-
                 if (r < 0) {
                         log_unit_warning_errno(UNIT(s), r, "Failed to spawn 'exec-condition' task: %m");
                         goto fail;