From a330a15807446e0eb46bcc6857d3236ae0ae3bb5 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Sat, 14 Apr 2012 09:14:52 +0200 Subject: [PATCH] Shutdown logging before exit() call to fix potential freeze --- backends/skype/main.cpp | 4 ++++ include/transport/logging.h | 2 ++ src/logging.cpp | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/backends/skype/main.cpp b/backends/skype/main.cpp index 1ccd81e4..838d9231 100644 --- a/backends/skype/main.cpp +++ b/backends/skype/main.cpp @@ -165,6 +165,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin { if (skype) { LOG4CXX_INFO(logger, "User wants to logout, logging out"); skype->logout(); + Logging::shutdownLogging(); exit(1); } } @@ -801,6 +802,7 @@ static int create_socket(char *host, int portno) { if ((hos = gethostbyname(host)) == NULL) { // strerror() will not work for gethostbyname() and hstrerror() // is supposedly obsolete + Logging::shutdownLogging(); exit(1); } serv_addr.sin_addr.s_addr = *((unsigned long *) hos->h_addr_list[0]); @@ -823,6 +825,7 @@ static gboolean transportDataReceived(GIOChannel *source, GIOCondition condition ssize_t n = read(m_sock, ptr, sizeof(buffer)); if (n <= 0) { LOG4CXX_INFO(logger, "Diconnecting from spectrum2 server"); + Logging::shutdownLogging(); exit(errno); } std::string d = std::string(buffer, n); @@ -831,6 +834,7 @@ static gboolean transportDataReceived(GIOChannel *source, GIOCondition condition } static void io_destroy(gpointer data) { + Logging::shutdownLogging(); exit(1); } diff --git a/include/transport/logging.h b/include/transport/logging.h index 4abf92dd..d3103103 100644 --- a/include/transport/logging.h +++ b/include/transport/logging.h @@ -35,6 +35,7 @@ #include "log4cxx/helpers/fileinputstream.h" #include "log4cxx/helpers/transcoder.h" #include "log4cxx/logger.h" +#include "log4cxx/logmanager.h" #define DEFINE_LOGGER(VAR, NAME) static log4cxx::LoggerPtr VAR = log4cxx::Logger::getLogger(NAME); @@ -55,6 +56,7 @@ namespace Logging { void initBackendLogging(Config *config); void initMainLogging(Config *config); +void shutdownLogging(); } diff --git a/src/logging.cpp b/src/logging.cpp index 3d56878f..bd78eec8 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -139,11 +139,19 @@ void initMainLogging(Config *config) { initLogging(config, "logging.config"); } +void shutdownLogging() { + log4cxx::LogManager::shutdown(); +} + #else /* WITH_LOG4CXX */ void initBackendLogging(Config */*config*/) { } void initMainLogging(Config */*config*/) { +} + +void shutdownLogging() { + } #endif /* WITH_LOG4CXX */