From db06e6e87f4fd051cb56c33e75c9eb08ea0474a9 Mon Sep 17 00:00:00 2001 From: defnax Date: Fri, 11 Oct 2019 12:26:00 +0200 Subject: [PATCH] fix retroshare ipc Patch by Cy It fixes a bug, where the IPC client process sets up the shared memory, then immediately deletes the shared memory, then notifies the main GUI that the shared memory has been set up. Then the main GUI reports an error because there is no shared memory, and can't open the link that used to be in the now deleted shared memory. So basically "$ retroshare retroshare://..." does nothing, even if the main GUI is running. At least that's what was happening for me. --- retroshare-gui/src/rshare.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp index 872273613..3898a899a 100644 --- a/retroshare-gui/src/rshare.cpp +++ b/retroshare-gui/src/rshare.cpp @@ -241,6 +241,11 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir) localServer= new QLocalServer(); QObject::connect(localServer, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished())); updateLocalServer(); + // clear out any old arguments (race condition?) + QSharedMemory newArgs; + newArgs.setKey(QString(TARGET) + "_newArgs"); + if(newArgs.attach(QSharedMemory::ReadWrite)) + newArgs.detach(); } } @@ -325,20 +330,27 @@ Rshare::~Rshare() */ void Rshare::slotConnectionEstablished() { - QLocalSocket *socket = localServer->nextPendingConnection(); - socket->close(); - delete socket; - QSharedMemory newArgs; newArgs.setKey(QString(TARGET) + "_newArgs"); + QLocalSocket *socket = localServer->nextPendingConnection(); + if (!newArgs.attach()) { - std::cerr << "(EE) Rshare::slotConnectionEstablished() Unable to attach to shared memory segment." - << newArgs.errorString().toStdString() << std::endl; + /* this is not an error. It just means we were notified to check + newArgs, but none had been set yet. + TODO: implement separate ping/take messages + std::cerr << "(EE) Rshare::slotConnectionEstablished() Unable to attach to shared memory segment." + << newArgs.errorString().toStdString() << std::endl; + */ + socket->close(); + delete socket; return; } + socket->close(); + delete socket; + QBuffer buffer; QDataStream in(&buffer); QStringList args;