]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Merge pull request #545 from SaberUK/master+logging-cleanup
[user/henk/code/inspircd.git] / src / inspircd.cpp
index bd15624739eee4c40e54cf3af8e6c1db35085927..fe33045692ede0004cedd1c8fcdb33cb94f2c6ab 100644 (file)
@@ -62,7 +62,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.
@@ -132,8 +131,6 @@ void InspIRCd::Cleanup()
        /* Must be deleted before modes as it decrements modelines */
        if (FakeClient)
                FakeClient->cull();
-       if (Res)
-               Res->cull();
        DeleteZero(this->FakeClient);
        DeleteZero(this->Users);
        DeleteZero(this->Modes);
@@ -144,7 +141,6 @@ void InspIRCd::Cleanup()
        DeleteZero(this->BanCache);
        DeleteZero(this->SNO);
        DeleteZero(this->Config);
-       DeleteZero(this->Res);
        DeleteZero(this->chanlist);
        DeleteZero(this->PI);
        DeleteZero(this->Threads);
@@ -234,13 +230,13 @@ bool InspIRCd::DaemonSeed()
        rlimit rl;
        if (getrlimit(RLIMIT_CORE, &rl) == -1)
        {
-               this->Logs->Log("STARTUP",LOG_DEFAULT,"Failed to getrlimit()!");
+               this->Logs->Log("STARTUP", LOG_DEFAULT, "Failed to getrlimit()!");
                return false;
        }
        rl.rlim_cur = rl.rlim_max;
 
        if (setrlimit(RLIMIT_CORE, &rl) == -1)
-                       this->Logs->Log("STARTUP",LOG_DEFAULT,"setrlimit() failed, cannot increase coredump size.");
+                       this->Logs->Log("STARTUP", LOG_DEFAULT, "setrlimit() failed, cannot increase coredump size.");
 
        return true;
 #endif
@@ -261,7 +257,7 @@ void InspIRCd::WritePID(const std::string &filename)
        else
        {
                std::cout << "Failed to write PID-file '" << fname << "', exiting." << std::endl;
-               this->Logs->Log("STARTUP",LOG_DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
+               this->Logs->Log("STARTUP", LOG_DEFAULT, "Failed to write PID-file '%s', exiting.",fname.c_str());
                Exit(EXIT_STATUS_PID);
        }
 #endif
@@ -275,7 +271,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
          * THIS MUST MATCH THE ORDER OF DECLARATION OF THE FUNCTORS, e.g. the methods
          * themselves within the class.
          */
-        NICKForced("NICKForced", NULL),
         OperQuit("OperQuit", NULL),
         GenRandom(&HandleGenRandom),
         IsChannel(&HandleIsChannel),
@@ -286,7 +281,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 {
        ServerInstance = this;
 
-       Extensions.Register(&NICKForced);
        Extensions.Register(&OperQuit);
 
        FailedPortList pl;
@@ -309,7 +303,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->Parser = 0;
        this->XLines = 0;
        this->Modes = 0;
-       this->Res = 0;
        this->ConfigThread = NULL;
        this->FakeClient = NULL;
 
@@ -326,8 +319,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        /* Default implementation does nothing */
        this->PI = new ProtocolInterface;
 
-       this->s_signal = 0;
-
        // Create base manager classes early, so nothing breaks
        this->Users = new UserManager;
 
@@ -373,7 +364,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        struct option longopts[] =
        {
                { "nofork",     no_argument,            &do_nofork,     1       },
-               { "logfile",    required_argument,      NULL,           'f'     },
                { "config",     required_argument,      NULL,           'c'     },
                { "debug",      no_argument,            &do_debug,      1       },
                { "nolog",      no_argument,            &do_nolog,      1       },
@@ -384,14 +374,10 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        };
 
        int index;
-       while ((c = getopt_long(argc, argv, ":c:f:", longopts, &index)) != -1)
+       while ((c = getopt_long(argc, argv, ":c:", longopts, &index)) != -1)
        {
                switch (c)
                {
-                       case 'f':
-                               /* Log filename was set */
-                               Config->cmdline.startup_log = optarg;
-                       break;
                        case 'c':
                                /* Config filename was set */
                                ConfigFileName = optarg;
@@ -404,8 +390,8 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                        default:
                                /* Fall through to handle other weird values too */
                                std::cout << "Unknown parameter '" << argv[optind-1] << "'" << std::endl;
-                               std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--debug] [--logfile <filename>] " << std::endl <<
-                                       std::string(static_cast<int>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version] [--config <config>] [--testsuite]" << std::endl;
+                               std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--debug] [--config <config>]" << std::endl <<
+                                       std::string(static_cast<int>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version] [--testsuite]" << std::endl;
                                Exit(EXIT_STATUS_ARGV);
                        break;
                }
@@ -438,11 +424,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                FileLogStream* fls = new FileLogStream(LOG_RAWIO, fw);
                Logs->AddLogTypes("*", fls, true);
        }
