core/socket: we may get ENOTCONN from socket_instantiate_service()
This means that the connection was aborted before we even got to figure out
what the service name will be. Let's treat this as a non-event and close the
connection fd without any further messages.
Code last changed in 934ef6a5.
Reported-by: Thiago Macieira <thiago.macieira@intel.com>
With the patch:
systemd[1]: foobar.socket: Incoming traffic
systemd[1]: foobar.socket: Got ENOTCONN on incoming socket, assuming aborted connection attempt, ignoring.
...
Also, when we get ENOMEM, don't give the hint about missing unit.
This commit is contained in:
+24
-11
@@ -18,6 +18,7 @@
|
||||
#include "dbus-socket.h"
|
||||
#include "dbus-unit.h"
|
||||
#include "def.h"
|
||||
#include "errno-list.h"
|
||||
#include "exit-status.h"
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
@@ -1424,11 +1425,12 @@ int socket_load_service_unit(Socket *s, int cfd, Unit **ret) {
|
||||
|
||||
if (cfd >= 0) {
|
||||
r = instance_from_socket(cfd, s->n_accepted, &instance);
|
||||
if (r == -ENOTCONN)
|
||||
/* ENOTCONN is legitimate if TCP RST was received.
|
||||
* This connection is over, but the socket unit lives on. */
|
||||
if (ERRNO_IS_DISCONNECT(r))
|
||||
/* ENOTCONN is legitimate if TCP RST was received. Other socket families might return
|
||||
* different errors. This connection is over, but the socket unit lives on. */
|
||||
return log_unit_debug_errno(UNIT(s), r,
|
||||
"Got ENOTCONN on incoming socket, assuming aborted connection attempt, ignoring.");
|
||||
"Got %s on incoming socket, assuming aborted connection attempt, ignoring.",
|
||||
errno_to_name(r));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@@ -2370,8 +2372,8 @@ static void socket_enter_running(Socket *s, int cfd) {
|
||||
|
||||
if (!pending) {
|
||||
if (!UNIT_ISSET(s->service)) {
|
||||
log_unit_error(UNIT(s), "Service to activate vanished, refusing activation.");
|
||||
r = -ENOENT;
|
||||
r = log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOENT),
|
||||
"Service to activate vanished, refusing activation.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -2393,8 +2395,10 @@ static void socket_enter_running(Socket *s, int cfd) {
|
||||
|
||||
if (s->max_connections_per_source > 0) {
|
||||
r = socket_acquire_peer(s, cfd, &p);
|
||||
if (r < 0)
|
||||
goto refuse;
|
||||
if (ERRNO_IS_DISCONNECT(r))
|
||||
goto notconn;
|
||||
if (r < 0) /* We didn't have enough resources to acquire peer information, let's fail. */
|
||||
goto fail;
|
||||
if (r > 0 && p->n_ref > s->max_connections_per_source) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
|
||||
@@ -2408,6 +2412,8 @@ static void socket_enter_running(Socket *s, int cfd) {
|
||||
}
|
||||
|
||||
r = socket_instantiate_service(s, cfd);
|
||||
if (ERRNO_IS_DISCONNECT(r))
|
||||
goto notconn;
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -2417,6 +2423,8 @@ static void socket_enter_running(Socket *s, int cfd) {
|
||||
s->n_accepted++;
|
||||
|
||||
r = service_set_socket_fd(service, cfd, s, s->selinux_context_from_net);
|
||||
if (ERRNO_IS_DISCONNECT(r))
|
||||
goto notconn;
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -2441,13 +2449,18 @@ static void socket_enter_running(Socket *s, int cfd) {
|
||||
|
||||
refuse:
|
||||
s->n_refused++;
|
||||
notconn:
|
||||
safe_close(cfd);
|
||||
return;
|
||||
|
||||
fail:
|
||||
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));
|
||||
if (ERRNO_IS_RESOURCE(r))
|
||||
log_unit_warning(UNIT(s), "Failed to queue service startup job: %s",
|
||||
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));
|
||||
|
||||
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||
safe_close(cfd);
|
||||
|
||||
Reference in New Issue
Block a user