File indexing completed on 2024-04-28 03:55:30

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     // As specified in "XDG standardization for applications" in https://systemd.io/DESKTOP_ENVIRONMENTS/
0017     const QString serviceName = QStringLiteral("app-%1-%2.scope").arg(escapeUnitName(resolveServiceAlias()), QUuid::createUuid().toString(QUuid::Id128));
0018 
0019     const auto manager = new systemd1::Manager(systemdService, systemdPath, QDBusConnection::sessionBus(), this);
0020 
0021     // Ask systemd for a new transient service
0022     const auto startReply =
0023         manager->StartTransientUnit(serviceName,
0024                                     QStringLiteral("fail"), // mode defines what to do in the case of a name conflict, in this case, just do nothing
0025                                     {// Properties of the transient service unit
0026                                      {QStringLiteral("Slice"), QStringLiteral("app.slice")},
0027                                      {QStringLiteral("Description"), m_description},
0028                                      {QStringLiteral("SourcePath"), m_desktopFilePath},
0029                                      {QStringLiteral("PIDs"), QVariant::fromValue(QList<uint>{static_cast<uint>(m_process->processId())})}},
0030                                     {} // aux is currently unused and should be passed as empty array.
0031         );
0032 
0033     connect(new QDBusPendingCallWatcher(startReply, this), &QDBusPendingCallWatcher::finished, [serviceName](QDBusPendingCallWatcher *watcher) {
0034         QDBusPendingReply<QDBusObjectPath> reply = *watcher;
0035         watcher->deleteLater();
0036         if (reply.isError()) {
0037             qCWarning(KIO_GUI) << "Failed to register new cgroup:" << serviceName << reply.error().name() << reply.error().message();
0038         } else {
0039             qCDebug(KIO_GUI) << "Successfully registered new cgroup:" << serviceName;
0040         }
0041     });
0042 }
0043 
0044 #include "moc_scopedprocessrunner_p.cpp"