Create lock file in config folder instead of temp folder

Some linux distros seem to alter TMPDIR environment variable and
therefore hamper qbt ability to find the lock files. So use config
folder instead of TMPDIR folder to create/locate the lock files.
Note that this change will also make qbt become one instance per-user
instead of one instance per-system.

Closes #15646.
This commit is contained in:
Chocobo1 2021-10-30 17:33:58 +08:00
parent 40f2718265
commit a5c531f0a4
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
6 changed files with 29 additions and 70 deletions

View file

@ -28,24 +28,27 @@
#include "applicationinstancemanager.h"
#include <QtGlobal>
#ifdef Q_OS_WIN
#include <windows.h>
#endif
#include <QDebug>
#include <QSharedMemory>
#endif
#include "qtlocalpeer/qtlocalpeer.h"
ApplicationInstanceManager::ApplicationInstanceManager(const QString &appId, QObject *parent)
ApplicationInstanceManager::ApplicationInstanceManager(const QString &instancePath, QObject *parent)
: QObject {parent}
, m_peer {new QtLocalPeer {this, appId}}
, m_peer {new QtLocalPeer {instancePath, this}}
, m_isFirstInstance {!m_peer->isClient()}
{
connect(m_peer, &QtLocalPeer::messageReceived, this, &ApplicationInstanceManager::messageReceived);
#ifdef Q_OS_WIN
auto sharedMem = new QSharedMemory {appId + QLatin1String {"-shared-memory-key"}, this};
const QString sharedMemoryKey = instancePath + QLatin1String {"/shared-memory"};
auto sharedMem = new QSharedMemory {sharedMemoryKey, this};
if (m_isFirstInstance)
{
// First instance creates shared memory and store PID
@ -79,8 +82,3 @@ bool ApplicationInstanceManager::sendMessage(const QString &message, const int t
{
return m_peer->sendMessage(message, timeout);
}
QString ApplicationInstanceManager::appId() const
{
return m_peer->applicationId();
}