aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/platform/MSWindowsWatchdog.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:35 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:35 -0500
commit58fb7a0cee13d84170aac52f3f89d91888e1afe3 (patch)
tree1d6312ba15f9ece5a8031e5280dfb8b38be8dfa3 /src/lib/platform/MSWindowsWatchdog.cpp
parent28db84b46139c9bb2bbcac8c6cc56e71d1e35629 (diff)
parentbeb08eb751fa8e1f72042f263316ab5e5ddb596d (diff)
Update upstream source from tag 'upstream/2.4.0+dfsg'
Update to upstream version '2.4.0+dfsg' with Debian dir 4b6668cc08c7b0e56b1e1f7b4e89ecdb316182a0
Diffstat (limited to 'src/lib/platform/MSWindowsWatchdog.cpp')
-rw-r--r--src/lib/platform/MSWindowsWatchdog.cpp60
1 files changed, 27 insertions, 33 deletions
diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp
index 0aa5505..2d9a61c 100644
--- a/src/lib/platform/MSWindowsWatchdog.cpp
+++ b/src/lib/platform/MSWindowsWatchdog.cpp
@@ -6,7 +6,7 @@
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
- *
+ *
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -29,7 +29,6 @@
#include "arch/win32/XArchWindows.h"
#include "arch/Arch.h"
#include "base/log_outputters.h"
-#include "base/TMethodJob.h"
#include "base/Log.h"
#include "common/Version.h"
@@ -81,21 +80,18 @@ MSWindowsWatchdog::MSWindowsWatchdog(
{
}
-void
+void
MSWindowsWatchdog::startAsync()
{
- m_thread = new Thread(new TMethodJob<MSWindowsWatchdog>(
- this, &MSWindowsWatchdog::mainLoop, nullptr));
-
- m_outputThread = new Thread(new TMethodJob<MSWindowsWatchdog>(
- this, &MSWindowsWatchdog::outputLoop, nullptr));
+ m_thread = new Thread([this](){ main_loop(); });
+ m_outputThread = new Thread([this](){ output_loop(); });
}
void
MSWindowsWatchdog::stop()
{
m_monitoring = false;
-
+
m_thread->wait(5);
delete m_thread;
@@ -117,7 +113,7 @@ MSWindowsWatchdog::duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES s
LOG((CLOG_ERR "could not open token, process handle: %d", process));
throw XArch(new XArchEvalWindows());
}
-
+
LOG((CLOG_DEBUG "got token %i, duplicating", sourceToken));
HANDLE newToken;
@@ -129,22 +125,22 @@ MSWindowsWatchdog::duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES s
LOG((CLOG_ERR "could not duplicate token %i", sourceToken));
throw XArch(new XArchEvalWindows());
}
-
+
LOG((CLOG_DEBUG "duplicated, new token: %i", newToken));
return newToken;
}
-HANDLE
+HANDLE
MSWindowsWatchdog::getUserToken(LPSECURITY_ATTRIBUTES security)
{
- // always elevate if we are at the vista/7 login screen. we could also
+ // always elevate if we are at the vista/7 login screen. we could also
// elevate for the uac dialog (consent.exe) but this would be pointless,
// since barrier would re-launch as non-elevated after the desk switch,
// and so would be unusable with the new elevated process taking focus.
if (m_elevateProcess || m_autoElevated) {
LOG((CLOG_DEBUG "getting elevated token, %s",
(m_elevateProcess ? "elevation required" : "at login screen")));
-
+
HANDLE process;
if (!m_session.isProcessInSession("winlogon.exe", &process)) {
throw XMSWindowsWatchdogError("cannot get user token without winlogon.exe");
@@ -157,8 +153,7 @@ MSWindowsWatchdog::getUserToken(LPSECURITY_ATTRIBUTES security)
}
}
-void
-MSWindowsWatchdog::mainLoop(void*)
+void MSWindowsWatchdog::main_loop()
{
shutdownExistingProcesses();
@@ -169,10 +164,10 @@ MSWindowsWatchdog::mainLoop(void*)
sendSasFunc = (SendSas)GetProcAddress(sasLib, "SendSAS");
}
- SECURITY_ATTRIBUTES saAttr;
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
+ SECURITY_ATTRIBUTES saAttr;
+ saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
+ saAttr.bInheritHandle = TRUE;
+ saAttr.lpSecurityDescriptor = NULL;
if (!CreatePipe(&m_stdOutRead, &m_stdOutWrite, &saAttr, 0)) {
throw XArch(new XArchEvalWindows());
@@ -196,7 +191,7 @@ MSWindowsWatchdog::mainLoop(void*)
LOG((CLOG_INFO "backing off, wait=%ds, failures=%d", timeout, m_processFailures));
ARCH->sleep(timeout);
}
-
+
if (!getCommand().empty() && ((m_processFailures != 0) || m_session.hasChanged() || m_commandChanged)) {
startProcess();
}
@@ -205,7 +200,7 @@ MSWindowsWatchdog::mainLoop(void*)
m_processFailures++;
m_processRunning = false;
-
+
LOG((CLOG_WARN "detected application not running, pid=%d",
m_processInfo.dwProcessId));
}
@@ -228,7 +223,7 @@ MSWindowsWatchdog::mainLoop(void*)
// if the sas event failed, wait by sleeping.
ARCH->sleep(1);
-
+
}
catch (std::exception& e) {
LOG((CLOG_ERR "failed to launch, error: %s", e.what()));
@@ -248,7 +243,7 @@ MSWindowsWatchdog::mainLoop(void*)
LOG((CLOG_DEBUG "terminated running process on exit"));
shutdownProcess(m_processInfo.hProcess, m_processInfo.dwProcessId, 20);
}
-
+
LOG((CLOG_DEBUG "watchdog main thread finished"));
}
@@ -260,7 +255,7 @@ MSWindowsWatchdog::isProcessActive()
return exitCode == STILL_ACTIVE;
}
-void
+void
MSWindowsWatchdog::setFileLogOutputter(FileLogOutputter* outputter)
{
m_fileLogOutputter = outputter;
@@ -367,7 +362,7 @@ BOOL MSWindowsWatchdog::doStartProcessAsUser(std::string& command, HANDLE userTo
throw XArch(new XArchEvalWindows);
}
- DWORD creationFlags =
+ DWORD creationFlags =
NORMAL_PRIORITY_CLASS |
CREATE_NO_WINDOW |
CREATE_UNICODE_ENVIRONMENT;
@@ -421,14 +416,13 @@ MSWindowsWatchdog::getCommand() const
return cmd;
}
-void
-MSWindowsWatchdog::outputLoop(void*)
+void MSWindowsWatchdog::output_loop()
{
// +1 char for \0
CHAR buffer[kOutputBufferSize + 1];
while (m_monitoring) {
-
+
DWORD bytesRead;
BOOL success = ReadFile(m_stdOutRead, buffer, kOutputBufferSize, &bytesRead, NULL);
@@ -443,7 +437,7 @@ MSWindowsWatchdog::outputLoop(void*)
if (m_fileLogOutputter != NULL) {
m_fileLogOutputter->write(kINFO, buffer);
}
- }
+ }
}
}
@@ -470,7 +464,7 @@ MSWindowsWatchdog::shutdownProcess(HANDLE handle, DWORD pid, int timeout)
break;
}
else {
-
+
double elapsed = (ARCH->time() - start);
if (elapsed > timeout) {
// if timeout reached, kill forcefully.
@@ -500,7 +494,7 @@ MSWindowsWatchdog::shutdownExistingProcesses()
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
- // get the first process, and if we can't do that then it's
+ // get the first process, and if we can't do that then it's
// unlikely we can go any further
BOOL gotEntry = Process32First(snapshot, &entry);
if (!gotEntry) {
@@ -517,7 +511,7 @@ MSWindowsWatchdog::shutdownExistingProcesses()
if (_stricmp(entry.szExeFile, "barrierc.exe") == 0 ||
_stricmp(entry.szExeFile, "barriers.exe") == 0) {
-
+
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
shutdownProcess(handle, entry.th32ProcessID, 10);
}