]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: move several checks from _start() to _test_startable() where appropriate
authorMike Yuan <me@yhndnzj.com>
Wed, 17 Dec 2025 13:40:48 +0000 (14:40 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Jan 2026 21:11:26 +0000 (06:11 +0900)
If these basic sanity checks fail, there's no point in
bumping ratelimit.

src/core/automount.c
src/core/path.c
src/core/socket.c
src/core/timer.c

index 79ccdd3fc70e07e9563d23b7829ca63540b7f61d..5fd9c8f4ccbc23eda7a875ec2afbc9c41812cd34 100644 (file)
@@ -804,10 +804,6 @@ static int automount_start(Unit *u) {
         if (path_is_mount_point(a->where) > 0)
                 return log_unit_error_errno(u, SYNTHETIC_ERRNO(EEXIST), "Path %s is already a mount point, refusing start.", a->where);
 
-        r = unit_test_trigger_loaded(u);
-        if (r < 0)
-                return r;
-
         r = unit_acquire_invocation_id(u);
         if (r < 0)
                 return r;
@@ -1047,6 +1043,10 @@ static int automount_test_startable(Unit *u) {
         Automount *a = ASSERT_PTR(AUTOMOUNT(u));
         int r;
 
+        r = unit_test_trigger_loaded(u);
+        if (r < 0)
+                return r;
+
         r = unit_test_start_limit(u);
         if (r < 0) {
                 automount_enter_dead(a, AUTOMOUNT_FAILURE_START_LIMIT_HIT);
index 764dea03dc46e1c245a8c1da03f3351873ad758b..789ef9e25d6e93faf3bc9c1211b858166cc27743 100644 (file)
@@ -632,10 +632,6 @@ static int path_start(Unit *u) {
 
         assert(IN_SET(p->state, PATH_DEAD, PATH_FAILED));
 
-        r = unit_test_trigger_loaded(u);
-        if (r < 0)
-                return r;
-
         r = unit_acquire_invocation_id(u);
         if (r < 0)
                 return r;
@@ -902,6 +898,10 @@ static int path_test_startable(Unit *u) {
         Path *p = ASSERT_PTR(PATH(u));
         int r;
 
+        r = unit_test_trigger_loaded(u);
+        if (r < 0)
+                return r;
+
         r = unit_test_start_limit(u);
         if (r < 0) {
                 path_enter_dead(p, PATH_FAILURE_START_LIMIT_HIT);
index 86e767452843a8b15f75b3d2288c183dbabd9a7f..6ce307a00f0b11861beeafdef9f1b3a72755c757 100644 (file)
@@ -2623,20 +2623,6 @@ static int socket_start(Unit *u) {
         Socket *s = ASSERT_PTR(SOCKET(u));
         int r;
 
-        /* Cannot run this without the service being around */
-        if (UNIT_ISSET(s->service)) {
-                Service *service = ASSERT_PTR(SERVICE(UNIT_DEREF(s->service)));
-
-                if (UNIT(service)->load_state != UNIT_LOADED)
-                        return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOENT),
-                                                    "Socket service %s not loaded, refusing.", UNIT(service)->id);
-
-                /* If the service is already active we cannot start the socket */
-                if (SOCKET_SERVICE_IS_ACTIVE(service, /* allow_finalize= */ false))
-                        return log_unit_error_errno(u, SYNTHETIC_ERRNO(EBUSY),
-                                                    "Socket service %s already active, refusing.", UNIT(service)->id);
-        }
-
         assert(IN_SET(s->state, SOCKET_DEAD, SOCKET_FAILED));
 
         r = unit_acquire_invocation_id(u);
@@ -3642,6 +3628,20 @@ static int socket_test_startable(Unit *u) {
                    SOCKET_START_POST))
                 return false;
 
+        /* Cannot run this without the service being around */
+        if (UNIT_ISSET(s->service)) {
+                Service *service = ASSERT_PTR(SERVICE(UNIT_DEREF(s->service)));
+
+                if (UNIT(service)->load_state != UNIT_LOADED)
+                        return log_unit_error_errno(u, SYNTHETIC_ERRNO(ENOENT),
+                                                    "Socket service %s not loaded, refusing.", UNIT(service)->id);
+
+                /* If the service is already active we cannot start the socket */
+                if (SOCKET_SERVICE_IS_ACTIVE(service, /* allow_finalize= */ false))
+                        return log_unit_error_errno(u, SYNTHETIC_ERRNO(EBUSY),
+                                                    "Socket service %s already active, refusing.", UNIT(service)->id);
+        }
+
         r = unit_test_start_limit(u);
         if (r < 0) {
                 socket_enter_dead(s, SOCKET_FAILURE_START_LIMIT_HIT);
index f2d4b5cc3dff9d7bcf46874fc16fccccb65095be..c591fcd469c7a25a67ab252640813451cc2723d3 100644 (file)
@@ -668,10 +668,6 @@ static int timer_start(Unit *u) {
 
         assert(IN_SET(t->state, TIMER_DEAD, TIMER_FAILED));
 
-        r = unit_test_trigger_loaded(u);
-        if (r < 0)
-                return r;
-
         r = unit_acquire_invocation_id(u);
         if (r < 0)
                 return r;
@@ -917,6 +913,10 @@ static int timer_test_startable(Unit *u) {
         Timer *t = ASSERT_PTR(TIMER(u));
         int r;
 
+        r = unit_test_trigger_loaded(u);
+        if (r < 0)
+                return r;
+
         r = unit_test_start_limit(u);
         if (r < 0) {
                 timer_enter_dead(t, TIMER_FAILURE_START_LIMIT_HIT);