ryantimwilson / rpms / systemd

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