From: Mike Yuan Date: Wed, 17 Dec 2025 13:40:48 +0000 (+0100) Subject: core: move several checks from _start() to _test_startable() where appropriate X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75f04abf16e0b167803b47acf8c59dd08fde27f0;p=thirdparty%2Fsystemd.git core: move several checks from _start() to _test_startable() where appropriate If these basic sanity checks fail, there's no point in bumping ratelimit. --- diff --git a/src/core/automount.c b/src/core/automount.c index 79ccdd3fc70..5fd9c8f4ccb 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -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); diff --git a/src/core/path.c b/src/core/path.c index 764dea03dc4..789ef9e25d6 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -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); diff --git a/src/core/socket.c b/src/core/socket.c index 86e76745284..6ce307a00f0 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -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); diff --git a/src/core/timer.c b/src/core/timer.c index f2d4b5cc3df..c591fcd469c 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -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);