-       else if (!this->OpenLog(argv, argc))
-       {
-               std::cout << "ERROR: Could not open initial logfile " << Config->cmdline.startup_log << ": " << strerror(errno) << std::endl << std::endl;
-               Exit(EXIT_STATUS_LOG);
-       }
 
        if (!ServerConfig::FileExists(ConfigFileName.c_str()))
        {
@@ -459,7 +440,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
 #endif
                {
                        std::cout << "ERROR: Cannot open config file: " << ConfigFileName << std::endl << "Exiting..." << std::endl;
-                       this->Logs->Log("STARTUP",LOG_DEFAULT,"Unable to open config file %s", ConfigFileName.c_str());
+                       this->Logs->Log("STARTUP", LOG_DEFAULT, "Unable to open config file %s", ConfigFileName.c_str());
                        Exit(EXIT_STATUS_CONFIG);
                }
        }
@@ -512,27 +493,12 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        Logs->OpenFileLogs();
        ModeParser::InitBuiltinModes();
 
-       this->Res = new DNS();
-
-       /*
-        * Initialise SID/UID.
-        * For an explanation as to exactly how this works, and why it works this way, see GetUID().
-        *   -- w00t
-        */
+       // If we don't have a SID, generate one based on the server name and the server description
        if (Config->sid.empty())
-       {
-               // Generate one
-               unsigned int sid = 0;
-               char sidstr[4];
+               Config->sid = UIDGenerator::GenerateSID(Config->ServerName, Config->ServerDesc);
 
-               for (const char* x = Config->ServerName.c_str(); *x; ++x)
-                       sid = 5 * sid + *x;
-               for (const char* y = Config->ServerDesc.c_str(); *y; ++y)
-                       sid = 5 * sid + *y;
-               sprintf(sidstr, "%03d", sid % 1000);
-
-               Config->sid = sidstr;
-       }
+       // Initialize the UID generator with our sid
+       this->UIDGen.init(Config->sid);
 
        /* set up fake client again this time with the correct uid */
        this->FakeClient = new FakeUser(Config->sid, Config->ServerName);
@@ -605,7 +571,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        }
        else
        {
-               Logs->Log("STARTUP", LOG_DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
+               Logs->Log("STARTUP", LOG_DEFAULT, "Keeping pseudo-tty open as we are running in the foreground.");
        }
 #else
        /* Set win32 service as running, if we are running as a service */
@@ -729,7 +695,7 @@ int InspIRCd::Run()
                if (this->ConfigThread && this->ConfigThread->IsDone())
                {
                        /* Rehash has completed */
-                       this->Logs->Log("CONFIG",LOG_DEBUG,"Detected ConfigThread exiting, tidying up...");
+                       this->Logs->Log("CONFIG", LOG_DEBUG, "Detected ConfigThread exiting, tidying up...");
 
                        this->ConfigThread->Finish();
 
@@ -806,10 +772,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;
                }
        }
 
@@ -818,10 +784,6 @@ int InspIRCd::Run()
 
 /**********************************************************************************/
 
-/**
- * An ircd in five lines! bwahahaha. ahahahahaha. ahahah *cough*.
- */
-
 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
  * registration timeout maximum seconds)
@@ -833,9 +795,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
@@ -847,7 +811,6 @@ void InspIRCd::SetSignal(int signal)
 ENTRYPOINT
 {
        new InspIRCd(argc, argv);
-       mysig = &ServerInstance->s_signal;
        ServerInstance->Run();
        delete ServerInstance;
        return 0;