From 6e5db507e6d6923e815d8c6d491994ec63db3083 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Thu, 8 May 2008 14:32:06 -0600 Subject: [PATCH] Added eCAP configuration code. Catch uncaught exceptions in main() to provide a more informative debugging message before dying. --- src/main.cc | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/main.cc b/src/main.cc index 8581ffd8d6..73543e97be 100644 --- a/src/main.cc +++ b/src/main.cc @@ -69,6 +69,7 @@ #include "forward.h" #include "MemPool.h" #include "ICMPSquid.h" +#include "TextException.h" #if USE_LOADABLE_MODULES #include "LoadableModules.h" @@ -77,6 +78,9 @@ #if ICAP_CLIENT #include "ICAP/ICAPConfig.h" #endif +#if USE_ECAP +#include "eCAP/Config.h" +#endif #if USE_ADAPTATION #include "adaptation/Config.h" #endif @@ -1099,11 +1103,13 @@ mainInitialize(void) // We can remove this dependency on specific adaptation mechanisms // if we create a generic Registry of such mechanisms. Should we? #if ICAP_CLIENT - TheICAPConfig.finalize(); // must be after we load modules - enableAdaptation = TheICAPConfig.onoff; + TheICAPConfig.finalize(); + enableAdaptation = TheICAPConfig.onoff || enableAdaptation; +#endif +#if USE_ECAP + Ecap::TheConfig.finalize(); // must be after we load modules + enableAdaptation = Ecap::TheConfig.onoff || enableAdaptation; #endif - // same for eCAP - // must be the last adaptation-related finalize Adaptation::Config::Finalize(enableAdaptation); #endif @@ -1135,20 +1141,39 @@ mainInitialize(void) configured_once = 1; } +static int SquidMain(int argc, char **argv); +static int SquidMainSafe(int argc, char **argv); + #if USE_WIN32_SERVICE /* When USE_WIN32_SERVICE is defined, the main function is placed in win32.cc */ extern "C" void WINAPI SquidWinSvcMain(int argc, char **argv) -{ - SquidMain(argc, argv); -} - -int -SquidMain(int argc, char **argv) #else int main(int argc, char **argv) #endif +{ + SquidMainSafe(argc, argv); +} + +static int +SquidMainSafe(int argc, char **argv) +{ + try { + return SquidMain(argc, argv); + } + catch (const TextException &e) { + // XXX: add TextException::print + std::cerr << "dying from unhandled exception: " << e.message << std::endl; + } + catch (...) { + std::cerr << "dying from unhandled exception." << std::endl; + } + return -1; +} + +static int +SquidMain(int argc, char **argv) { mode_t oldmask; #ifdef _SQUID_WIN32_ -- 2.47.2