From 4279a6caeaffab3e6125feb4a76a98028bb661d5 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 9 May 2018 13:48:32 +0000 Subject: [PATCH] Update: Make use of listensocket_container_set_sockcount_cb() and listensocket_container_sockcount() This fixes the starts-up-with-no-listen-sockets bug. --- src/connection.c | 13 +++++++++++++ src/main.c | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/connection.c b/src/connection.c index 7041d879..aed2feba 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1634,6 +1634,18 @@ static void _handle_connection(void) } +static void __on_sock_count(size_t count, void *userdata) +{ + (void)userdata; + + ICECAST_LOG_DEBUG("Listen socket count is now %zu.", count); + + if (count == 0 && global.running == ICECAST_RUNNING) { + ICECAST_LOG_INFO("No more listen sockets. Exiting."); + global.running = ICECAST_HALTING; + } +} + /* called when listening thread is not checking for incoming connections */ void connection_setup_sockets (ice_config_t *config) { @@ -1663,6 +1675,7 @@ void connection_setup_sockets (ice_config_t *config) global_unlock(); + listensocket_container_set_sockcount_cb(global.listensockets, __on_sock_count, NULL); listensocket_container_setup(global.listensockets);; } diff --git a/src/main.c b/src/main.c index 86998bfb..0f997b88 100644 --- a/src/main.c +++ b/src/main.c @@ -77,6 +77,7 @@ #include "yp.h" #include "auth.h" #include "event.h" +#include "listensocket.h" #include @@ -377,6 +378,11 @@ static int _server_proc_init(void) connection_setup_sockets(config); + if (listensocket_container_sockcount(global.listensockets) < 1) { + ICECAST_LOG_ERROR("Can not listen on any sockets."); + return 0; + } + pidfile_update(config, 1); return 1;