Skip to content

impossible to use by multiple users on the same machine #975

@m0ntana

Description

@m0ntana

Describe the bug
Fails to start when there are multiple X sessions running on the same machine.

To Reproduce

  1. start X session for user1
  2. start ksnip
  3. switch X session to user2
  4. 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
 {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions