-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenrc_actions.cpp
70 lines (61 loc) · 2.46 KB
/
openrc_actions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "openrc_actions.h"
#include <KAuth/KAuthAction>
#include <KAuth/KAuthExecuteJob>
#include <rc.h>
#include <qprocess.h>
KAuth::ActionReply OpenRCHelper::removeservice( const QVariantMap& args )
{
KAuth::ActionReply reply;
QString serviceName(args[QStringLiteral("serviceName")].toString());
if(!rc_service_delete("default", serviceName.toStdString().c_str())) {
reply = KAuth::ActionReply::HelperErrorReply();
reply.setErrorDescription(QStringLiteral("OpenRC failed to remove service ") + serviceName + QStringLiteral("."));
return reply;
}
return reply;
}
KAuth::ActionReply OpenRCHelper::stopservice(const QVariantMap& args)
{
KAuth::ActionReply reply;
QString serviceName(args[QStringLiteral("serviceName")].toString());
QProcess process(this);
process.setProgram(QStringLiteral("/etc/init.d/") + serviceName);
QStringList cmds;
cmds << QStringLiteral("stop");
process.setArguments(cmds);
process.start();
if(!process.waitForFinished(20000)) {
reply = KAuth::ActionReply::HelperErrorReply();
reply.setErrorDescription(QStringLiteral("OpenRC failed to stop service ") + serviceName + QStringLiteral("."));
return reply;
}
if(process.exitStatus() == QProcess::CrashExit) {
reply = KAuth::ActionReply::HelperErrorReply();
reply.setErrorDescription(QStringLiteral("OpenRC failed to stop service ") + serviceName + QStringLiteral("."));
return reply;
}
return reply;
}
KAuth::ActionReply OpenRCHelper::restartservice(const QVariantMap& args)
{
KAuth::ActionReply reply;
QString serviceName(args[QStringLiteral("serviceName")].toString());
QProcess process(this);
process.setProgram(QStringLiteral("/etc/init.d/") + serviceName);
QStringList cmds;
cmds << QStringLiteral("restart");
process.setArguments(cmds);
process.start();
if(!process.waitForFinished(20000)) {
reply = KAuth::ActionReply::HelperErrorReply();
reply.setErrorDescription(QStringLiteral("OpenRC failed to restart service ") + serviceName + QStringLiteral("."));
return reply;
}
if(process.exitStatus() == QProcess::CrashExit) {
reply = KAuth::ActionReply::HelperErrorReply();
reply.setErrorDescription(QStringLiteral("OpenRC failed to restart service ") + serviceName + QStringLiteral("."));
return reply;
}
return reply;
}
KAUTH_HELPER_MAIN("tridentu.auth.openrc.service", OpenRCHelper);