[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kio] src/core: Avoid launching klauncher just to check for held slaves - in fork-slaves mode.
From:       David Faure <faure () kde ! org>
Date:       2014-10-31 23:20:44
Message-ID: E1XkLUq-0003wh-O8 () scm ! kde ! org
[Download RAW message or body]

Git commit a8de3cb2032aba3dc86b1c7a7e745ca000f21bf4 by David Faure.
Committed on 31/10/2014 at 23:20.
Pushed by dfaure into branch 'master'.

Avoid launching klauncher just to check for held slaves - in fork-slaves mode.

Change-Id: Iee97f7f4208c01ac3af3b12042b1862bd56c5e0a

M  +32   -20   src/core/slave.cpp

http://commits.kde.org/kio/a8de3cb2032aba3dc86b1c7a7e745ca000f21bf4

diff --git a/src/core/slave.cpp b/src/core/slave.cpp
index 90f8298..f54e264 100644
--- a/src/core/slave.cpp
+++ b/src/core/slave.cpp
@@ -74,6 +74,34 @@ static org::kde::KSlaveLauncher *klauncher()
     return s_kslaveLauncher.localData();
 }
 
+#ifdef Q_OS_UNIX
+// In such case we start the slave via QProcess.
+// It's possible to force this by setting the env. variable
+// KDE_FORK_SLAVES, Clearcase seems to require this.
+static QBasicAtomicInt bForkSlaves = Q_BASIC_ATOMIC_INITIALIZER(-1);
+
+static bool forkSlaves()
+{
+    // In such case we start the slave via QProcess.
+    // It's possible to force this by setting the env. variable
+    // KDE_FORK_SLAVES, Clearcase seems to require this.
+    if (bForkSlaves.load() == -1) {
+        bool fork = !qgetenv("KDE_FORK_SLAVES").isEmpty();
+
+        if (!fork) {
+            // check the UID of klauncher
+            QDBusReply<uint> reply = \
QDBusConnection::sessionBus().interface()->serviceUid(klauncher()->service()); +      \
if (reply.isValid() && getuid() != reply) { +                fork = true;
+            }
+        }
+
+        bForkSlaves.testAndSetRelaxed(-1, fork ? 1 : 0);
+    }
+    return bForkSlaves.load() == 1;
+}
+#endif
+
 namespace KIO
 {
 
@@ -428,26 +456,7 @@ Slave *Slave::createSlave(const QString &protocol, const QUrl \
&url, int &error,  QUrl slaveAddress = slave->d_func()->slaveconnserver->address();
 
 #ifdef Q_OS_UNIX
-    // In such case we start the slave via QProcess.
-    // It's possible to force this by setting the env. variable
-    // KDE_FORK_SLAVES, Clearcase seems to require this.
-    static QBasicAtomicInt bForkSlaves = Q_BASIC_ATOMIC_INITIALIZER(-1);
-
-    if (bForkSlaves.load() == -1) {
-        bool fork = !qgetenv("KDE_FORK_SLAVES").isEmpty();
-
-        if (!fork) {
-            // check the UID of klauncher
-            QDBusReply<uint> reply = \
                QDBusConnection::sessionBus().interface()->serviceUid(klauncher()->service());
                
-            if (reply.isValid() && getuid() != reply) {
-                fork = true;
-            }
-        }
-
-        bForkSlaves.testAndSetRelaxed(-1, fork ? 1 : 0);
-    }
-
-    if (bForkSlaves.load() == 1) {
+    if (forkSlaves() == 1) {
         QString _name = KProtocolInfo::exec(protocol);
         if (_name.isEmpty()) {
             error_text = i18n("Unknown protocol '%1'.", protocol);
@@ -529,6 +538,9 @@ Slave *Slave::holdSlave(const QString &protocol, const QUrl &url)
 
 bool Slave::checkForHeldSlave(const QUrl &url)
 {
+    if (forkSlaves()) {
+        return false;
+    }
     return klauncher()->checkForHeldSlave(url.toString());
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic