From 7338b16c180a879745ecf6dcd6a7d490081dbb01 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 13 Feb 2012 20:48:51 +0100 Subject: listen: implement systemd socket activation --- src/listen.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/listen.c') 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 #include +#ifdef ENABLE_SYSTEMD_DAEMON +#include +#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 */ -- cgit v1.2.3