KIO

scopedprocessrunner.cpp
1#include "kiogui_debug.h"
2#include "managerinterface.h"
3#include "scopedprocessrunner_p.h"
4#include "systemdprocessrunner_p.h"
5
6using namespace org::freedesktop;
7
8ScopedProcessRunner::ScopedProcessRunner()
9 : ForkingProcessRunner()
10{
11}
12
13void ScopedProcessRunner::slotProcessStarted()
14{
15 ForkingProcessRunner::slotProcessStarted();
16 // As specified in "XDG standardization for applications" in https://systemd.io/DESKTOP_ENVIRONMENTS/
17 const QString serviceName = QStringLiteral("app-%1-%2.scope").arg(escapeUnitName(resolveServiceAlias()), QUuid::createUuid().toString(QUuid::Id128));
18
19 const auto manager = new systemd1::Manager(systemdService, systemdPath, QDBusConnection::sessionBus(), this);
20
21 // Ask systemd for a new transient service
22 const auto startReply =
23 manager->StartTransientUnit(serviceName,
24 QStringLiteral("fail"), // mode defines what to do in the case of a name conflict, in this case, just do nothing
25 {// Properties of the transient service unit
26 {QStringLiteral("Slice"), QStringLiteral("app.slice")},
27 {QStringLiteral("Description"), m_description},
28 {QStringLiteral("SourcePath"), m_desktopFilePath},
29 {QStringLiteral("PIDs"), QVariant::fromValue(QList<uint>{static_cast<uint>(m_process->processId())})}},
30 {} // aux is currently unused and should be passed as empty array.
31 );
32
33 connect(new QDBusPendingCallWatcher(startReply, this), &QDBusPendingCallWatcher::finished, [serviceName](QDBusPendingCallWatcher *watcher) {
35 watcher->deleteLater();
36 if (reply.isError()) {
37 qCWarning(KIO_GUI) << "Failed to register new cgroup:" << serviceName << reply.error().name() << reply.error().message();
38 } else {
39 qCDebug(KIO_GUI) << "Successfully registered new cgroup:" << serviceName;
40 }
41 });
42}
43
44#include "moc_scopedprocessrunner_p.cpp"
char * toString(const EngineQuery &query)
QDBusConnection sessionBus()
void finished(QDBusPendingCallWatcher *self)
bool isError() const const
void deleteLater()
QString arg(Args &&... args) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUuid createUuid()
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.