]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
* Changed forking code, now the parent will attempt to retrieve the exit code of...
authorburlex <burlex@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 8 Jun 2007 21:35:14 +0000 (21:35 +0000)
committerburlex <burlex@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 8 Jun 2007 21:35:14 +0000 (21:35 +0000)
. Exit code 14 means the creation of the forked process under windows failed.

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7257 e03df62e-2008-0410-955e-edbf42e46eb7

src/inspircd.cpp

index 779061e833e005907eaa118658ae4dcbbc342aa7..fe8366147f96cad2e56db768c00d3f72ab0c3df9 100644 (file)
@@ -44,7 +44,7 @@
 #else
 static DWORD owner_processid = 0;
 
-bool WindowsForkStart(InspIRCd * Instance)
+DWORD WindowsForkStart(InspIRCd * Instance)
 {
        /* Windows implementation of fork() :P */
        // Build the command line arguments.
@@ -67,10 +67,7 @@ bool WindowsForkStart(InspIRCd * Instance)
        // Create the "startup" event
        HANDLE fork_event = CreateEvent(0, TRUE, FALSE, "InspStartup");
        if(!fork_event)
-       {
-               printf("CreateEvent: %s\n", dlerror());
                return false;
-       }
 
        // Launch our "forked" process.
        BOOL bSuccess = CreateProcess ( module, module, 
@@ -99,19 +96,21 @@ bool WindowsForkStart(InspIRCd * Instance)
        // Wait for the new process to kill us. If there is some error, the new process will end and we will end up at the next line.
        WaitForSingleObject(procinfo.hProcess, INFINITE);
 
-       // If we hit this it means startup failed. :(
-       return true;
+       // If we hit this it means startup failed, default to 14 if this fails.
+       DWORD ExitCode = 14;
+       GetExitCodeProcess(procinfo.hProcess, &ExitCode);
+       CloseHandle(procinfo.hThread);
 }
 
 void WindowsForkKillOwner(InspIRCd * Instance)
 {
        HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, owner_processid);
        if(!hProcess || !owner_processid)
-               exit(1);
+               Instance->Exit(14);
 
        // die die die
        if(!TerminateProcess(hProcess, 0))
-               exit(1);
+               Instance->Exit(14);
 
        CloseHandle(hProcess);
 }
@@ -143,7 +142,7 @@ const char* ExitCodes[] =
                "Refusing to start up as root", /* 11 */
                "Found a <die> tag!", /* 12 */
                "Couldn't load module on startup", /* 13 */
-               "", /* 14 */
+               "Could not create forked process", /* 14 */
                "Received SIGTERM", /* 15 */
 };
 
@@ -507,8 +506,9 @@ InspIRCd::InspIRCd(int argc, char** argv)
        // Handle forking
        if(!do_nofork && !owner_processid)
        {
-               if(WindowsForkStart(this))
-                       Exit(0);
+               DWORD ExitCode = WindowsForkStart(this);
+               if(ExitCode)
+                       Exit(ExitCode);
        }
 
        // Set up winsock