From 63b5c8c34cf257d29fb8e67b41da7b606b32aec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Wed, 7 Jun 2017 19:21:59 +0200 Subject: [PATCH] Suspend Plasma removable device automounting. Before doing operations, we connect to DBus session of the original user and stop kded module for device automounting. BUG: 368175 --- CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + src/core/operationrunner.cpp | 27 ++++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4842e1..a8e05be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ ecm_setup_version(${VERSION} VARIABLE_PREFIX KPMCORE find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core + DBus Gui Widgets ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1da8ec6..1467f8e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,7 @@ target_link_libraries( kpmcore ${UUID_LIBRARIES} ${BLKID_LIBRARIES} ${LIBATASMART_LIBRARIES} + Qt5::DBus KF5::I18n KF5::IconThemes KF5::KIOCore diff --git a/src/core/operationrunner.cpp b/src/core/operationrunner.cpp index e88a1ba..5a176ba 100644 --- a/src/core/operationrunner.cpp +++ b/src/core/operationrunner.cpp @@ -17,15 +17,17 @@ *************************************************************************/ #include "core/operationrunner.h" - #include "core/operationstack.h" - #include "ops/operation.h" - #include "util/report.h" +#include +#include #include +#include +#include + /** Constructs an OperationRunner. @param ostack the OperationStack to act on */ @@ -47,6 +49,22 @@ void OperationRunner::run() bool status = true; + // Disable Plasma removable device automounting + unsigned int currentUid = getuid(); // 0 if running as root + unsigned int userId = getpwnam(getlogin())->pw_uid; // uid of original user before sudo + setuid(userId); + QStringList modules; + QDBusConnection bus = QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("sessionBus")); + QDBusInterface kdedInterface( QStringLiteral("org.kde.kded5"), QStringLiteral("/kded"), QStringLiteral("org.kde.kded5"), bus ); + QDBusReply reply = kdedInterface.call( QStringLiteral("loadedModules") ); + if ( reply.isValid() ) + modules = reply.value(); + QString automounterService = QStringLiteral("device_automounter"); + bool automounter = modules.contains(automounterService); + if (automounter) + kdedInterface.call( QStringLiteral("unloadModule"), automounterService ); + setuid(currentUid); + for (int i = 0; i < numOperations(); i++) { suspendMutex().lock(); @@ -77,6 +95,9 @@ void OperationRunner::run() msleep(5); } + if (automounter) + kdedInterface.call( QStringLiteral("loadModule"), automounterService ); + if (!status) emit error(); else if (isCancelling())