Commit 0bdb0197 authored by David Redondo's avatar David Redondo 🏎
Browse files

Update cgroup regex to be in line with spec

The spec also allows now app[-<launcher>]-<ApplicationID>[@<RANDOM>].service
(see https://systemd.io/DESKTOP_ENVIRONMENTS/).
Also add a test to verify that every allowed combination passes.
parent b0043f2e
......@@ -35,6 +35,7 @@ ecm_add_test(formattertest.cpp LINK_LIBRARIES Qt5::Test KSysGuard::Formatter)
ecm_add_test(sensortreemodeltest.cpp LINK_LIBRARIES Qt5::Test Qt5::DBus KSysGuard::Sensors)
ecm_add_test(sensordatamodeltest.cpp LINK_LIBRARIES Qt5::Test Qt5::DBus KSysGuard::Sensors KSysGuard::Formatter)
ecm_add_test(processdatamodeltest.cpp LINK_LIBRARIES Qt5::Test KSysGuard::ProcessCore)
ecm_add_test(cgrouptest.cpp LINK_LIBRARIES Qt5::Test KF5::Service KSysGuard::ProcessCore)
# set( ksysguarddtest_SRCS ksysguarddtest.cpp ${libksysguard_SOURCE_DIR}/ksgrd/SensorAgent.cpp ${libksysguard_SOURCE_DIR}/ksgrd/SensorManager.cpp ${libksysguard_SOURCE_DIR}/ksgrd/SensorSocketAgent.cpp ${libksysguard_SOURCE_DIR}/ksgrd/SensorShellAgent.cpp)
#
......
/*
Copyright (c) 2020 David Redondo <kde@david-redondo.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cgrouptest.h"
#define private public
#include "cgroup.h"
#define private private
#include <QTest>
void CGroupTest::testAppUnitRegex_data()
{
QTest::addColumn<QString>("id");
QTest::addColumn<QString>("desktopName");
QTest::newRow("service") << "app-gnome-org.gnome.Evince@12345.service" << "org.gnome.Evince";
QTest::newRow("service .desktop") << "app-flatpak-org.telegram.desktop@12345.service" << "org.telegram.desktop";
QTest::newRow("service no launcher") << "app-org.kde.okular@12345.service" << "org.kde.okular";
QTest::newRow("service no random") << "app-KDE-org.kde.okular.service" << "org.kde.okular";
QTest::newRow("service no launcher no random") << "app-org.kde.amarok.service" << "org.kde.amarok";
QTest::newRow("scope") << "app-gnome-org.gnome.Evince-12345.scope" << "org.gnome.Evince";
QTest::newRow("scope no launcher") << "app-org.gnome.Evince-12345.scope" << "org.gnome.Evince";
}
void CGroupTest::testAppUnitRegex()
{
QFETCH(QString, id);
QFETCH(QString, desktopName);
KSysGuard::CGroup c(id);
if (c.service()->menuId().isEmpty()) {
// The service is not known on d machine an we constructed a service with the id as name
QCOMPARE(c.service()->name(), desktopName);
} else {
QCOMPARE(c.service()->desktopEntryName(), desktopName);
}
}
QTEST_MAIN(CGroupTest)
#include "cgrouptest.moc"
/*
Copyright (c) 2020 David Redondo <kde@david-redondo.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CGROUPTEST_H
#define CGROUPTEST_H
#include <QObject>
class CGroupTest : public QObject {
Q_OBJECT
private Q_SLOTS:
void testAppUnitRegex();
void testAppUnitRegex_data();
};
#endif
/*
Copyright (c) 2019 David Edmundson <davidedmundson@kde.org>
Copyright (c) 2020 David Redondo <kde@david-redondo.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -57,10 +58,13 @@ public:
Q_GLOBAL_STATIC(CGroupSystemInformation, s_cGroupSystemInformation)
// The spec says that the two following schemes are allowed
// - app[-<launcher>]-<ApplicationID>-<RANDOM>.scope
// - app[-<launcher>]-<ApplicationID>[@<RANDOM>].service
// Flatpak's are currently in a cgroup, but they don't follow the specification
// this has been fixed, but this provides some compatability till that lands
// app vs apps exists because the spec changed.
QRegularExpression CGroupPrivate::s_appIdFromProcessGroupPattern(QStringLiteral("[apps|app|flatpak]-([^-]+)-.*"));
QRegularExpression CGroupPrivate::s_appIdFromProcessGroupPattern(QStringLiteral("[app|apps|flatpak]-(?:[^-]*-)?([^-]+(?=-.*\\.scope)|[^@]+(?=(?:@.*)?\\.service))"));
CGroup::CGroup(const QString &id)
: d(new CGroupPrivate(id))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment