[IPCPipe] Launch the worker process
This commit is contained in:
parent
8764d8327f
commit
ef01b4e617
@ -284,6 +284,18 @@ namespace Components
|
|||||||
Logger::Print("Sending ping to pipe!\n");
|
Logger::Print("Sending ping to pipe!\n");
|
||||||
IPCPipe::Write("ping", "");
|
IPCPipe::Write("ping", "");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
STARTUPINFOA sInfo;
|
||||||
|
PROCESS_INFORMATION pInfo;
|
||||||
|
|
||||||
|
ZeroMemory(&sInfo, sizeof(sInfo));
|
||||||
|
ZeroMemory(&pInfo, sizeof(pInfo));
|
||||||
|
sInfo.cb = sizeof(sInfo);
|
||||||
|
|
||||||
|
CreateProcessA("iw4x/iw4xworker.exe", const_cast<char*>(Utils::String::VA("-parentProc %d", GetCurrentProcessId())), nullptr, nullptr, false, NULL, nullptr, nullptr, &sInfo, &pInfo);
|
||||||
|
|
||||||
|
if (pInfo.hThread && pInfo.hThread != INVALID_HANDLE_VALUE) CloseHandle(pInfo.hThread);
|
||||||
|
if (pInfo.hProcess && pInfo.hProcess != INVALID_HANDLE_VALUE) CloseHandle(pInfo.hProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPCPipe::preDestroy()
|
void IPCPipe::preDestroy()
|
||||||
|
@ -1,15 +1,57 @@
|
|||||||
#include "STDInclude.hpp"
|
#include "STDInclude.hpp"
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
|
||||||
int main(int /*argc*/, char /*argv*/[])
|
void worker(bool* terminator)
|
||||||
{
|
{
|
||||||
AllocConsole();
|
printf("Worker started\n");
|
||||||
AttachConsole(GetCurrentProcessId());
|
|
||||||
freopen("CONOUT$", "w", stdout);
|
while(!*terminator)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(1ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Terminating worker\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
bool terminator = false;
|
||||||
|
char* command = "-parentProc ";
|
||||||
|
char* parentProc = strstr(GetCommandLineA(), command);
|
||||||
|
|
||||||
|
if (!parentProc)
|
||||||
|
{
|
||||||
|
printf("No parent process argument found\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentProc += strlen(command);
|
||||||
|
int pid = atoi(parentProc);
|
||||||
|
|
||||||
|
printf("Attaching to process %d...\n", pid);
|
||||||
|
|
||||||
|
HANDLE processHandle = OpenProcess(SYNCHRONIZE, FALSE, pid);
|
||||||
|
if (!processHandle || processHandle == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
printf("Unable to attach to parent process\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Successfully attached to parent process\n");
|
||||||
|
printf("Starting worker...\n");
|
||||||
|
|
||||||
|
std::thread runner(worker, &terminator);
|
||||||
|
|
||||||
|
WaitForSingleObject(processHandle, INFINITE);
|
||||||
|
CloseHandle(processHandle);
|
||||||
|
|
||||||
|
terminator = true;
|
||||||
|
|
||||||
|
printf("Awaiting worker termination...\n");
|
||||||
|
if (runner.joinable()) runner.join();
|
||||||
|
printf("Worker terminated\n");
|
||||||
|
|
||||||
printf("Hi");
|
|
||||||
_getch();
|
_getch();
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user