X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspircd.cpp;h=0fa90fca5b6028ed764f94f6878d470b530320cb;hb=c7a26bc21629ddd4103dac1ff7f9acf45a2c4d35;hp=9516449a0858d27e804987ffba7a3106df3cd9f1;hpb=538a89420955d55cc21d421fe1e961500591479d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 9516449a0..0fa90fca5 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -63,7 +63,6 @@ #include "testsuite.h" InspIRCd* ServerInstance = NULL; -int* mysig = NULL; /** Seperate from the other casemap tables so that code *can* still exclusively rely on RFC casemapping * if it must. @@ -244,13 +243,20 @@ void InspIRCd::QuickExit(int status) exit(status); } +// Required for returning the proper value of EXIT_SUCCESS for the parent process +static void VoidSignalHandler(int signalreceived) +{ + exit(0); +} + bool InspIRCd::DaemonSeed() { #ifdef _WIN32 std::cout << "InspIRCd Process ID: " << con_green << GetCurrentProcessId() << con_reset << std::endl; return true; #else - signal(SIGTERM, InspIRCd::QuickExit); + // Do not use QuickExit here: It will exit with status SIGTERM which would break e.g. daemon scripts + signal(SIGTERM, VoidSignalHandler); int childpid; if ((childpid = fork ()) < 0) @@ -288,7 +294,7 @@ bool InspIRCd::DaemonSeed() #endif } -void InspIRCd::WritePID(const std::string &filename) +void InspIRCd::WritePID(const std::string& filename, bool exitonfail) { #ifndef _WIN32 std::string fname(filename); @@ -301,10 +307,12 @@ void InspIRCd::WritePID(const std::string &filename) outfile.close(); } else - { - std::cout << "Failed to write PID-file '" << fname << "', exiting." << std::endl; - this->Logs->Log("STARTUP",DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str()); - Exit(EXIT_STATUS_PID); + { + if (exitonfail) + std::cout << "Failed to write PID-file '" << fname << "', exiting." << std::endl; + this->Logs->Log("STARTUP",DEFAULT,"Failed to write PID-file '%s'%s",fname.c_str(), (exitonfail ? ", exiting." : "")); + if (exitonfail) + Exit(EXIT_STATUS_PID); } #endif } @@ -470,7 +478,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : /* Set the finished argument values */ Config->cmdline.nofork = (do_nofork != 0); Config->cmdline.forcedebug = (do_debug != 0); - Config->cmdline.writelog = (!do_nolog != 0); + Config->cmdline.writelog = !do_nolog; Config->cmdline.TestSuite = (do_testsuite != 0); if (do_debug) @@ -687,7 +695,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (!g) { - this->Logs->Log("SETGUID", DEFAULT, "getgrnam() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("SETGUID", DEFAULT, "getgrnam(%s) failed (wrong group?): %s", SetGroup.c_str(), strerror(errno)); this->QuickExit(0); } @@ -695,7 +703,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (ret == -1) { - this->Logs->Log("SETGUID", DEFAULT, "setgid() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("SETGUID", DEFAULT, "setgid() failed (wrong group?): %s", strerror(errno)); this->QuickExit(0); } } @@ -710,7 +718,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (!u) { - this->Logs->Log("SETGUID", DEFAULT, "getpwnam() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("SETGUID", DEFAULT, "getpwnam(%s) failed (wrong user?): %s", SetUser.c_str(), strerror(errno)); this->QuickExit(0); } @@ -718,7 +726,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (ret == -1) { - this->Logs->Log("SETGUID", DEFAULT, "setuid() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("SETGUID", DEFAULT, "setuid() failed (wrong user?): %s", strerror(errno)); this->QuickExit(0); } } @@ -808,11 +816,11 @@ int InspIRCd::Run() /* Allow a buffer of two seconds drift on this so that ntpdate etc dont harass admins */ if (TIME.tv_sec < OLDTIME - 2) { - SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %lu secs.", (unsigned long)OLDTIME-TIME.tv_sec); + SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %lu secs.", (unsigned long)(OLDTIME-TIME.tv_sec)); } else if (TIME.tv_sec > OLDTIME + 2) { - SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is jumping FORWARDS! Clock skipped %lu secs.", (unsigned long)TIME.tv_sec - OLDTIME); + SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is jumping FORWARDS! Clock skipped %lu secs.", (unsigned long)(TIME.tv_sec - OLDTIME)); } OLDTIME = TIME.tv_sec; @@ -847,10 +855,10 @@ int InspIRCd::Run() GlobalCulls.Apply(); AtomicActions.Run(); - if (this->s_signal) + if (s_signal) { this->SignalHandler(s_signal); - this->s_signal = 0; + s_signal = 0; } } @@ -874,9 +882,11 @@ bool InspIRCd::AllModulesReportReady(LocalUser* user) return (res == MOD_RES_PASSTHRU); } +sig_atomic_t InspIRCd::s_signal = 0; + void InspIRCd::SetSignal(int signal) { - *mysig = signal; + s_signal = signal; } /* On posix systems, the flow of the program starts right here, with @@ -888,7 +898,6 @@ void InspIRCd::SetSignal(int signal) ENTRYPOINT { new InspIRCd(argc, argv); - mysig = &ServerInstance->s_signal; ServerInstance->Run(); delete ServerInstance; return 0;