Windows/DebugOutput: Check that only one process reads output

Only one process can attach to the system wide application output
buffer. Re-add checks that makes sure we don't try to attach
as second one.

Change-Id: Ic50b43b8d0ac58d792075b59ecb3e490fdb75df8
Reviewed-on: http://codereview.qt.nokia.com/827
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
Kai Koehne
2011-06-28 12:40:25 +02:00
committed by Tobias Hunger
parent 2d4b5fcb65
commit 7827af9712
4 changed files with 25 additions and 12 deletions

View File

@@ -77,7 +77,8 @@ void WinDebugInterface::run()
m_bufferReadyEvent = 0;
m_sharedFile = 0;
m_sharedMem = 0;
runLoop();
if (!runLoop())
emit cannotRetrieveDebugOutput();
if (m_sharedMem) {
UnmapViewOfFile(m_sharedMem);
m_sharedMem = 0;
@@ -100,21 +101,25 @@ void WinDebugInterface::run()
}
}
void WinDebugInterface::runLoop()
bool WinDebugInterface::runLoop()
{
m_waitHandles[TerminateEventHandle] = CreateEvent(NULL, FALSE, FALSE, NULL);
if (GetLastError() == ERROR_ALREADY_EXISTS)
return false;
m_waitHandles[DataReadyEventHandle] = CreateEvent(NULL, FALSE, FALSE, L"DBWIN_DATA_READY");
if (!m_waitHandles[TerminateEventHandle] || !m_waitHandles[DataReadyEventHandle])
return;
if (!m_waitHandles[TerminateEventHandle] || !m_waitHandles[DataReadyEventHandle]
|| GetLastError() == ERROR_ALREADY_EXISTS)
return false;
m_bufferReadyEvent = CreateEvent(NULL, FALSE, FALSE, L"DBWIN_BUFFER_READY");
if (!m_bufferReadyEvent)
return;
if (!m_bufferReadyEvent
|| GetLastError() == ERROR_ALREADY_EXISTS)
return false;
m_sharedFile = CreateFileMapping((HANDLE)-1, NULL, PAGE_READWRITE, 0, 4096, L"DBWIN_BUFFER");
if (!m_sharedFile)
return;
if (!m_sharedFile || GetLastError() == ERROR_ALREADY_EXISTS)
return false;
m_sharedMem = MapViewOfFile(m_sharedFile, FILE_MAP_READ, 0, 0, 512);
if (!m_sharedMem)
return;
return false;
LPSTR message = reinterpret_cast<LPSTR>(m_sharedMem) + sizeof(DWORD);
LPDWORD processId = reinterpret_cast<LPDWORD>(m_sharedMem);
@@ -130,6 +135,7 @@ void WinDebugInterface::runLoop()
SetEvent(m_bufferReadyEvent);
}
}
return true;
}
} // namespace Internal