Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-threaded asynchronous svrplus #198

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
[svrplus] split InstallServer
Now all blocking code is in ThreadProc
  • Loading branch information
DankRank committed Oct 20, 2019
commit 12818e8838b1bda0953bd2fe2869522e35fa8598
51 changes: 40 additions & 11 deletions src/svrplus/svrplus.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,13 @@ typedef enum {
/**
* (Un)installs the COM Server DLL.
*
* @param isUninstall [in] When true, uninstalls the DLL, instead of installing it.
* @param is64 [in] When true, installs 64-bit version.
* @param pErrorCode [out,opt] Additional error code.
* @param isUninstall [in] When true, uninstalls the DLL, instead of installing it.
* @param is64 [in] When true, installs 64-bit version.
* @param pHandle [out,opt] Process handle.
* @param pErrorCode [out,opt] Additional error code.
* @return InstallServerResult
*/
static InstallServerResult InstallServer(bool isUninstall, bool is64, DWORD *pErrorCode)
static InstallServerResult InstallServer(bool isUninstall, bool is64, HANDLE *pHandle, DWORD *pErrorCode)
{
TCHAR regsvr32_path[MAX_PATH];
TCHAR args[14 + MAX_PATH + 4 + 3 + ARRAY_SIZE(str_rp64path)] = _T("regsvr32.exe \"");
Expand All @@ -287,7 +288,6 @@ static InstallServerResult InstallServer(bool isUninstall, bool is64, DWORD *pEr

STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD status;

// Determine the REGSVR32 path.
int ret = GetSystemDirFilePath(regsvr32_path, ARRAY_SIZE(regsvr32_path), _T("regsvr32.exe"), is64);
Expand Down Expand Up @@ -335,12 +335,32 @@ static InstallServerResult InstallServer(bool isUninstall, bool is64, DWORD *pEr
return ISR_CREATEPROCESS_FAILED;
}

// Wait for the process to exit.
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &status);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

*pHandle = pi.hProcess;

// The calles should wait for the process to exit.
return ISR_OK;
}

/**
* (Un)installs the COM Server DLL.
*
* @param handle [in] Process handle from InstallServer
* @param pErrorCode [out,opt] Additional error code.
* @return InstallServerResult
*/
static InstallServerResult InstallServerEnd(HANDLE handle, DWORD *pErrorCode)
{
DWORD status;

if (!handle) {
return ISR_FATAL_ERROR;
}

GetExitCodeProcess(handle, &status);
CloseHandle(handle);

switch (status) {
case STILL_ACTIVE:
// Process is still active...
Expand Down Expand Up @@ -456,17 +476,26 @@ static unsigned int WINAPI ThreadProc(LPVOID lpParameter)
TCHAR msg32[256], msg64[256];
InstallServerResult res32 = ISR_OK, res64 = ISR_OK;
DWORD errorCode = 0;
HANDLE hProcess;

ThreadParams *const params = (ThreadParams*)lpParameter;

// Try to (un)install the 64-bit version.
if (g_is64bit) {
res64 = InstallServer(params->isUninstall, true, &errorCode);
res64 = InstallServer(params->isUninstall, true, &hProcess, &errorCode);
if (res64 == ISR_OK) {
WaitForSingleObject(hProcess, INFINITE);
res64 = InstallServerEnd(hProcess, &errorCode);
}
InstallServerErrorMsg(res64, errorCode, params->isUninstall, true, msg64, ARRAY_SIZE(msg64));
}

// Try to (un)install the 32-bit version.
res32 = InstallServer(params->isUninstall, false, &errorCode);
res32 = InstallServer(params->isUninstall, false, &hProcess, &errorCode);
if (res32 == ISR_OK) {
WaitForSingleObject(hProcess, INFINITE);
res32 = InstallServerEnd(hProcess, &errorCode);
}
InstallServerErrorMsg(res32, errorCode, params->isUninstall, false, msg32, ARRAY_SIZE(msg32));

if (res32 == ISR_OK && res64 == ISR_OK) {
Expand Down