service: Continue shutdown on socket activated unit on termination (#4108)
authorKyle Russell <bkylerussell@gmail.com>
Fri, 9 Sep 2016 02:34:43 +0000 (22:34 -0400)
committerEvgeny Vereshchagin <evvers@ya.ru>
Fri, 9 Sep 2016 02:34:43 +0000 (05:34 +0300)
ENOTCONN may be a legitimate return code if the endpoint disappeared,
but the service should still attempt to shutdown cleanly.

src/core/service.c

index 969c62b..57f8d90 100644 (file)
@@ -1256,10 +1256,17 @@ static int service_spawn(
                 socklen_t salen = sizeof(sa);
 
                 r = getpeername(s->socket_fd, &sa.sa, &salen);
-                if (r < 0)
-                        return -errno;
+                if (r < 0) {
+                        r = -errno;
+
+                        /* ENOTCONN is legitimate if the endpoint disappeared on shutdown.
+                         * This connection is over, but the socket unit lives on. */
+                        if (r != -ENOTCONN ||
+                            (c != s->exec_command[SERVICE_EXEC_STOP] && c != s->exec_command[SERVICE_EXEC_STOP_POST]))
+                                return r;
+                }
 
-                if (IN_SET(sa.sa.sa_family, AF_INET, AF_INET6)) {
+                if (r == 0 && IN_SET(sa.sa.sa_family, AF_INET, AF_INET6)) {
                         _cleanup_free_ char *addr = NULL;
                         char *t;
                         int port;