mirror of
https://github.com/debauchee/barrier.git
synced 2025-08-03 16:48:48 +02:00
Patch by Jerry:
- Fixed line endings - Integ test for file transfer - Fixed crashed problem when log info is larger than 2048 bytes - Fixed compile error caused by std exception (by Feng ye) - Fixed include path on Mac and linux (by Feng ye)
This commit is contained in:
parent
c368013f13
commit
394ece004a
72 changed files with 3884 additions and 3127 deletions
|
@ -203,7 +203,7 @@ CMSWindowsRelauncher::duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTE
|
|||
LOG((CLOG_ERR "could not open token, process handle: %d (error: %i)", process, GetLastError()));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
LOG((CLOG_DEBUG "got token %i, duplicating", sourceToken));
|
||||
|
||||
HANDLE newToken;
|
||||
|
@ -216,7 +216,7 @@ CMSWindowsRelauncher::duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTE
|
|||
sourceToken, GetLastError()));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
LOG((CLOG_DEBUG "duplicated, new token: %i", newToken));
|
||||
return newToken;
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ CMSWindowsRelauncher::getSessionToken(DWORD sessionId, LPSECURITY_ATTRIBUTES sec
|
|||
LOG((CLOG_ERR "could not duplicate token (error: %i)", GetLastError()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
LOG((CLOG_DEBUG "duplicated, new token: %i", newToken));
|
||||
return newToken;
|
||||
}
|
||||
|
@ -284,10 +284,10 @@ CMSWindowsRelauncher::mainLoop(void*)
|
|||
|
||||
DWORD sessionId = -1;
|
||||
bool launched = false;
|
||||
|
||||
SECURITY_ATTRIBUTES saAttr;
|
||||
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||
saAttr.bInheritHandle = TRUE;
|
||||
|
||||
SECURITY_ATTRIBUTES saAttr;
|
||||
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||
saAttr.bInheritHandle = TRUE;
|
||||
saAttr.lpSecurityDescriptor = NULL;
|
||||
|
||||
if (!CreatePipe(&m_stdOutRead, &m_stdOutWrite, &saAttr, 0)) {
|
||||
|
@ -308,27 +308,27 @@ CMSWindowsRelauncher::mainLoop(void*)
|
|||
sendSasEvent = CreateEvent(NULL, FALSE, FALSE, "Global\\SendSAS");
|
||||
}
|
||||
|
||||
DWORD newSessionId = getSessionId();
|
||||
|
||||
bool running = false;
|
||||
if (launched) {
|
||||
|
||||
DWORD exitCode;
|
||||
GetExitCodeProcess(pi.hProcess, &exitCode);
|
||||
running = (exitCode == STILL_ACTIVE);
|
||||
|
||||
if (!running) {
|
||||
failures++;
|
||||
LOG((CLOG_INFO "detected application not running, pid=%d, failures=%d", pi.dwProcessId, failures));
|
||||
|
||||
// increasing backoff period, maximum of 10 seconds.
|
||||
int timeout = (failures * 2) < 10 ? (failures * 2) : 10;
|
||||
LOG((CLOG_DEBUG "waiting, backoff period is %d seconds", timeout));
|
||||
ARCH->sleep(timeout);
|
||||
|
||||
// double check, in case process started after we waited.
|
||||
GetExitCodeProcess(pi.hProcess, &exitCode);
|
||||
running = (exitCode == STILL_ACTIVE);
|
||||
DWORD newSessionId = getSessionId();
|
||||
|
||||
bool running = false;
|
||||
if (launched) {
|
||||
|
||||
DWORD exitCode;
|
||||
GetExitCodeProcess(pi.hProcess, &exitCode);
|
||||
running = (exitCode == STILL_ACTIVE);
|
||||
|
||||
if (!running) {
|
||||
failures++;
|
||||
LOG((CLOG_INFO "detected application not running, pid=%d, failures=%d", pi.dwProcessId, failures));
|
||||
|
||||
// increasing backoff period, maximum of 10 seconds.
|
||||
int timeout = (failures * 2) < 10 ? (failures * 2) : 10;
|
||||
LOG((CLOG_DEBUG "waiting, backoff period is %d seconds", timeout));
|
||||
ARCH->sleep(timeout);
|
||||
|
||||
// double check, in case process started after we waited.
|
||||
GetExitCodeProcess(pi.hProcess, &exitCode);
|
||||
running = (exitCode == STILL_ACTIVE);
|
||||
}
|
||||
else {
|
||||
// reset failures when running.
|
||||
|
@ -383,7 +383,7 @@ CMSWindowsRelauncher::mainLoop(void*)
|
|||
si.cb = sizeof(STARTUPINFO);
|
||||
si.lpDesktop = "winsta0\\Default"; // TODO: maybe this should be \winlogon if we have logonui.exe?
|
||||
si.hStdError = m_stdOutWrite;
|
||||
si.hStdOutput = m_stdOutWrite;
|
||||
si.hStdOutput = m_stdOutWrite;
|
||||
si.dwFlags |= STARTF_USESTDHANDLES;
|
||||
|
||||
LPVOID environment;
|
||||
|
@ -502,45 +502,45 @@ CMSWindowsRelauncher::outputLoop(void*)
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsRelauncher::shutdownProcess(HANDLE handle, DWORD pid, int timeout)
|
||||
{
|
||||
DWORD exitCode;
|
||||
GetExitCodeProcess(handle, &exitCode);
|
||||
if (exitCode != STILL_ACTIVE)
|
||||
return;
|
||||
|
||||
CIpcShutdownMessage shutdown;
|
||||
m_ipcServer.send(shutdown, kIpcClientNode);
|
||||
|
||||
// wait for process to exit gracefully.
|
||||
double start = ARCH->time();
|
||||
while (true)
|
||||
{
|
||||
GetExitCodeProcess(handle, &exitCode);
|
||||
if (exitCode != STILL_ACTIVE) {
|
||||
// yay, we got a graceful shutdown. there should be no hook in use errors!
|
||||
LOG((CLOG_INFO "process %d was shutdown gracefully", pid));
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
||||
double elapsed = (ARCH->time() - start);
|
||||
if (elapsed > timeout) {
|
||||
// if timeout reached, kill forcefully.
|
||||
// calling TerminateProcess on synergy is very bad!
|
||||
// it causes the hook DLL to stay loaded in some apps,
|
||||
// making it impossible to start synergy again.
|
||||
LOG((CLOG_WARN "shutdown timed out after %d secs, forcefully terminating", (int)elapsed));
|
||||
TerminateProcess(handle, kExitSuccess);
|
||||
break;
|
||||
}
|
||||
|
||||
ARCH->sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsRelauncher::shutdownProcess(HANDLE handle, DWORD pid, int timeout)
|
||||
{
|
||||
DWORD exitCode;
|
||||
GetExitCodeProcess(handle, &exitCode);
|
||||
if (exitCode != STILL_ACTIVE)
|
||||
return;
|
||||
|
||||
CIpcShutdownMessage shutdown;
|
||||
m_ipcServer.send(shutdown, kIpcClientNode);
|
||||
|
||||
// wait for process to exit gracefully.
|
||||
double start = ARCH->time();
|
||||
while (true)
|
||||
{
|
||||
GetExitCodeProcess(handle, &exitCode);
|
||||
if (exitCode != STILL_ACTIVE) {
|
||||
// yay, we got a graceful shutdown. there should be no hook in use errors!
|
||||
LOG((CLOG_INFO "process %d was shutdown gracefully", pid));
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
||||
double elapsed = (ARCH->time() - start);
|
||||
if (elapsed > timeout) {
|
||||
// if timeout reached, kill forcefully.
|
||||
// calling TerminateProcess on synergy is very bad!
|
||||
// it causes the hook DLL to stay loaded in some apps,
|
||||
// making it impossible to start synergy again.
|
||||
LOG((CLOG_WARN "shutdown timed out after %d secs, forcefully terminating", (int)elapsed));
|
||||
TerminateProcess(handle, kExitSuccess);
|
||||
break;
|
||||
}
|
||||
|
||||
ARCH->sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -597,4 +597,4 @@ CMSWindowsRelauncher::shutdownExistingProcesses()
|
|||
}
|
||||
|
||||
CloseHandle(snapshot);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue