diff options
author | Adam <Adam@anope.org> | 2010-08-29 19:28:04 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-08-29 19:28:04 -0400 |
commit | f2769273652f61f1d620c98a94b9c95983ed5647 (patch) | |
tree | 6d8c77e680258c095221d4ef98cf04845666d621 /src/main.cpp | |
parent | d70f1a43bc9520b3db22534fee07a047be4fa4d1 (diff) |
Redo some of the sighandling code, and made anoperc rehash actually work.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 107 |
1 files changed, 34 insertions, 73 deletions
diff --git a/src/main.cpp b/src/main.cpp index 64e755b7c..04baf1dd3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -248,81 +248,55 @@ void sighandler(int signum) * QUIT code without having a valid quitmsg. -GD */ if (quitmsg.empty()) - quitmsg = "Services terminating via a signal."; + quitmsg = Anope::string("Services terminating via signal ") + strsignal(signum) + " (" + stringify(signum) + ")"; + bool fatal = false; if (started) { -#ifndef _WIN32 - if (signum == SIGHUP) + switch (signum) { - Log() << "Received SIGHUP: Saving Databases & Rehash Configuration"; - - expire_all(); - save_databases(); +#ifndef _WIN32 + case SIGHUP: + Log() << "Received SIGHUP: Saving Databases & Rehash Configuration"; - try - { - ServerConfig *newconfig = new ServerConfig(); - delete Config; - Config = newconfig; - FOREACH_MOD(I_OnReload, OnReload(true)); - } - catch (const ConfigException &ex) - { - Log() << "Error reloading configuration file: " << ex.GetReason(); - } - return; + expire_all(); + save_databases(); - } - else + try + { + ServerConfig *newconfig = new ServerConfig(); + delete Config; + Config = newconfig; + FOREACH_MOD(I_OnReload, OnReload(true)); + } + catch (const ConfigException &ex) + { + Log() << "Error reloading configuration file: " << ex.GetReason(); + } + break; #endif - if (signum == SIGTERM) - { - signal(SIGTERM, SIG_IGN); + case SIGINT: + case SIGTERM: + signal(signum, SIG_IGN); #ifndef _WIN32 - signal(SIGHUP, SIG_IGN); + signal(SIGHUP, SIG_IGN); #endif - Log() << "Received SIGTERM, exiting."; + Log() << "Received " << strsignal(signum) << " signal (" << signum << "), exiting."; - expire_all(); - save_databases(); - quitmsg = "Shutting down on SIGTERM"; - services_shutdown(); - exit(0); - } - else if (signum == SIGINT) - { - if (nofork) - { - signal(SIGINT, SIG_IGN); - Log() << "Received SIGINT, exiting."; expire_all(); save_databases(); - quitmsg = "Shutting down on SIGINT"; - services_shutdown(); - exit(0); - } + quitmsg = "shutting down on sigterm"; + default: + fatal = true; + break; } } - /* Should we send the signum here as well? -GD */ - FOREACH_MOD(I_OnSignal, OnSignal(quitmsg)); - - if (started) - { - services_shutdown(); - exit(0); - } - else - { - if (isatty(2)) - fprintf(stderr, "%s\n", quitmsg.c_str()); - else - Log() << quitmsg; + FOREACH_MOD(I_OnSignal, OnSignal(signum, quitmsg)); - exit(1); - } + if (fatal) + throw FatalException(quitmsg); } /*************************************************************************/ @@ -465,21 +439,6 @@ int main(int ac, char **av, char **envp) started = true; -#ifndef _WIN32 - if (Config->DumpCore) - { - rlimit rl; - if (getrlimit(RLIMIT_CORE, &rl) == -1) - Log() << "Failed to getrlimit()!"; - else - { - rl.rlim_cur = rl.rlim_max; - if (setrlimit(RLIMIT_CORE, &rl) == -1) - Log() << "setrlimit() failed, cannot increase coredump size"; - } - } -#endif - /* Set up timers */ time_t last_check = time(NULL); ExpireTimer expireTimer(Config->ExpireTimeout, last_check); @@ -570,6 +529,8 @@ int main(int ac, char **av, char **envp) { if (!ex.GetReason().empty()) Log(LOG_TERMINAL) << ex.GetReason(); + if (started) + services_shutdown(); return -1; } |