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
This commit is contained in:
parent
3228fa081a
commit
63b5c8c34c
|
@ -47,6 +47,7 @@ ecm_setup_version(${VERSION} VARIABLE_PREFIX KPMCORE
|
|||
|
||||
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
|
||||
Core
|
||||
DBus
|
||||
Gui
|
||||
Widgets
|
||||
)
|
||||
|
|
|
@ -43,6 +43,7 @@ target_link_libraries( kpmcore
|
|||
${UUID_LIBRARIES}
|
||||
${BLKID_LIBRARIES}
|
||||
${LIBATASMART_LIBRARIES}
|
||||
Qt5::DBus
|
||||
KF5::I18n
|
||||
KF5::IconThemes
|
||||
KF5::KIOCore
|
||||
|
|
|
@ -17,15 +17,17 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "core/operationrunner.h"
|
||||
|
||||
#include "core/operationstack.h"
|
||||
|
||||
#include "ops/operation.h"
|
||||
|
||||
#include "util/report.h"
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QMutex>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/** 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<QStringList> 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())
|
||||
|
|
Loading…
Reference in New Issue