Fixing SingleInstance for *nix

This commit is contained in:
Andrei Smirnov 2021-08-06 09:19:17 +03:00 committed by Michał
parent 31eb8d939d
commit ee4f152349
1 changed files with 4 additions and 0 deletions

View File

@ -20,6 +20,10 @@ SingleInstance::SingleInstance(const QString &uniqueName, QObject *parent)
// note: this is an ad-hoc timeout value selected based on prior experience.
if (!localSocket.waitForConnected(100)) {
connect(m_localServer, &QLocalServer::newConnection, this, &SingleInstance::secondInstanceDetected);
// on *nix a crashed process will leave /tmp/xyz file preventing to start a new server.
// therefore, if we were unable to connect, then we assume the server died and we need to clean up.
// p.s. on Windows, this function does nothing.
QLocalServer::removeServer(socketName);
if (!m_localServer->listen(socketName)) {
qWarning() << "QLocalServer::listen(" << socketName << ") failed";
}