diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-23 12:00:14 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-23 13:19:24 +0200 |
commit | 3770f4b1489b8d0d8fd6ffef23b8aac7dbf2e33b (patch) | |
tree | 23b3486ec6d1149d7001b35d9e77939581840c41 /src/corelib | |
parent | 7aae6219d578b4d8ca8f97d67136b946fc25f5d6 (diff) |
QLockFile/Windows: Determine host name from environment variable COMPUTERNAME.
Useful when using shared directories.
Task-number: QTBUG-39967
Change-Id: I2c082e33133b00306378b6ff58478e94119e6a0e
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qlockfile_win.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/corelib/io/qlockfile_win.cpp b/src/corelib/io/qlockfile_win.cpp index 28f6b02a64..00c8a85bcc 100644 --- a/src/corelib/io/qlockfile_win.cpp +++ b/src/corelib/io/qlockfile_win.cpp @@ -50,6 +50,11 @@ QT_BEGIN_NAMESPACE +static inline QByteArray localHostName() +{ + return qgetenv("COMPUTERNAME"); +} + QLockFile::LockError QLockFilePrivate::tryLock_sys() { const QFileSystemEntry fileEntry(fileName); @@ -98,7 +103,7 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys() fileData += '\n'; fileData += qAppName().toUtf8(); fileData += '\n'; - //fileData += localHostname(); // gethostname requires winsock init, see QHostInfo... + fileData += localHostName(); fileData += '\n'; DWORD bytesWritten = 0; QLockFile::LockError error = QLockFile::NoError; @@ -123,14 +128,16 @@ bool QLockFilePrivate::isApparentlyStale() const // On WinRT there seems to be no way of obtaining information about other // processes due to sandboxing #ifndef Q_OS_WINRT - HANDLE procHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); - if (!procHandle) - return true; - // We got a handle but check if process is still alive - DWORD dwR = ::WaitForSingleObject(procHandle, 0); - ::CloseHandle(procHandle); - if (dwR == WAIT_TIMEOUT) - return true; + if (hostname == QString::fromLocal8Bit(localHostName())) { + HANDLE procHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); + if (!procHandle) + return true; + // We got a handle but check if process is still alive + DWORD dwR = ::WaitForSingleObject(procHandle, 0); + ::CloseHandle(procHandle); + if (dwR == WAIT_TIMEOUT) + return true; + } #endif // !Q_OS_WINRT const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime()); return staleLockTime > 0 && age > staleLockTime; |