Skip to content
Snippets Groups Projects
Commit 2d8078a0 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

runguard: enable on linux

GitLab: #350
GitLab: #439
Change-Id: Iba420995401cb4a8c20f3611473eb6f5bd22334b
parent 64720224
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "mainapplication.h" #include "mainapplication.h"
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QLocalSocket>
namespace { namespace {
...@@ -77,16 +78,16 @@ RunGuard::isAnotherRunning() ...@@ -77,16 +78,16 @@ RunGuard::isAnotherRunning()
bool bool
RunGuard::tryToRun() RunGuard::tryToRun()
{ {
#ifdef Q_OS_WIN
if (isAnotherRunning()) { if (isAnotherRunning()) {
/* /*
* This is a secondary instance, * This is a secondary instance,
* connect to the primary instance to trigger a restore * connect to the primary instance to trigger a restore
* then fail. * then fail.
*/ */
if (socket_ == nullptr) { if (!socket_)
socket_ = new QLocalSocket(); socket_ = new QLocalSocket();
} if (!socket_)
return false;
if (socket_->state() == QLocalSocket::UnconnectedState if (socket_->state() == QLocalSocket::UnconnectedState
|| socket_->state() == QLocalSocket::ClosingState) { || socket_->state() == QLocalSocket::ClosingState) {
socket_->connectToServer(key_); socket_->connectToServer(key_);
...@@ -94,7 +95,11 @@ RunGuard::tryToRun() ...@@ -94,7 +95,11 @@ RunGuard::tryToRun()
if (socket_->state() == QLocalSocket::ConnectingState) { if (socket_->state() == QLocalSocket::ConnectingState) {
socket_->waitForConnected(); socket_->waitForConnected();
} }
return false; if (socket_->state() == QLocalSocket::ConnectedState) {
return false;
}
// If not connected, this means that the server doesn't exists
// and the app can be relaunched (can be the case after a client crash or Ctrl+C)
} }
memLock_.acquire(); memLock_.acquire();
...@@ -117,7 +122,6 @@ RunGuard::tryToRun() ...@@ -117,7 +122,6 @@ RunGuard::tryToRun()
&QLocalServer::newConnection, &QLocalServer::newConnection,
this, this,
&RunGuard::tryRestorePrimaryInstance); &RunGuard::tryRestorePrimaryInstance);
#endif
return true; return true;
} }
......
...@@ -52,8 +52,8 @@ private: ...@@ -52,8 +52,8 @@ private:
QSharedMemory sharedMem_; QSharedMemory sharedMem_;
QSystemSemaphore memLock_; QSystemSemaphore memLock_;
QLocalSocket* socket_; QLocalSocket* socket_ {nullptr};
QLocalServer* server_; QLocalServer* server_ {nullptr};
Q_DISABLE_COPY(RunGuard) Q_DISABLE_COPY(RunGuard)
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment