summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorPawel Szewczyk <p.szewczyk@samsung.com>2015-09-21 16:30:41 +0200
committerPawel Szewczyk <p.szewczyk@samsung.com>2015-09-22 12:01:53 +0200
commit15087cdbd63312f706f21339489daf210ae609d0 (patch)
treed297ec2750f157a503eddb935c2de48e2d996064 /src/core
parentac2896bab61bd8cd0b8a8b92f8347e2c11a088b5 (diff)
core: Add list of additional file descriptors to socket port
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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/load-fragment.c2
-rw-r--r--src/core/socket.c23
-rw-r--r--src/core/socket.h2
3 files changed, 24 insertions, 3 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index b476d472b3..b8cdde3bff 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -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) {
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);
diff --git a/src/core/socket.h b/src/core/socket.h
index fa3ebdafa0..e1046adad4 100644
--- a/src/core/socket.h
+++ b/src/core/socket.h
@@ -81,6 +81,8 @@ typedef struct SocketPort {
SocketType type;
int fd;
+ int *auxiliary_fds;
+ int n_auxiliary_fds;
SocketAddress address;
char *path;