diff --git a/src/kdeinitinterface.cpp b/src/kdeinitinterface.cpp --- a/src/kdeinitinterface.cpp +++ b/src/kdeinitinterface.cpp @@ -41,10 +41,13 @@ qCDebug(KDBUSADDONS_LOG) << "klauncher not running... launching kdeinit"; QLockFile lock(QDir::tempPath() + QLatin1Char('/') + QLatin1String("startkdeinitlock")); + // If we can't get the lock, then someone else is already in the process of starting kdeinit. if (!lock.tryLock()) { + // Wait for that to happen, by locking again lock.lock(); + // Check that the DBus name is up, i.e. the other process did manage to do it successfully. if (dbusDaemon->isServiceRegistered(QStringLiteral("org.kde.klauncher5"))) { - return; // whoever held the lock has already started it + return; } } // Try to launch kdeinit. @@ -65,6 +68,8 @@ #ifndef Q_OS_WIN args += QStringLiteral("--suicide"); #endif - QProcess::execute(srv, args); + QProcess proc; + // started asynchronously, so even if kdeinit5 takes forever to start, the lock will be released + proc.start(srv, args); }