]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: Add list of additional file descriptors to socket port
authorPawel Szewczyk <p.szewczyk@samsung.com>
Mon, 21 Sep 2015 14:30:41 +0000 (16:30 +0200)
committerPawel Szewczyk <p.szewczyk@samsung.com>
Tue, 22 Sep 2015 10:01:53 +0000 (12:01 +0200)
Some additional files related to single socket may appear in the
filesystem and they should be opened and passed to related service.

This commit adds optional list of file descriptors, which are
dynamically discovered and opened.

src/core/load-fragment.c
src/core/socket.c
src/core/socket.h

index b476d472b3aaf91d94b6f1064c17c1319b845c06..b8cdde3bffd960c59c0779f443eb70d3474f713e 100644 (file)
@@ -381,6 +381,8 @@ int config_parse_socket_listen(const char *unit,
         }
 
         p->fd = -1;
+        p->auxiliary_fds = NULL;
+        p->n_auxiliary_fds = 0;
         p->socket = s;
 
         if (s->ports) {
index 9db42a033310c53e3f53dcae2bb14a393ec1ad06..518c935f96a84ad18ef189a9dfaba1564f64e9e7 100644 (file)
@@ -104,6 +104,16 @@ static void socket_unwatch_control_pid(Socket *s) {
         s->control_pid = 0;
 }
 
+static void socket_cleanup_fd_list(SocketPort *p) {
+        int k = p->n_auxiliary_fds;
+
+        while (k--)
+                safe_close(p->auxiliary_fds[k]);
+
+        p->auxiliary_fds = mfree(p->auxiliary_fds);
+        p->n_auxiliary_fds = 0;
+}
+
 void socket_free_ports(Socket *s) {
         SocketPort *p;
 
@@ -114,6 +124,7 @@ void socket_free_ports(Socket *s) {
 
                 sd_event_source_unref(p->event_source);
 
+                socket_cleanup_fd_list(p);
                 safe_close(p->fd);
                 free(p->path);
                 free(p);
@@ -775,6 +786,7 @@ static void socket_close_fds(Socket *s) {
                         continue;
 
                 p->fd = safe_close(p->fd);
+                socket_cleanup_fd_list(p);
 
                 /* One little note: we should normally not delete any
                  * sockets in the file system here! After all some
@@ -2297,7 +2309,6 @@ static int socket_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
                         log_unit_error(UNIT(p->socket), "Got POLLHUP on a listening socket. The service probably invoked shutdown() on it, and should better not do that.");
                 else
                         log_unit_error(UNIT(p->socket), "Got unexpected poll event (0x%x) on socket.", revents);
-
                 goto fail;
         }
 
@@ -2496,6 +2507,7 @@ static int socket_dispatch_timer(sd_event_source *source, usec_t usec, void *use
 int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
         int *rfds;
         unsigned rn_fds, k;
+        int i;
         SocketPort *p;
 
         assert(s);
@@ -2505,9 +2517,11 @@ int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
         /* Called from the service code for requesting our fds */
 
         rn_fds = 0;
-        LIST_FOREACH(port, p, s->ports)
+        LIST_FOREACH(port, p, s->ports) {
                 if (p->fd >= 0)
                         rn_fds++;
+                rn_fds += p->n_auxiliary_fds;
+        }
 
         if (rn_fds <= 0) {
                 *fds = NULL;
@@ -2520,9 +2534,12 @@ int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
                 return -ENOMEM;
 
         k = 0;
-        LIST_FOREACH(port, p, s->ports)
+        LIST_FOREACH(port, p, s->ports) {
                 if (p->fd >= 0)
                         rfds[k++] = p->fd;
+                for (i = 0; i < p->n_auxiliary_fds; ++i)
+                        rfds[k++] = p->auxiliary_fds[i];
+        }
 
         assert(k == rn_fds);
 
index fa3ebdafa064f050268b0dd15495fdadb4e106a6..e1046adad4c47b5955cf8f6238c1f036fd7c4a79 100644 (file)
@@ -81,6 +81,8 @@ typedef struct SocketPort {
 
         SocketType type;
         int fd;
+        int *auxiliary_fds;
+        int n_auxiliary_fds;
 
         SocketAddress address;
         char *path;