core: move several checks from _start() to _test_startable() where appropriate

If these basic sanity checks fail, there's no point in
bumping ratelimit.
This commit is contained in:
Mike Yuan
2026-01-05 06:11:26 +09:00
committed by Yu Watanabe
parent f8e1a7a66e
commit 75f04abf16
4 changed files with 26 additions and 26 deletions
+4 -4
View 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);
+4 -4
View 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);
+14 -14
View 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);
+4 -4
View 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);