summaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index 9db42a0333..518c935f96 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -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);