fix: deskflow-core always starts a new instance without --new-instance

fixes: #9216
This commit is contained in:
sithlord48 2025-11-26 15:53:54 -05:00 committed by Chris Rizzitello
parent 2f5166fafa
commit 52e0daba0f

View file

@ -66,22 +66,19 @@ int main(int argc, char **argv)
return s_exitSuccess; return s_exitSuccess;
} }
if (parser.singleInstanceOnly()) { // Before we check any more args we need to check for a duplicate process.
// Before we check any more args we need to check for a duplicate process. // Create a shared memory segment with a unique key
// Create a shared memory segment with a unique key // This is to prevent a new instance from running if one is already running
// This is to prevent a new instance from running if one is already running QSharedMemory sharedMemory(kCoreBinName);
QSharedMemory sharedMemory(kCoreBinName);
// Attempt to attach first and detach in order to clean up stale shm chunks // Attempt to attach first and detach in order to clean up stale shm chunks
// This can happen if the previous instance was killed or crashed // This can happen if the previous instance was killed or crashed
if (sharedMemory.attach()) if (sharedMemory.attach())
sharedMemory.detach(); sharedMemory.detach();
// If we can create 1 byte of SHM we are the only instance if (!sharedMemory.create(1) && parser.singleInstanceOnly()) {
if (!sharedMemory.create(1)) { LOG_WARN("an instance of deskflow core is already running");
LOG_WARN("an instance of deskflow core is already running"); return s_exitDuplicate;
return s_exitDuplicate;
}
} }
parser.parse(); parser.parse();