core: increment start limit counter only when we can start the unit
Otherwise, e.g. requesting to start a unit that is under stopping may enter the failed state. This makes - rename .can_start() -> .test_startable(), and make it allow to return boolean and refuse to start units when it returns false, - refuse earlier to start units that are in the deactivating state, so several redundant conditions in .start() can be dropped, - move checks for unit states mapped to UNIT_ACTIVATING from .start() to .test_startable(). Fixes #39247.
This commit is contained in:
+11
-23
@@ -2623,26 +2623,6 @@ static int socket_start(Unit *u) {
|
||||
Socket *s = ASSERT_PTR(SOCKET(u));
|
||||
int r;
|
||||
|
||||
/* We cannot fulfill this request right now, try again later
|
||||
* please! */
|
||||
if (IN_SET(s->state,
|
||||
SOCKET_STOP_PRE,
|
||||
SOCKET_STOP_PRE_SIGKILL,
|
||||
SOCKET_STOP_PRE_SIGTERM,
|
||||
SOCKET_STOP_POST,
|
||||
SOCKET_FINAL_SIGTERM,
|
||||
SOCKET_FINAL_SIGKILL,
|
||||
SOCKET_CLEANING))
|
||||
return -EAGAIN;
|
||||
|
||||
/* Already on it! */
|
||||
if (IN_SET(s->state,
|
||||
SOCKET_START_PRE,
|
||||
SOCKET_START_OPEN,
|
||||
SOCKET_START_CHOWN,
|
||||
SOCKET_START_POST))
|
||||
return 0;
|
||||
|
||||
/* Cannot run this without the service being around */
|
||||
if (UNIT_ISSET(s->service)) {
|
||||
Service *service = ASSERT_PTR(SERVICE(UNIT_DEREF(s->service)));
|
||||
@@ -3650,17 +3630,25 @@ static int socket_can_clean(Unit *u, ExecCleanMask *ret) {
|
||||
return exec_context_get_clean_mask(&s->exec_context, ret);
|
||||
}
|
||||
|
||||
static int socket_can_start(Unit *u) {
|
||||
static int socket_test_startable(Unit *u) {
|
||||
Socket *s = ASSERT_PTR(SOCKET(u));
|
||||
int r;
|
||||
|
||||
/* It is already being started. */
|
||||
if (IN_SET(s->state,
|
||||
SOCKET_START_PRE,
|
||||
SOCKET_START_OPEN,
|
||||
SOCKET_START_CHOWN,
|
||||
SOCKET_START_POST))
|
||||
return false;
|
||||
|
||||
r = unit_test_start_limit(u);
|
||||
if (r < 0) {
|
||||
socket_enter_dead(s, SOCKET_FAILURE_START_LIMIT_HIT);
|
||||
return r;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char* const socket_exec_command_table[_SOCKET_EXEC_COMMAND_MAX] = {
|
||||
@@ -3801,5 +3789,5 @@ const UnitVTable socket_vtable = {
|
||||
},
|
||||
},
|
||||
|
||||
.can_start = socket_can_start,
|
||||
.test_startable = socket_test_startable,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user