From: Dmitry V. Levin Date: Fri, 14 Jul 2023 08:00:00 +0000 (+0000) Subject: socket: cleanup use of ERRNO_IS_DISCONNECT() X-Git-Tag: v255-rc1~886^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8dfb0ef16529dff6fc7f84e6a003dfe7ad0bee6c;p=thirdparty%2Fsystemd.git socket: cleanup use of ERRNO_IS_DISCONNECT() Given that ERRNO_IS_DISCONNECT() also matches positive values, make sure this macro is not called with arguments that do not have errno semantics. In this case the arguments passed to ERRNO_IS_DISCONNECT() are the values returned by instance_from_socket(), socket_load_service_unit(), and service_set_socket_fd() which are not expected to return any positive values, but let's be consistent anyway and move ERRNO_IS_DISCONNECT() invocations to the branches where the return values are known to be negative. --- diff --git a/src/core/socket.c b/src/core/socket.c index 03b8cbd164a..aaa443432b0 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1386,14 +1386,15 @@ int socket_load_service_unit(Socket *s, int cfd, Unit **ret) { if (cfd >= 0) { r = instance_from_socket(cfd, s->n_accepted, &instance); - 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 %s on incoming socket, assuming aborted connection attempt, ignoring.", - errno_to_name(r)); - if (r < 0) + if (r < 0) { + 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 %s on incoming socket, assuming aborted connection attempt, ignoring.", + errno_to_name(r)); return r; + } } /* For accepting sockets, we don't know how the instance will be called until we get a connection and @@ -2377,10 +2378,11 @@ static void socket_enter_running(Socket *s, int cfd_in) { } r = socket_load_service_unit(s, cfd, &service); - if (ERRNO_IS_DISCONNECT(r)) - return; - if (r < 0) + if (r < 0) { + if (ERRNO_IS_DISCONNECT(r)) + return; goto fail; + } r = unit_add_two_dependencies(UNIT(s), UNIT_BEFORE, UNIT_TRIGGERS, service, false, UNIT_DEPENDENCY_IMPLICIT); @@ -2390,10 +2392,11 @@ static void socket_enter_running(Socket *s, int cfd_in) { s->n_accepted++; r = service_set_socket_fd(SERVICE(service), cfd, s, p, s->selinux_context_from_net); - if (ERRNO_IS_DISCONNECT(r)) - return; - if (r < 0) + if (r < 0) { + if (ERRNO_IS_DISCONNECT(r)) + return; goto fail; + } TAKE_FD(cfd); /* We passed ownership of the fd to the service now. Forget it here. */ s->n_connections++;