core: make sure to close connection fd when we fail to activate a per-connection...
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Apr 2016 15:09:50 +0000 (17:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 29 Apr 2016 14:27:48 +0000 (16:27 +0200)
Fixes: #2993 #2691

src/core/service.c
src/core/service.h
src/core/socket.c

index 3c4328c..88f8cc5 100644 (file)
@@ -180,7 +180,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);
index cd9e416..c7f1e81 100644 (file)
@@ -198,6 +198,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_;
index 42260d8..a897a11 100644 (file)
@@ -2010,8 +2010,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));