diff options
| author | Eran Mizrahi <erasmux@gmail.com> | 2017-12-13 16:18:54 +0200 |
|---|---|---|
| committer | Eran Mizrahi <erasmux@gmail.com> | 2017-12-13 22:27:11 +0200 |
| commit | a5bb70f53bc20f36f695ac5cd9f8b91163f694eb (patch) | |
| tree | 0d6f2c1e2bce7497c59785dd6de645d741620193 /src/organizercore.cpp | |
| parent | 0586b2856b0b8973e5781b9b0a1b5e5acac20532 (diff) | |
Wait for injected processes on MO close
Diffstat (limited to 'src/organizercore.cpp')
| -rw-r--r-- | src/organizercore.cpp | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 1f42bf95..c4bcaf3d 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1367,26 +1367,8 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode, IL QThread::msleep(500);
// search if there is another usvfs process active and if so wait for it
- // in theory a querySize of 1 is probably enough since the MO process doesn't seem to be returned by GetVFSProcessList
- constexpr size_t querySize = 2; // just to be on the safe side
- DWORD pids[querySize];
- size_t found = querySize;
- if (!::GetVFSProcessList(&found, pids)) {
- qWarning() << "Failed waiting for process completion : GetVFSProcessList failed?!";
- break;
- }
-
- for (size_t i = 0; i < found; ++i) {
- if (pids[i] == GetCurrentProcessId())
- continue; // obviously don't wait for MO process
- handle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION|SYNCHRONIZE, FALSE, pids[i]);
- if (handle == INVALID_HANDLE_VALUE) {
- qWarning() << "Failed waiting for process completion : OpenProcess failed" << GetLastError();
- continue;
- }
- newHandle = true;
- break;
- }
+ handle = findAndOpenAUSVFSProcess();
+ newHandle = handle != INVALID_HANDLE_VALUE;
}
}
@@ -1403,6 +1385,29 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode, IL return res == WAIT_OBJECT_0;
}
+HANDLE OrganizerCore::findAndOpenAUSVFSProcess() {
+ // in theory a querySize of 1 is probably enough since the MO process doesn't seem to be returned by GetVFSProcessList
+ constexpr size_t querySize = 2; // just to be on the safe side
+ DWORD pids[querySize];
+ size_t found = querySize;
+ if (!::GetVFSProcessList(&found, pids)) {
+ qWarning() << "Failed seeking USVFS processes : GetVFSProcessList failed?!";
+ return INVALID_HANDLE_VALUE;
+ }
+
+ for (size_t i = 0; i < found; ++i) {
+ if (pids[i] == GetCurrentProcessId())
+ continue; // obviously don't wait for MO process
+ HANDLE handle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE, pids[i]);
+ if (handle != INVALID_HANDLE_VALUE)
+ return handle;
+ else
+ qWarning() << "Failed openning USVFS process " << pids[i] << " : OpenProcess failed" << GetLastError();
+ }
+
+ return INVALID_HANDLE_VALUE;
+}
+
bool OrganizerCore::onAboutToRun(
const std::function<bool(const QString &)> &func)
{
|
