summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2016-11-11 13:30:24 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2016-11-14 14:27:23 +0000
commit46ab4476a46dc90ba0d7c7250f52a9df0ff12c0c (patch)
tree4fb9c18d6f3d887229de9a0b85eccf0fc896f895
parent3992c478749a2256f13016a74200fc9d73158507 (diff)
Fix sub-jom detection for chocolatey shims
Do not walk the process tree up to find if some parent is called "jom.exe" to find out whether we're a sub-jom, because this fails if a non-jom which is called "jom.exe" calls the real "jom.exe". This is the case for chocolatey shims. Instead, simply check for the existence of the _JOMSRVKEY_ variable which is set by the top-level jom. Task-number: QTCREATORBUG-15494 Change-Id: I90db7cf4b34cb6c3a03764cb5137f1f6e4af223d Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r--src/app/application.cpp45
1 files changed, 3 insertions, 42 deletions
diff --git a/src/app/application.cpp b/src/app/application.cpp
index 45a3ecb..0f0ba29 100644
--- a/src/app/application.cpp
+++ b/src/app/application.cpp
@@ -30,57 +30,18 @@
#include <QtCore/QFileInfo>
#include <QtCore/QSet>
#include <qt_windows.h>
-#include <Tlhelp32.h>
namespace NMakeFile {
-static bool isSubJOM(const QString &processExeName)
+static bool isSubJOM()
{
- HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hSnapshot == INVALID_HANDLE_VALUE)
- return false;
- bool result = false;
- QHash<DWORD, PROCESSENTRY32> processEntries;
- QSet<DWORD> seenProcessIds;
- PROCESSENTRY32 pe = {0};
- pe.dwSize = sizeof(pe);
- if (!Process32First(hSnapshot, &pe)) {
- qWarning("Process32First failed with error code %d.", GetLastError());
- goto done;
- }
- do {
- processEntries.insert(pe.th32ProcessID, pe);
- } while (Process32Next(hSnapshot, &pe));
-
- const DWORD dwCurrentProcessId = GetCurrentProcessId();
- DWORD dwProcessId = dwCurrentProcessId;
- while (dwProcessId && !seenProcessIds.contains(dwProcessId)) {
- seenProcessIds.insert(dwProcessId);
- QHash<DWORD, PROCESSENTRY32>::iterator it = processEntries.find(dwProcessId);
- if (it == processEntries.end())
- break;
-
- PROCESSENTRY32 &pe = it.value();
- QString exeName = QString::fromUtf16((const ushort*)pe.szExeFile);
- if (pe.th32ProcessID != dwCurrentProcessId && exeName == processExeName) {
- result = true;
- goto done;
- }
-
- dwProcessId = pe.th32ParentProcessID;
- processEntries.erase(it);
- }
-
-done:
- CloseHandle(hSnapshot);
- return result;
+ return GetEnvironmentVariableA("_JOMSRVKEY_", NULL, 0) > 0;
}
Application::Application(int &argc, char **argv)
: QCoreApplication(argc, argv)
{
- QString exeName = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
- m_bIsSubJOM = NMakeFile::isSubJOM(exeName);
+ m_bIsSubJOM = NMakeFile::isSubJOM();
}
Application::~Application()