diff options
author | Max Kellermann <max@duempel.org> | 2012-02-13 20:48:51 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-02-13 21:32:42 +0100 |
commit | 7338b16c180a879745ecf6dcd6a7d490081dbb01 (patch) | |
tree | 9fe1882d415d5bbb3693f94f2b7150f0b675f2d4 /src/listen.c | |
parent | f5294414004c258236a9d31ae3d3ee00ccb26717 (diff) | |
download | mpd-7338b16c180a879745ecf6dcd6a7d490081dbb01.tar.gz mpd-7338b16c180a879745ecf6dcd6a7d490081dbb01.tar.xz mpd-7338b16c180a879745ecf6dcd6a7d490081dbb01.zip |
listen: implement systemd socket activation
Diffstat (limited to '')
-rw-r--r-- | src/listen.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/listen.c b/src/listen.c index 5c958507d..e2a40e93f 100644 --- a/src/listen.c +++ b/src/listen.c @@ -28,6 +28,10 @@ #include <string.h> #include <assert.h> +#ifdef ENABLE_SYSTEMD_DAEMON +#include <systemd/sd-daemon.h> +#endif + #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "listen" @@ -61,6 +65,30 @@ listen_add_config_param(unsigned int port, } } +static bool +listen_systemd_activation(GError **error_r) +{ +#ifdef ENABLE_SYSTEMD_DAEMON + int n = sd_listen_fds(true); + if (n <= 0) { + if (n < 0) + g_warning("sd_listen_fds() failed: %s", + g_strerror(-n)); + return false; + } + + for (int i = SD_LISTEN_FDS_START, end = SD_LISTEN_FDS_START + n; + i != end; ++i) + if (!server_socket_add_fd(listen_socket, i, error_r)) + return false; + + return true; +#else + (void)error_r; + return false; +#endif +} + bool listen_global_init(GError **error_r) { @@ -72,6 +100,14 @@ listen_global_init(GError **error_r) listen_socket = server_socket_new(listen_callback, NULL); + if (listen_systemd_activation(&error)) + return true; + + if (error != NULL) { + g_propagate_error(error_r, error); + return false; + } + if (param != NULL) { /* "bind_to_address" is configured, create listeners for all values */ |