systemd/0032-core-make-sure-to-close-connection-fd-when-we-fail-t.patch
Zbigniew Jędrzejewski-Szmek f4cc4c90ab Bugs for three outstanding fixes
2016-10-04 16:39:16 -04:00

59 lines
2.2 KiB
Diff

From 17c17ff59518267077632906ac39b7c69bf47f96 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 28 Apr 2016 17:09:50 +0200
Subject: [PATCH] core: make sure to close connection fd when we fail to
activate a per-connection service
Fixes: #2993 #2691
(cherry picked from commit 3e7a1f50e473a374e1657d2051237e2db04c4db2)
Resolves: rhbug#1310608
---
src/core/service.c | 2 +-
src/core/service.h | 1 +
src/core/socket.c | 6 +++++-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/core/service.c b/src/core/service.c
index ac7e41d777..01d6582aec 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -181,7 +181,7 @@ static int service_set_main_pid(Service *s, pid_t pid) {
return 0;
}
-static void service_close_socket_fd(Service *s) {
+void service_close_socket_fd(Service *s) {
assert(s);
s->socket_fd = asynchronous_close(s->socket_fd);
diff --git a/src/core/service.h b/src/core/service.h
index d342e000bb..20bfd0662b 100644
--- a/src/core/service.h
+++ b/src/core/service.h
@@ -200,6 +200,7 @@ struct Service {
extern const UnitVTable service_vtable;
int service_set_socket_fd(Service *s, int fd, struct Socket *socket, bool selinux_context_net);
+void service_close_socket_fd(Service *s);
const char* service_restart_to_string(ServiceRestart i) _const_;
ServiceRestart service_restart_from_string(const char *s) _pure_;
diff --git a/src/core/socket.c b/src/core/socket.c
index 976687af41..60906b196c 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1994,8 +1994,12 @@ static void socket_enter_running(Socket *s, int cfd) {
s->n_connections ++;
r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(service), JOB_REPLACE, &error, NULL);
- if (r < 0)
+ if (r < 0) {
+ /* We failed to activate the new service, but it still exists. Let's make sure the service
+ * closes and forgets the connection fd again, immediately. */
+ service_close_socket_fd(service);
goto fail;
+ }
/* Notify clients about changed counters */
unit_add_to_dbus_queue(UNIT(s));