]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Checking if child pid still exists, if it vanishes we exit
[user/henk/code/inspircd.git] / src / inspircd.cpp
index e58e8039b23506dd72b4c2379a44af08a38c5f67..e8e93bcc52fbe169e4e79cbb0fa498f828acc356 100644 (file)
@@ -54,8 +54,6 @@ using irc::sockets::insp_ntoa;
 using irc::sockets::insp_inaddr;
 using irc::sockets::insp_sockaddr;
 
-char lowermap[255];
-
 InspIRCd* SI = NULL;
 
 void InspIRCd::AddServerName(const std::string &servername)
@@ -109,10 +107,11 @@ void InspIRCd::Rehash(int status)
 
 void InspIRCd::SetSignals(bool SEGVHandler)
 {
-       signal (SIGALRM, SIG_IGN);
-       signal (SIGHUP, InspIRCd::Rehash);
-       signal (SIGPIPE, SIG_IGN);
-       signal (SIGTERM, InspIRCd::Exit);
+       signal(SIGALRM, SIG_IGN);
+       signal(SIGHUP, InspIRCd::Rehash);
+       signal(SIGPIPE, SIG_IGN);
+       signal(SIGTERM, InspIRCd::Exit);
+       signal(SIGCHLD, SIG_IGN);
 }
 
 bool InspIRCd::DaemonSeed()
@@ -122,9 +121,18 @@ bool InspIRCd::DaemonSeed()
                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);
+               /* We wait here for the child process to kill us,
+                * so that the shell prompt doesnt come back over
+                * the output.
+                * Sending a kill with a signal of 0 just checks
+                * if the child pid is still around. If theyre not,
+                * they threw an error and we should give up.
+                */
+               while (kill(childpid, 0) != -1)
+               {
+                       sleep(1);
+               }
+               exit(ERROR);
        }
        setsid ();
        umask (007);
@@ -142,7 +150,7 @@ bool InspIRCd::DaemonSeed()
                if (setrlimit(RLIMIT_CORE, &rl) == -1)
                        this->Log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
        }
-  
+
        return true;
 }
 
@@ -240,9 +248,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        strlcpy(Config->MyExecutable,argv[0],MAXBUF);
 
-       this->MakeLowerMap();
-
-       OpenLog(argv, argc);
+       this->OpenLog(argv, argc);
        this->stats = new serverstats();
        this->Parser = new CommandParser(this);
        this->Timers = new TimerManager();
@@ -281,10 +287,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        this->Res = new DNS(this);
 
-       this->Log(DEBUG,"RES: %08x",this->Res);
-
        this->LoadAllModules();
-
        /* Just in case no modules were loaded - fix for bug #101 */
        this->BuildISupport();
 
@@ -310,9 +313,11 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        if (!Config->nofork)
        {
-               fclose(stdout);
-               fclose(stderr);
+               if (kill(getppid(), SIGTERM) == -1)
+                       printf("Error killing parent process: %s\n",strerror(errno));
                fclose(stdin);
+               fclose(stderr);
+               fclose(stdout);
        }
 
        printf("\nInspIRCd is now running!\n");
@@ -625,38 +630,22 @@ bool InspIRCd::LoadModule(const char* filename)
        for (unsigned int j = 0; j < Config->module_names.size(); j++)
        {
                if (modules[j]->Prioritize() == PRIORITY_LAST)
-               {
                        put_to_back.push_back(Config->module_names[j]);
-               }
                else if (modules[j]->Prioritize() == PRIORITY_FIRST)
-               {
                        put_to_front.push_back(Config->module_names[j]);
-               }
                else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE)
-               {
                        put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
-               }
                else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER)
-               {
                        put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
-               }
        }
        for (unsigned int j = 0; j < put_to_back.size(); j++)
-       {
                MoveToLast(put_to_back[j]);
-       }
        for (unsigned int j = 0; j < put_to_front.size(); j++)
-       {
                MoveToFirst(put_to_front[j]);
-       }
        for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++)
-       {
                MoveBefore(j->first,j->second);
-       }
        for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++)
-       {
                MoveAfter(j->first,j->second);
-       }
        BuildISupport();
        return true;
 }