From kde-commits Fri Oct 31 23:20:44 2014 From: David Faure Date: Fri, 31 Oct 2014 23:20:44 +0000 To: kde-commits Subject: [kio] src/core: Avoid launching klauncher just to check for held slaves - in fork-slaves mode. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=141479765508909 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 mo= de. 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 =3D 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() =3D=3D -1) { + bool fork =3D !qgetenv("KDE_FORK_SLAVES").isEmpty(); + + if (!fork) { + // check the UID of klauncher + QDBusReply reply =3D QDBusConnection::sessionBus().inter= face()->serviceUid(klauncher()->service()); + if (reply.isValid() && getuid() !=3D reply) { + fork =3D true; + } + } + + bForkSlaves.testAndSetRelaxed(-1, fork ? 1 : 0); + } + return bForkSlaves.load() =3D=3D 1; +} +#endif + namespace KIO { = @@ -428,26 +456,7 @@ Slave *Slave::createSlave(const QString &protocol, con= st QUrl &url, int &error, QUrl slaveAddress =3D 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 =3D Q_BASIC_ATOMIC_INITIALIZER(-1); - - if (bForkSlaves.load() =3D=3D -1) { - bool fork =3D !qgetenv("KDE_FORK_SLAVES").isEmpty(); - - if (!fork) { - // check the UID of klauncher - QDBusReply reply =3D QDBusConnection::sessionBus().inter= face()->serviceUid(klauncher()->service()); - if (reply.isValid() && getuid() !=3D reply) { - fork =3D true; - } - } - - bForkSlaves.testAndSetRelaxed(-1, fork ? 1 : 0); - } - - if (bForkSlaves.load() =3D=3D 1) { + if (forkSlaves() =3D=3D 1) { QString _name =3D KProtocolInfo::exec(protocol); if (_name.isEmpty()) { error_text =3D 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()); } =20