mirror of
https://github.com/systemd/systemd.git
synced 2025-02-04 21:47:31 +03:00
core/socket: validate service unit load state before continuing
Fixes #31915
This commit is contained in:
parent
dc4c587163
commit
f61e4e5380
@ -1369,6 +1369,8 @@ clear:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int socket_load_service_unit(Socket *s, int cfd, Unit **ret) {
|
int socket_load_service_unit(Socket *s, int cfd, Unit **ret) {
|
||||||
|
int r;
|
||||||
|
|
||||||
/* Figure out what the unit that will be used to handle the connections on the socket looks like.
|
/* Figure out what the unit that will be used to handle the connections on the socket looks like.
|
||||||
*
|
*
|
||||||
* If cfd < 0, then we don't have a connection yet. In case of Accept=yes sockets, use a fake
|
* If cfd < 0, then we don't have a connection yet. In case of Accept=yes sockets, use a fake
|
||||||
@ -1388,7 +1390,6 @@ int socket_load_service_unit(Socket *s, int cfd, Unit **ret) {
|
|||||||
|
|
||||||
/* Build the instance name and load the unit */
|
/* Build the instance name and load the unit */
|
||||||
_cleanup_free_ char *prefix = NULL, *instance = NULL, *name = NULL;
|
_cleanup_free_ char *prefix = NULL, *instance = NULL, *name = NULL;
|
||||||
int r;
|
|
||||||
|
|
||||||
r = unit_name_to_prefix(UNIT(s)->id, &prefix);
|
r = unit_name_to_prefix(UNIT(s)->id, &prefix);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -2295,8 +2296,8 @@ static void socket_enter_running(Socket *s, int cfd_in) {
|
|||||||
|
|
||||||
if (!pending) {
|
if (!pending) {
|
||||||
if (!UNIT_ISSET(s->service)) {
|
if (!UNIT_ISSET(s->service)) {
|
||||||
r = log_unit_warning_errno(UNIT(s), SYNTHETIC_ERRNO(ENOENT),
|
log_unit_warning(UNIT(s),
|
||||||
"Service to activate vanished, refusing activation.");
|
"Service to activate vanished, refusing activation.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2340,11 +2341,15 @@ static void socket_enter_running(Socket *s, int cfd_in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r = socket_load_service_unit(s, cfd, &service);
|
r = socket_load_service_unit(s, cfd, &service);
|
||||||
if (r < 0) {
|
if (ERRNO_IS_NEG_DISCONNECT(r))
|
||||||
if (ERRNO_IS_DISCONNECT(r))
|
return;
|
||||||
return;
|
if (r < 0 || UNIT_IS_LOAD_ERROR(service->load_state)) {
|
||||||
|
log_unit_warning_errno(UNIT(s), r < 0 ? r : service->load_error,
|
||||||
log_unit_warning_errno(UNIT(s), r, "Failed to load connection service unit: %m");
|
"Failed to load connection service unit: %m");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if (service->load_state == UNIT_MASKED) {
|
||||||
|
log_unit_warning(UNIT(s), "Connection service unit is masked, refusing.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2388,13 +2393,9 @@ refuse:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
queue_error:
|
queue_error:
|
||||||
if (ERRNO_IS_RESOURCE(r))
|
log_unit_warning_errno(UNIT(s), r, "Failed to queue service startup job%s: %s",
|
||||||
log_unit_warning(UNIT(s), "Failed to queue service startup job: %s",
|
cfd >= 0 && !ERRNO_IS_RESOURCE(r) ? " (Maybe the service is missing or is a template unit?)" : "",
|
||||||
bus_error_message(&error, r));
|
bus_error_message(&error, r));
|
||||||
else
|
|
||||||
log_unit_warning(UNIT(s), "Failed to queue service startup job (Maybe the service file is missing or not a %s unit?): %s",
|
|
||||||
cfd >= 0 ? "template" : "non-template",
|
|
||||||
bus_error_message(&error, r));
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user