Added more logging (#10445)

This commit is contained in:
Mykhailo Pylyp
2021-03-26 14:21:29 +02:00
committed by GitHub
parent ccaa98513c
commit 1c46e6b72b

View File

@@ -192,6 +192,7 @@ public:
if (!is_process_elevated(false)) if (!is_process_elevated(false))
{ {
Logger::trace("Starting PowerToys Run from not elevated process");
std::wstring executable_args; std::wstring executable_args;
executable_args += L" -powerToysPid "; executable_args += L" -powerToysPid ";
executable_args += std::to_wstring(powertoys_pid); executable_args += std::to_wstring(powertoys_pid);
@@ -207,6 +208,7 @@ public:
{ {
m_enabled = true; m_enabled = true;
m_hProcess = sei.hProcess; m_hProcess = sei.hProcess;
Logger::trace("Started PowerToys Run. Handle {}", m_hProcess);
} }
else else
{ {
@@ -215,6 +217,7 @@ public:
} }
else else
{ {
Logger::trace("Starting PowerToys Run from elevated process");
std::wstring action_runner_path = get_module_folderpath(); std::wstring action_runner_path = get_module_folderpath();
std::wstring params; std::wstring params;
@@ -228,8 +231,13 @@ public:
action_runner_path += L"\\action_runner.exe"; action_runner_path += L"\\action_runner.exe";
// Set up the shared file from which to retrieve the PID of PowerLauncher // Set up the shared file from which to retrieve the PID of PowerLauncher
HANDLE hMapFile = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(DWORD), POWER_LAUNCHER_PID_SHARED_FILE); HANDLE hMapFile = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(DWORD), POWER_LAUNCHER_PID_SHARED_FILE);
if (hMapFile) if (!hMapFile)
{ {
auto err = get_last_error_message(GetLastError());
Logger::error(L"Failed to create FileMapping {}. {}", POWER_LAUNCHER_PID_SHARED_FILE, err.has_value() ? err.value() : L"");
return;
}
PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD))); PDWORD pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
if (pidBuffer) if (pidBuffer)
{ {
@@ -238,6 +246,7 @@ public:
if (run_non_elevated(action_runner_path, params, pidBuffer)) if (run_non_elevated(action_runner_path, params, pidBuffer))
{ {
Logger::trace("Started PowerToys Run Process. PID {}", *pidBuffer);
m_enabled = true; m_enabled = true;
const int maxRetries = 80; const int maxRetries = 80;
for (int retry = 0; retry < maxRetries; ++retry) for (int retry = 0; retry < maxRetries; ++retry)
@@ -247,16 +256,20 @@ public:
if (pid) if (pid)
{ {
m_hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid); m_hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
Logger::trace("Opened PowerToys Run Process. Handle {}", m_hProcess);
break; break;
} }
} }
} }
else
{
Logger::error("Failed to start PowerToys Run");
}
} }
CloseHandle(hMapFile); CloseHandle(hMapFile);
} }
} }
} }
}
// Disable the powertoy // Disable the powertoy
virtual void disable() virtual void disable()
@@ -308,7 +321,7 @@ public:
enable(); enable();
} }
Logger::trace("Set POWER_LAUNCHER_SHARED_EVENT"); Logger::trace("Set POWER_LAUNCHER_SHARED_EVENT. Handle {}", m_hProcess);
SetEvent(m_hEvent); SetEvent(m_hEvent);
return true; return true;
} }
@@ -331,6 +344,7 @@ public:
// Terminate process by sending WM_CLOSE signal and if it fails, force terminate. // Terminate process by sending WM_CLOSE signal and if it fails, force terminate.
void terminateProcess() void terminateProcess()
{ {
Logger::trace(L"Terminating PowerToys Run process. Handle {}.", m_hProcess);
DWORD processID = GetProcessId(m_hProcess); DWORD processID = GetProcessId(m_hProcess);
if (TerminateProcess(m_hProcess, 1) == 0) if (TerminateProcess(m_hProcess, 1) == 0)
{ {