socket-server: Add support for systemd socket activation.

This adds support to module-native-protocol-unix to take over already
listening sockets passed in via socket activation (e.g. from systemd)

Most of the code is isolated to socket-server but some cleanup code also
had to be tweaked to ensure we do not overzealously close open fds.
This commit is contained in:
Colin Guthrie 2014-10-16 10:05:19 +01:00
parent fb1ca6f0c1
commit 467b4b9bee
5 changed files with 116 additions and 29 deletions

View file

@ -52,6 +52,9 @@
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_SYSTEMD_DAEMON
#include <systemd/sd-daemon.h>
#endif
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
@ -255,6 +258,21 @@ int pa_unix_socket_remove_stale(const char *fn) {
pa_assert(fn);
#ifdef HAVE_SYSTEMD_DAEMON
{
int n = sd_listen_fds(0);
if (n > 0) {
for (int i = 0; i < n; ++i) {
if (sd_is_socket_unix(SD_LISTEN_FDS_START + i, SOCK_STREAM, 1, fn, 0) > 0) {
/* This is a socket activated socket, therefore do not consider
* it stale. */
return 0;
}
}
}
}
#endif
if ((r = pa_unix_socket_is_stale(fn)) < 0)
return errno != ENOENT ? -1 : 0;