-
-
Notifications
You must be signed in to change notification settings - Fork 196
Closed
Labels
Description
Describe the bug
Fails to start when there are multiple X sessions running on the same machine.
To Reproduce
- start X session for
user1
- start
ksnip
- switch X session to
user2
- try to start
ksnip
It will fail to start with errors:
Warning: QIODevice::write (QLocalSocket): device not open
Warning: QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState
Desktop (please complete the following information):
- OS: Debian
- Distribution in case of Linux: Bullseye
- Window System in case of Linux: X11
- ksnip version: 1.11.0
- How did you install ksnip:
apt-get
and manual build
Additional context
Problem comes from not unique key for QSharedMemory
in InstanceLock.cpp
Suggested solution
diff --git a/src/bootstrapper/singleInstance/InstanceLock.cpp b/src/bootstrapper/singleInstance/InstanceLock.cpp
index c341313c..c73b72d3 100644
--- a/src/bootstrapper/singleInstance/InstanceLock.cpp
+++ b/src/bootstrapper/singleInstance/InstanceLock.cpp
@@ -21,7 +21,8 @@
InstanceLock::InstanceLock()
{
- mSingular = new QSharedMemory(QLatin1String("KsnipInstanceLock"), this);
+ unsigned int _pid = QCoreApplication::applicationPid();
+ mSingular = new QSharedMemory(QLatin1String("KsnipInstanceLock_%1").arg(_pid), this);
}
InstanceLock::~InstanceLock()
@@ -58,4 +59,4 @@ bool InstanceLock::attachDetach()
return true;
}
return false;
-}
\ No newline at end of file
+}
diff --git a/src/bootstrapper/singleInstance/InstanceLock.h b/src/bootstrapper/singleInstance/InstanceLock.h
index a904bfb8..7c010cbb 100644
--- a/src/bootstrapper/singleInstance/InstanceLock.h
+++ b/src/bootstrapper/singleInstance/InstanceLock.h
@@ -21,6 +21,7 @@
#define KSNIP_INSTANCELOCK_H
#include <QSharedMemory>
+#include <QCoreApplication>
class InstanceLock : public QObject
{