From 17d704427c960b9f7af4ca02f6456aa805dffa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavol=20=C5=BD=C3=A1=C4=8Dik?= Date: Tue, 3 Sep 2024 15:47:29 +0200 Subject: [PATCH] tuned-ppd: Support the new UPower PPD namespace Since version 0.20, power-profiles-daemon exposes its DBus interface under "org.freedesktop.UPower.PowerProfiles" alongside the previous name. To be compatible with PPD, this commit implements the same change into tuned-ppd. Resolves: #683 --- Makefile | 11 ++++++++--- tuned-ppd.py | 8 ++++---- tuned.spec | 3 +++ tuned/consts.py | 20 ++++++++++++++++---- tuned/ppd/dbus.conf | 10 +++++----- tuned/ppd/tuned-ppd.dbus.service | 2 +- tuned/ppd/tuned-ppd.policy | 4 ++-- tuned/ppd/tuned-ppd.service | 1 + 8 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index f73f572f2..7db4e1596 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ TUNED_PROFILES_DIR = $(TUNED_SYSTEM_DIR)/profiles TUNED_RECOMMEND_DIR = $(TUNED_SYSTEM_DIR)/recommend.d TUNED_USER_RECOMMEND_DIR = $(SYSCONFDIR)/tuned/recommend.d BASH_COMPLETIONS = $(DATADIR)/bash-completion/completions +PPD_BUS_NAMES = org.freedesktop.UPower.PowerProfiles net.hadess.PowerProfiles copy_executable = install -Dm 0755 $(1) $(2) rewrite_shebang = sed -i -r -e $(SHEBANG_REWRITE_REGEX) $(1) @@ -231,10 +232,14 @@ install: install-dirs install-ppd: install $(call install_python_script,tuned-ppd.py,$(DESTDIR)/usr/sbin/tuned-ppd) install -Dpm 0644 tuned/ppd/tuned-ppd.service $(DESTDIR)$(UNITDIR)/tuned-ppd.service - install -Dpm 0644 tuned/ppd/tuned-ppd.dbus.service $(DESTDIR)$(DATADIR)/dbus-1/system-services/net.hadess.PowerProfiles.service - install -Dpm 0644 tuned/ppd/dbus.conf $(DESTDIR)$(DATADIR)/dbus-1/system.d/net.hadess.PowerProfiles.conf - install -Dpm 0644 tuned/ppd/tuned-ppd.policy $(DESTDIR)$(DATADIR)/polkit-1/actions/net.hadess.PowerProfiles.policy install -Dpm 0644 tuned/ppd/ppd.conf $(DESTDIR)$(SYSCONFDIR)/tuned/ppd.conf + $(foreach bus, $(PPD_BUS_NAMES), \ + install -Dpm 0644 tuned/ppd/tuned-ppd.dbus.service $(DESTDIR)$(DATADIR)/dbus-1/system-services/$(bus).service; \ + sed -i 's/?name?/$(bus)/g' $(DESTDIR)$(DATADIR)/dbus-1/system-services/$(bus).service; \ + install -Dpm 0644 tuned/ppd/dbus.conf $(DESTDIR)$(DATADIR)/dbus-1/system.d/$(bus).conf; \ + sed -i 's/?name?/$(bus)/g' $(DESTDIR)$(DATADIR)/dbus-1/system.d/$(bus).conf; \ + install -Dpm 0644 tuned/ppd/tuned-ppd.policy $(DESTDIR)$(DATADIR)/polkit-1/actions/$(bus).policy; \ + sed -i 's/?name?/$(bus)/g' $(DESTDIR)$(DATADIR)/polkit-1/actions/$(bus).policy;) clean: clean-html find -name "*.pyc" | xargs rm -f diff --git a/tuned-ppd.py b/tuned-ppd.py index ece733212..b88e619ce 100755 --- a/tuned-ppd.py +++ b/tuned-ppd.py @@ -56,10 +56,10 @@ def handler_wrapper(_signal_number, _frame): handle_signal(signal.SIGTERM, controller.terminate) handle_signal(signal.SIGHUP, controller.initialize) - dbus_exporter = exports.dbus_with_properties.DBusExporterWithProperties( - consts.PPD_DBUS_BUS, consts.PPD_DBUS_INTERFACE, consts.PPD_DBUS_OBJECT, consts.PPD_NAMESPACE - ) + for name_dict in consts.PPD_DBUS_NAMES: + dbus_exporter = exports.dbus_with_properties.DBusExporterWithProperties( + name_dict["bus"], name_dict["interface"], name_dict["object"], name_dict["namespace"]) + exports.register_exporter(dbus_exporter) - exports.register_exporter(dbus_exporter) exports.register_object(controller) controller.run() diff --git a/tuned.spec b/tuned.spec index a48840710..a1026bf0b 100644 --- a/tuned.spec +++ b/tuned.spec @@ -610,6 +610,9 @@ fi %{_datadir}/dbus-1/system-services/net.hadess.PowerProfiles.service %{_datadir}/dbus-1/system.d/net.hadess.PowerProfiles.conf %{_datadir}/polkit-1/actions/net.hadess.PowerProfiles.policy +%{_datadir}/dbus-1/system-services/org.freedesktop.UPower.PowerProfiles.service +%{_datadir}/dbus-1/system.d/org.freedesktop.UPower.PowerProfiles.conf +%{_datadir}/polkit-1/actions/org.freedesktop.UPower.PowerProfiles.policy %config(noreplace) %{_sysconfdir}/tuned/ppd.conf %changelog diff --git a/tuned/consts.py b/tuned/consts.py index 5134684c9..40fce7aeb 100644 --- a/tuned/consts.py +++ b/tuned/consts.py @@ -92,11 +92,23 @@ PREFIX_PROFILE_USER = "User" # PPD-to-tuned API translation daemon configuration -PPD_NAMESPACE = "net.hadess.PowerProfiles" -PPD_DBUS_BUS = PPD_NAMESPACE -PPD_DBUS_OBJECT = "/net/hadess/PowerProfiles" -PPD_DBUS_INTERFACE = PPD_DBUS_BUS PPD_CONFIG_FILE = "/etc/tuned/ppd.conf" +PPD_DBUS_BUS = "org.freedesktop.UPower.PowerProfiles" +PPD_DBUS_BUS_LEGACY = "net.hadess.PowerProfiles" +PPD_DBUS_NAMES = [ + { + "bus": PPD_DBUS_BUS, + "namespace": PPD_DBUS_BUS, + "interface": PPD_DBUS_BUS, + "object": "/org/freedesktop/UPower/PowerProfiles" + }, + { + "bus": PPD_DBUS_BUS_LEGACY, + "namespace": PPD_DBUS_BUS_LEGACY, + "interface": PPD_DBUS_BUS_LEGACY, + "object": "/net/hadess/PowerProfiles" + } +] # After adding new option to tuned-main.conf add here its name with CFG_ prefix # and eventually default value with CFG_DEF_ prefix (default is None) diff --git a/tuned/ppd/dbus.conf b/tuned/ppd/dbus.conf index 2f2d6fa03..e20248e2a 100644 --- a/tuned/ppd/dbus.conf +++ b/tuned/ppd/dbus.conf @@ -4,13 +4,13 @@ - + - - - - + + + + diff --git a/tuned/ppd/tuned-ppd.dbus.service b/tuned/ppd/tuned-ppd.dbus.service index 7866f097c..dad6c494a 100644 --- a/tuned/ppd/tuned-ppd.dbus.service +++ b/tuned/ppd/tuned-ppd.dbus.service @@ -1,5 +1,5 @@ [D-BUS Service] -Name=net.hadess.PowerProfiles +Name=?name? Exec=/bin/false User=root SystemdService=tuned-ppd.service diff --git a/tuned/ppd/tuned-ppd.policy b/tuned/ppd/tuned-ppd.policy index 8106808d4..e05dda097 100644 --- a/tuned/ppd/tuned-ppd.policy +++ b/tuned/ppd/tuned-ppd.policy @@ -6,7 +6,7 @@ TuneD https://tuned-project.org/ - + Hold power profile Authentication is required to hold power profiles. @@ -16,7 +16,7 @@ - + Release power profile Authentication is required to release power profiles. diff --git a/tuned/ppd/tuned-ppd.service b/tuned/ppd/tuned-ppd.service index f18003e0b..53ae86fa5 100644 --- a/tuned/ppd/tuned-ppd.service +++ b/tuned/ppd/tuned-ppd.service @@ -6,6 +6,7 @@ Before=multi-user.target display-manager.target [Service] Type=dbus +BusName=org.freedesktop.UPower.PowerProfiles BusName=net.hadess.PowerProfiles ExecStart=/usr/sbin/tuned-ppd -l