File indexing completed on 2024-05-12 15:41:46

0001 #include "kiogui_debug.h"
0002 #include "managerinterface.h"
0003 #include "scopedprocessrunner_p.h"
0004 #include "systemdprocessrunner_p.h"
0005 
0006 using namespace org::freedesktop;
0007 
0008 ScopedProcessRunner::ScopedProcessRunner()
0009     : ForkingProcessRunner()
0010 {
0011 }
0012 
0013 void ScopedProcessRunner::slotProcessStarted()
0014 {
0015     ForkingProcessRunner::slotProcessStarted();
0016     const QString serviceName = maybeAliasedName(QStringLiteral("app-%1-%2.scope"));
0017 
0018     const auto manager = new systemd1::Manager(systemdService, systemdPath, QDBusConnection::sessionBus(), this);
0019 
0020     // Ask systemd for a new transient service
0021     const auto startReply =
0022         manager->StartTransientUnit(serviceName,
0023                                     QStringLiteral("fail"), // mode defines what to do in the case of a name conflict, in this case, just do nothing
0024                                     {// Properties of the transient service unit
0025                                      {QStringLiteral("Slice"), QStringLiteral("app.slice")},
0026                                      {QStringLiteral("Description"), m_description},
0027                                      {QStringLiteral("SourcePath"), m_desktopFilePath},
0028                                      {QStringLiteral("PIDs"), QVariant::fromValue(QList<uint>{static_cast<uint>(m_process->processId())})}},
0029                                     {} // aux is currently unused and should be passed as empty array.
0030         );
0031 
0032     connect(new QDBusPendingCallWatcher(startReply, this), &QDBusPendingCallWatcher::finished, [serviceName](QDBusPendingCallWatcher *watcher) {
0033         QDBusPendingReply<QDBusObjectPath> reply = *watcher;
0034         watcher->deleteLater();
0035         if (reply.isError()) {
0036             qCWarning(KIO_GUI) << "Failed to register new cgroup:" << serviceName << reply.error().name() << reply.error().message();
0037         } else {
0038             qCDebug(KIO_GUI) << "Successfully registered new cgroup:" << serviceName;
0039         }
0040     });
0041 }
0042 
0043 #include "moc_scopedprocessrunner_p.cpp"