From be6a689fb1a87fc9a1f9d30097e1b208c99a1730 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sun, 1 Jan 2017 23:20:35 +0100 Subject: [PATCH] Fixed stuck listening socket thread problem in config library --- lib/config.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/config.cpp b/lib/config.cpp index 2fd03d05..dce06ca4 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -35,6 +35,7 @@ #include "procs.h" bool Util::Config::is_active = false; +static Socket::Server * serv_sock_pointer = 0; unsigned int Util::Config::printDebugLevel = DEBUG;// Util::Config::Config() { @@ -359,9 +360,12 @@ int Util::Config::serveThreadedSocket(int (*callback)(Socket::Connection &)) { DEBUG_MSG(DLVL_DEVEL, "Failure to open socket"); return 1; } + serv_sock_pointer = &server_socket; DEBUG_MSG(DLVL_DEVEL, "Activating threaded server: %s", getString("cmd").c_str()); activate(); - return threadServer(server_socket, callback); + int r = threadServer(server_socket, callback); + serv_sock_pointer = 0; + return r; } int Util::Config::serveForkedSocket(int (*callback)(Socket::Connection & S)) { @@ -376,9 +380,12 @@ int Util::Config::serveForkedSocket(int (*callback)(Socket::Connection & S)) { DEBUG_MSG(DLVL_DEVEL, "Failure to open socket"); return 1; } + serv_sock_pointer = &server_socket; DEBUG_MSG(DLVL_DEVEL, "Activating forked server: %s", getString("cmd").c_str()); activate(); - return forkServer(server_socket, callback); + int r = forkServer(server_socket, callback); + serv_sock_pointer = 0; + return r; } /// Activated the stored config. This will: @@ -415,6 +422,7 @@ void Util::Config::signal_handler(int signum, siginfo_t * sigInfo, void * ignore case SIGINT: //these three signals will set is_active to false. case SIGHUP: case SIGTERM: + if (serv_sock_pointer){serv_sock_pointer->close();} is_active = false; default: switch (sigInfo->si_code){