mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 02:42:50 +00:00
plasma: kill runner optimization
by calling kill() function instead of spawning a process Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
bcb99e3eff
commit
8fb86d0a8c
2 changed files with 17 additions and 27 deletions
|
@ -20,7 +20,6 @@
|
||||||
#include "killrunner.h"
|
#include "killrunner.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QProcess>
|
|
||||||
#include <KDebug>
|
#include <KDebug>
|
||||||
#include <KIcon>
|
#include <KIcon>
|
||||||
#include <KUser>
|
#include <KUser>
|
||||||
|
@ -36,10 +35,6 @@ KillRunner::KillRunner(QObject *parent, const QVariantList& args)
|
||||||
reloadConfiguration();
|
reloadConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
KillRunner::~KillRunner()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void KillRunner::reloadConfiguration()
|
void KillRunner::reloadConfiguration()
|
||||||
{
|
{
|
||||||
#warning TODO: untranslated keyword match, why is it even translated when it is configurable?
|
#warning TODO: untranslated keyword match, why is it even translated when it is configurable?
|
||||||
|
@ -106,16 +101,19 @@ void KillRunner::match(Plasma::RunnerContext &context)
|
||||||
|
|
||||||
// Set the relevance
|
// Set the relevance
|
||||||
switch (m_sorting) {
|
switch (m_sorting) {
|
||||||
case KillRunnerSort::CPU:
|
case KillRunnerSort::CPU: {
|
||||||
match.setRelevance((process->userUsage + process->sysUsage) / 100);
|
match.setRelevance((process->userUsage + process->sysUsage) / 100);
|
||||||
break;
|
break;
|
||||||
case KillRunnerSort::CPUI:
|
}
|
||||||
|
case KillRunnerSort::CPUI: {
|
||||||
match.setRelevance(1 - (process->userUsage + process->sysUsage) / 100);
|
match.setRelevance(1 - (process->userUsage + process->sysUsage) / 100);
|
||||||
break;
|
break;
|
||||||
case KillRunnerSort::NONE:
|
}
|
||||||
|
case KillRunnerSort::NONE: {
|
||||||
match.setRelevance(name.compare(term, Qt::CaseInsensitive) == 0 ? 1 : 9);
|
match.setRelevance(name.compare(term, Qt::CaseInsensitive) == 0 ? 1 : 9);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
matches << match;
|
matches << match;
|
||||||
}
|
}
|
||||||
|
@ -127,28 +125,21 @@ void KillRunner::match(Plasma::RunnerContext &context)
|
||||||
void KillRunner::run(const Plasma::QueryMatch &match)
|
void KillRunner::run(const Plasma::QueryMatch &match)
|
||||||
{
|
{
|
||||||
const quint64 pid = match.data().toULongLong();
|
const quint64 pid = match.data().toULongLong();
|
||||||
int signal = SIGKILL;
|
int sig = SIGKILL;
|
||||||
if (match.selectedAction() != NULL) {
|
if (match.selectedAction() != NULL) {
|
||||||
signal = match.selectedAction()->data().toInt();
|
sig = match.selectedAction()->data().toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList args;
|
if (::kill(pid, sig) == -1) {
|
||||||
args << QString("-%1").arg(signal) << QString::number(pid);
|
const int savederrno = errno;
|
||||||
|
KMessageBox::error(nullptr, qt_error_string(savederrno));
|
||||||
QProcess killproc(this);
|
|
||||||
killproc.start("kill", args);
|
|
||||||
if (!killproc.waitForFinished() || killproc.exitCode() != 0) {
|
|
||||||
const QString errorstring = QString::fromLocal8Bit(killproc.readAllStandardError());
|
|
||||||
KMessageBox::error(nullptr, errorstring);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QAction*> KillRunner::actionsForMatch(const Plasma::QueryMatch &match)
|
QList<QAction*> KillRunner::actionsForMatch(const Plasma::QueryMatch &match)
|
||||||
{
|
{
|
||||||
Q_UNUSED(match)
|
Q_UNUSED(match)
|
||||||
|
|
||||||
QList<QAction*> ret;
|
QList<QAction*> ret;
|
||||||
|
|
||||||
if (!action("SIGTERM")) {
|
if (!action("SIGTERM")) {
|
||||||
QAction* action = addAction("SIGTERM", KIcon("application-exit"), i18n("Send SIGTERM"));
|
QAction* action = addAction("SIGTERM", KIcon("application-exit"), i18n("Send SIGTERM"));
|
||||||
action->setData(int(SIGTERM));
|
action->setData(int(SIGTERM));
|
||||||
|
|
|
@ -33,7 +33,6 @@ class KillRunner : public Plasma::AbstractRunner
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KillRunner(QObject *parent, const QVariantList& args);
|
KillRunner(QObject *parent, const QVariantList& args);
|
||||||
~KillRunner();
|
|
||||||
|
|
||||||
void match(Plasma::RunnerContext &context);
|
void match(Plasma::RunnerContext &context);
|
||||||
void run(const Plasma::QueryMatch &match);
|
void run(const Plasma::QueryMatch &match);
|
||||||
|
|
Loading…
Add table
Reference in a new issue