From d2ee6f861787aa2edcf817e37e76c8de297d902b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Lepp=C3=A4nen?= Date: Tue, 9 Feb 2021 14:48:43 +0200 Subject: [PATCH] [launcherlib] Correct single instance code for QML apps. Contributes to JB#53097 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure that we retain the behaviour we had before for non-sandboxed apps. This is done to ensure that locking uses appName() when using for example QML based applications. Signed-off-by: Tomi Leppänen --- src/launcherlib/booster.cpp | 13 +++++-------- src/launcherlib/booster.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/launcherlib/booster.cpp b/src/launcherlib/booster.cpp index 0b008c5..a79c033 100644 --- a/src/launcherlib/booster.cpp +++ b/src/launcherlib/booster.cpp @@ -107,7 +107,7 @@ void Booster::initialize(int initialArgc, char ** initialArgv, int newBoosterLau SingleInstancePluginEntry * pluginEntry = singleInstance->pluginEntry(); if (pluginEntry) { - std::string lockedAppName = getFinalFileName(); + std::string lockedAppName = getFinalName(m_appData->appName()); if (!pluginEntry->lockFunc(lockedAppName.c_str())) { // Try to activate the window of the existing instance @@ -433,7 +433,7 @@ void Booster::setEnvironmentBeforeLaunch() if (!errno && cur_prio < m_appData->priority()) setpriority(PRIO_PROCESS, 0, m_appData->priority()); - std::string fileName = getFinalFileName(); + std::string fileName = getFinalName(m_appData->fileName()); setCgroup(fileName); if (!m_appData->isPrivileged()) { @@ -616,9 +616,8 @@ void Booster::resetOomAdj() } } -std::string Booster::getFinalFileName() +std::string Booster::getFinalName(const std::string &name) { - std::string name = m_appData->fileName(); if (name == "/usr/bin/sailjail") { // This doesn't implement sailjail's parsing logic but instead // has some assumptions about the arguments: @@ -638,12 +637,10 @@ std::string Booster::getFinalFileName() for (int i = 1; i < m_appData->argc(); i++, ptr++) { if (strcmp(*ptr, "--") == 0) { if (i+1 < m_appData->argc()) { - name = *(++ptr); - break; + return std::string(*(++ptr)); } } else if (strncmp(*ptr, "/usr/bin/", 9) == 0) { - name = *ptr; - break; + return std::string(*ptr); } } } diff --git a/src/launcherlib/booster.h b/src/launcherlib/booster.h index efefbae..2ce43fb 100644 --- a/src/launcherlib/booster.h +++ b/src/launcherlib/booster.h @@ -195,7 +195,7 @@ private: void* loadMain(); //! Helper method: returns application name for to use for locking etc. - std::string getFinalFileName(); + std::string getFinalName(const std::string &name); //! Socket connection to invoker Connection* m_connection;