richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
ff479f
From aaeac7a33c8cc23cb890d2ad33b0b1542d5a9176 Mon Sep 17 00:00:00 2001
ff479f
From: Daan De Meyer <daan.j.demeyer@gmail.com>
ff479f
Date: Tue, 19 Oct 2021 10:45:48 +0100
ff479f
Subject: [PATCH] core: Delay start rate limit check when starting a unit
ff479f
ff479f
Doing start rate limit checks before doing condition checks made
ff479f
condition check failures count towards the start rate limit which
ff479f
broke existing assumptions (see #21025). Run the rate limit checks
ff479f
after the condition checks again to restore the previous behaviour.
ff479f
ff479f
(cherry picked from commit ce2146f5256659c7fb53a7d5b9dc551252e27e7e)
ff479f
ff479f
Related: #2086553
ff479f
---
ff479f
 src/core/unit.c | 14 +++++++-------
ff479f
 1 file changed, 7 insertions(+), 7 deletions(-)
ff479f
ff479f
diff --git a/src/core/unit.c b/src/core/unit.c
ff479f
index 4fd9af87b7..b825e2418c 100644
ff479f
--- a/src/core/unit.c
ff479f
+++ b/src/core/unit.c
ff479f
@@ -1729,13 +1729,6 @@ int unit_start(Unit *u) {
ff479f
 
ff479f
         assert(u);
ff479f
 
ff479f
-        /* Check our ability to start early so that failure conditions don't cause us to enter a busy loop. */
ff479f
-        if (UNIT_VTABLE(u)->can_start) {
ff479f
-                r = UNIT_VTABLE(u)->can_start(u);
ff479f
-                if (r < 0)
ff479f
-                        return r;
ff479f
-        }
ff479f
-
ff479f
         /* If this is already started, then this will succeed. Note that this will even succeed if this unit
ff479f
          * is not startable by the user. This is relied on to detect when we need to wait for units and when
ff479f
          * waiting is finished. */
ff479f
@@ -1790,6 +1783,13 @@ int unit_start(Unit *u) {
ff479f
                 return unit_start(following);
ff479f
         }
ff479f
 
ff479f
+        /* Check start rate limiting early so that failure conditions don't cause us to enter a busy loop. */
ff479f
+        if (UNIT_VTABLE(u)->can_start) {
ff479f
+                r = UNIT_VTABLE(u)->can_start(u);
ff479f
+                if (r < 0)
ff479f
+                        return r;
ff479f
+        }
ff479f
+
ff479f
         /* If it is stopped, but we cannot start it, then fail */
ff479f
         if (!UNIT_VTABLE(u)->start)
ff479f
                 return -EBADR;