Skip to content

Commit

Permalink
Free SHM as soon as we dont need it anymore
Browse files Browse the repository at this point in the history
If gammaray-client hangs (for whatever reason), it's parent process, the
launcher is still alive and doesn't release the SHM segment it owns. The
same happens when the launcher application crashes -- the SHM segment is
not released.

Each QSHM holds a QSystemSemaphore, and number of accessible semaphores
on a Unix system is very limited (128 is the upper limit).

If you've finally reached this limit, you can't create more SHM segments
and hence cannot start a GammaRay instance anymore.
You end up with this message:

void GammaRay::Launcher::sendProbeSettings() Failed to obtain shared
memory for probe settings: "QSharedMemoryPrivate::initKey: unable to set
key on lock" - error code (QSharedMemory::SharedMemoryError): 7
  • Loading branch information
krf committed Mar 6, 2014
1 parent cc2d85e commit d92d8f5
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,28 @@ void Launcher::semaphoreReleased()
m_safetyTimer.stop();

#ifdef HAVE_SHM
SharedMemoryLocker locker(m_shm);
QByteArray ba = QByteArray::fromRawData(static_cast<const char*>(m_shm->data()), m_shm->size());
QBuffer buffer(&ba);
buffer.open(QIODevice::ReadOnly);

quint16 port = 0;

while (Message::canReadMessage(&buffer)) {
const Message msg = Message::readMessage(&buffer);
switch (msg.type()) {
case Protocol::ServerPort:
{
msg.payload() >> port;
break;
{
SharedMemoryLocker locker(m_shm);
QByteArray ba = QByteArray::fromRawData(static_cast<const char*>(m_shm->data()), m_shm->size());
QBuffer buffer(&ba);
buffer.open(QIODevice::ReadOnly);

while (Message::canReadMessage(&buffer)) {
const Message msg = Message::readMessage(&buffer);
switch (msg.type()) {
case Protocol::ServerPort:
{
msg.payload() >> port;
break;
}
default:
continue;
}
default:
continue;
}
}
delete m_shm;
m_shm = 0;

if (port == 0) {
qWarning() << "Unable to receive port number.";
Expand Down

0 comments on commit d92d8f5

Please sign in to comment.