mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
soliduiserver: wait for the process via QEventLoop in SolidUiServerHelper
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
2b48360cd9
commit
b59da184df
2 changed files with 111 additions and 57 deletions
|
@ -21,13 +21,31 @@
|
||||||
#include <kstandarddirs.h>
|
#include <kstandarddirs.h>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QTimer>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
static const int s_waittime = 3000;
|
||||||
|
|
||||||
SolidUiServerHelper::SolidUiServerHelper(const char* const helper, QObject *parent)
|
SolidUiServerHelper::SolidUiServerHelper(const char* const helper, QObject *parent)
|
||||||
: KAuthorization(helper, parent)
|
: KAuthorization(helper, parent),
|
||||||
|
m_process(nullptr),
|
||||||
|
m_eventloop(nullptr)
|
||||||
{
|
{
|
||||||
|
m_process = new QProcess(this);
|
||||||
|
m_eventloop = new QEventLoop(this);
|
||||||
|
connect(
|
||||||
|
m_process, SIGNAL(finished(int)),
|
||||||
|
m_eventloop, SLOT(quit())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SolidUiServerHelper::~SolidUiServerHelper()
|
||||||
|
{
|
||||||
|
m_process->terminate();
|
||||||
|
if (!m_process->waitForFinished(s_waittime)) {
|
||||||
|
m_process->kill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SolidUiServerHelper::cryptopen(const QVariantMap ¶meters)
|
int SolidUiServerHelper::cryptopen(const QVariantMap ¶meters)
|
||||||
|
@ -36,29 +54,22 @@ int SolidUiServerHelper::cryptopen(const QVariantMap ¶meters)
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString cryptbin = KStandardDirs::findRootExe("cryptsetup");
|
m_cryptbin = KStandardDirs::findRootExe("cryptsetup");
|
||||||
if (cryptbin.isEmpty()) {
|
if (m_cryptbin.isEmpty()) {
|
||||||
kWarning() << "cryptsetup is missing";
|
kWarning() << "cryptsetup is missing";
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString device = parameters.value("device").toString();
|
m_parameters = parameters;
|
||||||
const QString name = parameters.value("name").toString();
|
QTimer::singleShot(500, this, SLOT(slotCryptOpen()));
|
||||||
const QByteArray password = QByteArray::fromHex(parameters.value("password").toByteArray());
|
m_eventloop->exec();
|
||||||
const QStringList cryptargs = QStringList() << "--batch-mode" << "--key-file=-" << "open" << device << name;
|
|
||||||
QProcess cryptproc;
|
|
||||||
cryptproc.start(cryptbin, cryptargs);
|
|
||||||
cryptproc.waitForStarted();
|
|
||||||
cryptproc.write(password);
|
|
||||||
cryptproc.closeWriteChannel();
|
|
||||||
cryptproc.waitForFinished();
|
|
||||||
|
|
||||||
if (cryptproc.exitCode() == 0) {
|
if (m_process->exitCode() == 0) {
|
||||||
return KAuthorization::NoError;
|
return KAuthorization::NoError;
|
||||||
}
|
}
|
||||||
QString crypterror = cryptproc.readAllStandardError();
|
QString crypterror = m_process->readAllStandardError();
|
||||||
if (crypterror.isEmpty()) {
|
if (crypterror.isEmpty()) {
|
||||||
crypterror = cryptproc.readAllStandardOutput();
|
crypterror = m_process->readAllStandardOutput();
|
||||||
}
|
}
|
||||||
kWarning() << crypterror;
|
kWarning() << crypterror;
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
|
@ -70,25 +81,22 @@ int SolidUiServerHelper::cryptclose(const QVariantMap ¶meters)
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString cryptbin = KStandardDirs::findRootExe("cryptsetup");
|
m_cryptbin = KStandardDirs::findRootExe("cryptsetup");
|
||||||
if (cryptbin.isEmpty()) {
|
if (m_cryptbin.isEmpty()) {
|
||||||
kWarning() << "cryptsetup is missing";
|
kWarning() << "cryptsetup is missing";
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString name = parameters.value("name").toString();
|
m_parameters = parameters;
|
||||||
const QStringList cryptargs = QStringList() << "--batch-mode" << "close" << name;
|
QTimer::singleShot(500, this, SLOT(slotCryptClose()));
|
||||||
QProcess cryptproc;
|
m_eventloop->exec();
|
||||||
cryptproc.start(cryptbin, cryptargs);
|
|
||||||
cryptproc.waitForStarted();
|
|
||||||
cryptproc.waitForFinished();
|
|
||||||
|
|
||||||
if (cryptproc.exitCode() == 0) {
|
if (m_process->exitCode() == 0) {
|
||||||
return KAuthorization::NoError;
|
return KAuthorization::NoError;
|
||||||
}
|
}
|
||||||
QString crypterror = cryptproc.readAllStandardError();
|
QString crypterror = m_process->readAllStandardError();
|
||||||
if (crypterror.isEmpty()) {
|
if (crypterror.isEmpty()) {
|
||||||
crypterror = cryptproc.readAllStandardOutput();
|
crypterror = m_process->readAllStandardOutput();
|
||||||
}
|
}
|
||||||
kWarning() << crypterror;
|
kWarning() << crypterror;
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
|
@ -101,30 +109,16 @@ int SolidUiServerHelper::mount(const QVariantMap ¶meters)
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString device = parameters.value("device").toString();
|
m_parameters = parameters;
|
||||||
const QString mountpoint = parameters.value("mountpoint").toString();
|
QTimer::singleShot(500, this, SLOT(slotMount()));
|
||||||
const bool readonly = parameters.value("readonly").toBool();
|
m_eventloop->exec();
|
||||||
// qDebug() << Q_FUNC_INFO << device << mountpoint << readonly;
|
|
||||||
|
|
||||||
QStringList mountargs = QStringList() << device << mountpoint;
|
if (m_process->exitCode() == 0) {
|
||||||
if (readonly) {
|
|
||||||
#if defined(Q_OS_SOLARIS)
|
|
||||||
mountargs << QString::fromLatin1("-oro");
|
|
||||||
#else
|
|
||||||
mountargs << QString::fromLatin1("-r");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
QProcess mountproc;
|
|
||||||
mountproc.start("mount", mountargs);
|
|
||||||
mountproc.waitForStarted();
|
|
||||||
mountproc.waitForFinished();
|
|
||||||
|
|
||||||
if (mountproc.exitCode() == 0) {
|
|
||||||
return KAuthorization::NoError;
|
return KAuthorization::NoError;
|
||||||
}
|
}
|
||||||
QString mounterror = mountproc.readAllStandardError();
|
QString mounterror = m_process->readAllStandardError();
|
||||||
if (mounterror.isEmpty()) {
|
if (mounterror.isEmpty()) {
|
||||||
mounterror = mountproc.readAllStandardOutput();
|
mounterror = m_process->readAllStandardOutput();
|
||||||
}
|
}
|
||||||
kWarning() << mounterror;
|
kWarning() << mounterror;
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
|
@ -136,22 +130,65 @@ int SolidUiServerHelper::unmount(const QVariantMap ¶meters)
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString mountpoint = parameters.value("mountpoint").toString();
|
m_parameters = parameters;
|
||||||
const QStringList umountargs = QStringList() << mountpoint;
|
QTimer::singleShot(500, this, SLOT(slotUnmount()));
|
||||||
QProcess umountproc;
|
m_eventloop->exec();
|
||||||
umountproc.start("umount", umountargs);
|
|
||||||
umountproc.waitForStarted();
|
|
||||||
umountproc.waitForFinished();
|
|
||||||
|
|
||||||
if (umountproc.exitCode() == 0) {
|
if (m_process->exitCode() == 0) {
|
||||||
return KAuthorization::NoError;
|
return KAuthorization::NoError;
|
||||||
}
|
}
|
||||||
QString umounterror = umountproc.readAllStandardError();
|
QString umounterror = m_process->readAllStandardError();
|
||||||
if (umounterror.isEmpty()) {
|
if (umounterror.isEmpty()) {
|
||||||
umounterror = umountproc.readAllStandardOutput();
|
umounterror = m_process->readAllStandardOutput();
|
||||||
}
|
}
|
||||||
kWarning() << umounterror;
|
kWarning() << umounterror;
|
||||||
return KAuthorization::HelperError;
|
return KAuthorization::HelperError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SolidUiServerHelper::slotCryptOpen()
|
||||||
|
{
|
||||||
|
Q_ASSERT(!m_cryptbin.isEmpty());
|
||||||
|
const QString device = m_parameters.value("device").toString();
|
||||||
|
const QString name = m_parameters.value("name").toString();
|
||||||
|
const QByteArray password = QByteArray::fromHex(m_parameters.value("password").toByteArray());
|
||||||
|
const QStringList cryptargs = QStringList() << "--batch-mode" << "--key-file=-" << "open" << device << name;
|
||||||
|
m_process->start(m_cryptbin, cryptargs);
|
||||||
|
m_process->waitForStarted(s_waittime);
|
||||||
|
m_process->write(password);
|
||||||
|
m_process->closeWriteChannel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SolidUiServerHelper::slotCryptClose()
|
||||||
|
{
|
||||||
|
Q_ASSERT(!m_cryptbin.isEmpty());
|
||||||
|
const QString name = m_parameters.value("name").toString();
|
||||||
|
const QStringList cryptargs = QStringList() << "--batch-mode" << "close" << name;
|
||||||
|
m_process->start(m_cryptbin, cryptargs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SolidUiServerHelper::slotMount()
|
||||||
|
{
|
||||||
|
const QString device = m_parameters.value("device").toString();
|
||||||
|
const QString mountpoint = m_parameters.value("mountpoint").toString();
|
||||||
|
const bool readonly = m_parameters.value("readonly").toBool();
|
||||||
|
// qDebug() << Q_FUNC_INFO << device << mountpoint << readonly;
|
||||||
|
|
||||||
|
QStringList mountargs = QStringList() << device << mountpoint;
|
||||||
|
if (readonly) {
|
||||||
|
#if defined(Q_OS_SOLARIS)
|
||||||
|
mountargs << QString::fromLatin1("-oro");
|
||||||
|
#else
|
||||||
|
mountargs << QString::fromLatin1("-r");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
m_process->start("mount", mountargs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SolidUiServerHelper::slotUnmount()
|
||||||
|
{
|
||||||
|
const QString mountpoint = m_parameters.value("mountpoint").toString();
|
||||||
|
const QStringList umountargs = QStringList() << mountpoint;
|
||||||
|
m_process->start("umount", umountargs);
|
||||||
|
}
|
||||||
|
|
||||||
K_AUTH_MAIN("org.kde.soliduiserver.mountunmounthelper", SolidUiServerHelper)
|
K_AUTH_MAIN("org.kde.soliduiserver.mountunmounthelper", SolidUiServerHelper)
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
#ifndef SOLIDUISERVER_HELPER_H
|
#ifndef SOLIDUISERVER_HELPER_H
|
||||||
#define SOLIDUISERVER_HELPER_H
|
#define SOLIDUISERVER_HELPER_H
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QEventLoop>
|
||||||
|
|
||||||
#include <kauthorization.h>
|
#include <kauthorization.h>
|
||||||
|
|
||||||
class SolidUiServerHelper : public KAuthorization
|
class SolidUiServerHelper : public KAuthorization
|
||||||
|
@ -26,11 +29,25 @@ class SolidUiServerHelper : public KAuthorization
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SolidUiServerHelper(const char* const helper, QObject *parent = nullptr);
|
SolidUiServerHelper(const char* const helper, QObject *parent = nullptr);
|
||||||
|
~SolidUiServerHelper();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
int cryptopen(const QVariantMap ¶meters);
|
int cryptopen(const QVariantMap ¶meters);
|
||||||
int cryptclose(const QVariantMap ¶meters);
|
int cryptclose(const QVariantMap ¶meters);
|
||||||
int mount(const QVariantMap ¶meters);
|
int mount(const QVariantMap ¶meters);
|
||||||
int unmount(const QVariantMap ¶meters);
|
int unmount(const QVariantMap ¶meters);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void slotCryptOpen();
|
||||||
|
void slotCryptClose();
|
||||||
|
void slotMount();
|
||||||
|
void slotUnmount();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariantMap m_parameters;
|
||||||
|
QString m_cryptbin;
|
||||||
|
QProcess* m_process;
|
||||||
|
QEventLoop* m_eventloop;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SOLIDUISERVER_HELPER_H
|
#endif // SOLIDUISERVER_HELPER_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue