]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
More stuff for allowing hostnames in <bind> and <link> again - note there is a FIXME...
[user/henk/code/inspircd.git] / src / inspircd.cpp
index bdb1812c3cf092a8997e9754e32fe86c185afde3..77c2c72b380b682b5519db2ad62c3e8e656bfd5e 100644 (file)
@@ -1,41 +1,48 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/* ---------------------------------------------------------------------
+ * 
+ *              +------------------------------------+
+ *              | Inspire Internet Relay Chat Daemon |
+ *              +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
+ *         InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
+ *                             E-mail:
+ *                      <brain@chatspike.net>
+ *                      <Craig@chatspike.net>
  *     
- * Written by Craig Edwards, Craig McLure, and others.
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ *  Written by Craig Edwards, Craig McLure, and others.
+ *  This program is free but copyrighted software; you can redistribute
+ *  it and/or modify it under the terms of the GNU General Public
+ *  License as published by the Free Software Foundation, version 2
+ *  (two) ONLY.
  *
- * ---------------------------------------------------
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ---------------------------------------------------------------------
  */
 
-/* Now with added unF! ;) */
-
-using namespace std;
-
+#include <algorithm>
 #include "inspircd_config.h"
 #include "inspircd.h"
-#include "inspircd_io.h"
+#include "configreader.h"
 #include <fcntl.h>
 #include <sys/errno.h>
 #include <sys/ioctl.h>
+#include <signal.h>
 #include <time.h>
 #include <string>
 #include <exception>
 #include <stdexcept>
 #include <new>
-#ifdef GCC3
-#include <ext/hash_map>
-#else
-#include <hash_map>
-#endif
 #include <map>
 #include <sstream>
+#include <fstream>
 #include <vector>
 #include <deque>
 #ifdef THREADED_DNS
@@ -66,8 +73,8 @@ InspIRCd* ServerInstance;
 int WHOWAS_STALE = 48; // default WHOWAS Entries last 2 days before they go 'stale'
 int WHOWAS_MAX = 100;  // default 100 people maximum in the WHOWAS list
 
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
+extern ModuleList modules;
+extern FactoryList factory;
 
 std::vector<InspSocket*> module_sockets;
 std::vector<userrec*> local_users;
@@ -100,36 +107,120 @@ chan_hash chanlist;
 servernamelist servernames;
 char lowermap[255];
 
-void AddServerName(std::string servername)
+void AddServerName(const std::string &servername)
 {
        log(DEBUG,"Adding server name: %s",servername.c_str());
-       for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
-       {
-               if (*a == servername)
-                       return;
+       
+       if(find(servernames.begin(), servernames.end(), servername) == servernames.end())
+               servernames.push_back(servername); /* Wasn't already there. */
+}
+
+const char* FindServerNamePtr(const std::string &servername)
+{
+       servernamelist::iterator iter = find(servernames.begin(), servernames.end(), servername);
+       
+       if(iter == servernames.end())
+       {               
+               AddServerName(servername);
+               iter = --servernames.end();
        }
-       servernames.push_back(servername);
+
+       return iter->c_str();
+}
+
+bool FindServerName(const std::string &servername)
+{
+       return (find(servernames.begin(), servernames.end(), servername) != servernames.end());
+}
+
+void Exit(int status)
+{
+       if (Config->log_file)
+               fclose(Config->log_file);
+       send_error("Server shutdown.");
+       exit (status);
+}
+
+void Start()
+{
+       printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
+       printf("(C) ChatSpike Development team.\033[0m\n\n");
+       printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om\033[0m\n");
+       printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
+       printf("Name concept:\t\t\033[1;32mLord_Zathras\033[0m\n\n");
 }
 
-const char* FindServerNamePtr(std::string servername)
+void Killed(int status)
 {
-       for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
+       if (Config->log_file)
+               fclose(Config->log_file);
+       send_error("Server terminated.");
+       exit(status);
+}
+
+void Rehash(int status)
+{
+       WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE));
+       fclose(Config->log_file);
+       OpenLog(NULL,0);
+       Config->Read(false,NULL);
+       FOREACH_MOD(I_OnRehash,OnRehash(""));
+}
+
+void SetSignals()
+{
+       signal (SIGALRM, SIG_IGN);
+       signal (SIGHUP, Rehash);
+       signal (SIGPIPE, SIG_IGN);
+       signal (SIGTERM, Exit);
+       signal (SIGSEGV, Error);
+}
+
+bool DaemonSeed()
+{
+       int childpid;
+       if ((childpid = fork ()) < 0)
+               return (ERROR);
+       else if (childpid > 0)
+       {
+               /* We wait a few seconds here, so that the shell prompt doesnt come back over the output */
+               sleep(6);
+               exit (0);
+       }
+       setsid ();
+       umask (007);
+       printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
+
+       rlimit rl;
+       if (getrlimit(RLIMIT_CORE, &rl) == -1)
+       {
+               log(DEFAULT,"Failed to getrlimit()!");
+               return false;
+       }
+       else
        {
-               if (*a == servername)
-                       return a->c_str();
+               rl.rlim_cur = rl.rlim_max;
+               if (setrlimit(RLIMIT_CORE, &rl) == -1)
+                       log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
        }
-       AddServerName(servername);
-       return FindServerNamePtr(servername);
+  
+       return true;
 }
 
-bool FindServerName(std::string servername)
+void WritePID(const std::string &filename)
 {
-       for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
+       std::ofstream outfile(filename.c_str());
+       if (outfile.is_open())
        {
-               if (*a == servername)
-                       return true;
+               outfile << getpid();
+               outfile.close();
+       }
+       else
+       {
+               printf("Failed to write PID-file '%s', exiting.\n",filename.c_str());
+               log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str());
+               Exit(0);
        }
-       return false;
 }
 
 std::string InspIRCd::GetRevision()
@@ -292,7 +383,7 @@ void InspIRCd::erase_module(int j)
        {
                if (v1 == j)
                {
-                       delete *m;
+                       DELETE(*m);
                        modules.erase(m);
                        modules.push_back(NULL);
                        break;
@@ -737,7 +828,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                                                }
                                        }
                                        s->Close();
-                                       delete s;
+                                       DELETE(s);
                                }
                                else if (!s)
                                {
@@ -867,7 +958,7 @@ int main(int argc, char** argv)
        {
                ServerInstance = new InspIRCd(argc, argv);
                ServerInstance->Run();
-               delete ServerInstance;
+               DELETE(ServerInstance);
        }
        catch (std::bad_alloc)
        {