forked from qt-creator/qt-creator
QtSingleApplication: Fix race
If a starting instance locks the shared memory while another instance that is destructed tries to lock, when the destructed one tests for running peers, it doesn't detect the newly started instance, since its QtLocalPeer object is not initialized until after parsing the command-line arguments Change-Id: I05aeb771ba67390f554bff7a80c475b3e4d37984 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
99ba6fb8da
commit
e3e177d407
@@ -497,8 +497,7 @@ int main(int argc, char **argv)
|
|||||||
errorOverview.exec();
|
errorOverview.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up lock and remote arguments.
|
// Set up remote arguments.
|
||||||
app.initialize();
|
|
||||||
QObject::connect(&app, SIGNAL(messageReceived(QString,QObject*)),
|
QObject::connect(&app, SIGNAL(messageReceived(QString,QObject*)),
|
||||||
&pluginManager, SLOT(remoteArguments(QString,QObject*)));
|
&pluginManager, SLOT(remoteArguments(QString,QObject*)));
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char *
|
|||||||
// Add current pid to list and terminate it
|
// Add current pid to list and terminate it
|
||||||
*pids++ = QCoreApplication::applicationPid();
|
*pids++ = QCoreApplication::applicationPid();
|
||||||
*pids = 0;
|
*pids = 0;
|
||||||
|
pidPeer = new QtLocalPeer(this, appId + QLatin1Char('-') +
|
||||||
|
QString::number(QCoreApplication::applicationPid()));
|
||||||
|
connect(pidPeer, SIGNAL(messageReceived(QString,QObject*)), SIGNAL(messageReceived(QString,QObject*)));
|
||||||
|
pidPeer->isClient();
|
||||||
lockfile.unlock();
|
lockfile.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,14 +141,6 @@ bool QtSingleApplication::isRunning(qint64 pid)
|
|||||||
return peer.isClient();
|
return peer.isClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtSingleApplication::initialize(bool)
|
|
||||||
{
|
|
||||||
pidPeer = new QtLocalPeer(this, appId + QLatin1Char('-') +
|
|
||||||
QString::number(QCoreApplication::applicationPid()));
|
|
||||||
connect(pidPeer, SIGNAL(messageReceived(QString,QObject*)), SIGNAL(messageReceived(QString,QObject*)));
|
|
||||||
pidPeer->isClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QtSingleApplication::sendMessage(const QString &message, int timeout, qint64 pid)
|
bool QtSingleApplication::sendMessage(const QString &message, int timeout, qint64 pid)
|
||||||
{
|
{
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ public Q_SLOTS:
|
|||||||
bool sendMessage(const QString &message, int timeout = 5000, qint64 pid = -1);
|
bool sendMessage(const QString &message, int timeout = 5000, qint64 pid = -1);
|
||||||
void activateWindow();
|
void activateWindow();
|
||||||
|
|
||||||
public:
|
|
||||||
void initialize(bool = true);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void messageReceived(const QString &message, QObject *socket);
|
void messageReceived(const QString &message, QObject *socket);
|
||||||
void fileOpenRequest(const QString &file);
|
void fileOpenRequest(const QString &file);
|
||||||
|
|||||||
Reference in New Issue
Block a user