+#else
+static DWORD owner_processid = 0;
+
+bool WindowsForkStart(InspIRCd * Instance)
+{
+ /* Windows implementation of fork() :P */
+ // Build the command line arguments.
+ string command_line;
+ for(int i = 0; i < Instance->Config->argc; ++i)
+ command_line += Instance->Config->argv[i];
+
+ char module[MAX_PATH];
+ if(!GetModuleFileName(NULL, module, MAX_PATH))
+ return false;
+
+ STARTUPINFO startupinfo;
+ PROCESS_INFORMATION procinfo;
+ ZeroMemory(&startupinfo, sizeof(STARTUPINFO));
+ ZeroMemory(&procinfo, sizeof(PROCESS_INFORMATION));
+
+ // Fill in the startup info struct
+ GetStartupInfo(&startupinfo);
+
+ // 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,
+ 0, // PROCESS_SECURITY_ATTRIBUTES
+ 0, // THREAD_SECURITY_ATTRIBUTES
+ TRUE, // We went to inherit handles.
+ CREATE_SUSPENDED | // Suspend the primary thread of the new process
+ CREATE_PRESERVE_CODE_AUTHZ_LEVEL, // Allow us full access to the process
+ 0, // ENVIRONMENT
+ 0, // CURRENT_DIRECTORY
+ &startupinfo, // startup info
+ &procinfo); // process info
+
+ if(!bSuccess)
+ return false;
+
+ // Set the owner process id in the target process.
+ SIZE_T written = 0;
+ DWORD pid = GetCurrentProcessId();
+ if(!WriteProcessMemory(procinfo.hProcess, &owner_processid, &pid, sizeof(DWORD), &written) || written != sizeof(DWORD))
+ return false;
+
+ // Resume the other thread (let it start)
+ ResumeThread(procinfo.hThread);
+
+ // 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;
+}
+
+void WindowsForkKillOwner(InspIRCd * Instance)
+{
+ HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, owner_processid);
+ if(!hProcess || !owner_processid)
+ exit(1);
+
+ // die die die
+ if(!TerminateProcess(hProcess, 0))
+ exit(1);
+
+ CloseHandle(hProcess);
+}
+