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.
This commit is contained in:
Pawel Szewczyk
2015-09-22 12:01:53 +02:00
parent ac2896bab6
commit 15087cdbd6
3 changed files with 24 additions and 3 deletions
+2
View 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) {
+20 -3
View 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);
+2
View File
@@ -81,6 +81,8 @@ typedef struct SocketPort {
SocketType type;
int fd;
int *auxiliary_fds;
int n_auxiliary_fds;
SocketAddress address;
char *path;