2
KSysGuard, the KDE System Guard
4
Copyright (c) 2009 John Tapsell <john.tapsell@kde.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
Boston, MA 02110-1301, USA.
24
#include "processes_local_p.h"
26
KSysGuardProcessListHelper::KSysGuardProcessListHelper()
28
qRegisterMetaType<QList<long long> >();
31
/* The functions here run as ROOT. So be careful. DO NOT TRUST THE INPUTS TO BE SANE. */
32
#define GET_PID(i) parameters.value(QString("pid%1").arg(i), -1).toULongLong(); if(pid < 0) return KAuth::ActionReply::HelperErrorReply;
33
KAuth::ActionReply KSysGuardProcessListHelper::sendsignal(QVariantMap parameters) {
34
KAuth::ActionReply errorReply(KAuth::ActionReply::HelperError);
35
if(!parameters.contains("signal")) {
36
errorReply.setErrorDescription("Internal error - no signal parameter was passed to the helper");
37
errorReply.setErrorCode(1);
40
if(!parameters.contains("pidcount")) {
41
errorReply.setErrorDescription("Internal error - no pidcount parameter was passed to the helper");
42
errorReply.setErrorCode(2);
46
KSysGuard::ProcessesLocal processes;
47
int signal = qvariant_cast<int>(parameters.value("signal"));
49
int numProcesses = parameters.value("pidcount").toInt();
50
QStringList errorList;
51
for (int i = 0; i < numProcesses; ++i) {
52
qlonglong pid = GET_PID(i);
53
bool successForThisPid = processes.sendSignal(pid, signal);
54
if (!successForThisPid)
55
errorList << QString::number(pid);
56
success = successForThisPid && success;
59
return KAuth::ActionReply::SuccessReply;
61
errorReply.setErrorDescription(QString("Could not send signal to: ") + errorList.join(", "));
62
errorReply.setErrorCode(0);
67
KAuth::ActionReply KSysGuardProcessListHelper::renice(QVariantMap parameters) {
68
if(!parameters.contains("nicevalue") || !parameters.contains("pidcount"))
69
return KAuth::ActionReply::HelperErrorReply;
71
KSysGuard::ProcessesLocal processes;
72
int niceValue = qvariant_cast<int>(parameters.value("nicevalue"));
74
int numProcesses = parameters.value("pidcount").toInt();
75
for (int i = 0; i < numProcesses; ++i) {
76
qlonglong pid = GET_PID(i);
77
success = processes.setNiceness(pid, niceValue) && success;
80
return KAuth::ActionReply::SuccessReply;
82
return KAuth::ActionReply::HelperErrorReply;
85
KAuth::ActionReply KSysGuardProcessListHelper::changeioscheduler(QVariantMap parameters) {
86
if(!parameters.contains("ioScheduler") || !parameters.contains("ioSchedulerPriority") || !parameters.contains("pidcount"))
87
return KAuth::ActionReply::HelperErrorReply;
89
KSysGuard::ProcessesLocal processes;
90
int ioScheduler = qvariant_cast<int>(parameters.value("ioScheduler"));
91
int ioSchedulerPriority = qvariant_cast<int>(parameters.value("ioSchedulerPriority"));
93
int numProcesses = parameters.value("pidcount").toInt();
94
for (int i = 0; i < numProcesses; ++i) {
95
qlonglong pid = GET_PID(i);
96
success = processes.setIoNiceness(pid, ioScheduler, ioSchedulerPriority) && success;
99
return KAuth::ActionReply::SuccessReply;
101
return KAuth::ActionReply::HelperErrorReply;
104
KAuth::ActionReply KSysGuardProcessListHelper::changecpuscheduler(QVariantMap parameters) {
105
if(!parameters.contains("cpuScheduler") || !parameters.contains("cpuSchedulerPriority") || !parameters.contains("pidcount"))
106
return KAuth::ActionReply::HelperErrorReply;
108
KSysGuard::ProcessesLocal processes;
109
int cpuScheduler = qvariant_cast<int>(parameters.value("cpuScheduler"));
110
int cpuSchedulerPriority = qvariant_cast<int>(parameters.value("cpuSchedulerPriority"));
113
int numProcesses = parameters.value("pidcount").toInt();
114
for (int i = 0; i < numProcesses; ++i) {
115
qlonglong pid = GET_PID(i);
116
success = processes.setScheduler(pid, cpuScheduler, cpuSchedulerPriority) && success;
119
return KAuth::ActionReply::SuccessReply;
121
return KAuth::ActionReply::HelperErrorReply;
124
KDE4_AUTH_HELPER_MAIN("org.kde.ksysguard.processlisthelper", KSysGuardProcessListHelper)