summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKyle Russell <bkylerussell@gmail.com>2016-09-08 22:34:43 -0400
committerEvgeny Vereshchagin <evvers@ya.ru>2016-09-09 05:34:43 +0300
commitf2dbd059a6b325f058c1eff65f2441a0f9f90eb1 (patch)
treeaa5a29e1734f3e9e5693a02ed504fc5b1ab5b7b4 /src
parentde737be0a8c90a7a1f113e0c63f995937da32f4e (diff)
service: Continue shutdown on socket activated unit on termination (#4108)
ENOTCONN may be a legitimate return code if the endpoint disappeared, but the service should still attempt to shutdown cleanly.
Diffstat (limited to 'src')
-rw-r--r--src/core/service.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/core/service.c b/src/core/service.c
index 969c62bd83..57f8d90ee5 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -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;