1
0
power-profiles-daemon/fd1664dfe26f13f8c8cd7b44483cd872dfdede36.patch

147 lines
4.8 KiB
Diff

From fd1664dfe26f13f8c8cd7b44483cd872dfdede36 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Mon, 8 Nov 2021 15:39:07 +0100
Subject: [PATCH] main: Error out on D-Bus communication errors
The bug reporting tool in Fedora, in its infinite wisdom, considers
innocuous exceptions that occur when system daemons aren't running
to be bug report worthy.
Catch all the D-Bus communication errors, print an error message
detailing the problem and exit with a return value of 1 when they occur
instead of printing an exception.
See:
https://bugzilla.redhat.com/show_bug.cgi?id=2019536
https://bugzilla.redhat.com/show_bug.cgi?id=2020251
https://bugzilla.redhat.com/show_bug.cgi?id=2020941
---
meson.build | 2 +-
src/powerprofilesctl.in | 44 +++++++++++++++++++++++++++++------------
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/meson.build b/meson.build
index d7b5a8c..84e67c6 100644
--- a/meson.build
+++ b/meson.build
@@ -44,7 +44,7 @@ add_global_arguments(common_cflags, language: 'c')
if get_option('pylint')
pylint = find_program('pylint-3', 'pylint3', 'pylint', required: true)
- pylint_flags = ['-d', 'C0116', '-d', 'C0114', '-d', 'W0707']
+ pylint_flags = ['-d', 'C0116', '-d', 'C0114', '-d', 'W0707', '-d', 'W0706' ]
endif
xmllint = find_program('xmllint', required: false)
diff --git a/src/powerprofilesctl.in b/src/powerprofilesctl.in
index 9b5e201..1461e3a 100755
--- a/src/powerprofilesctl.in
+++ b/src/powerprofilesctl.in
@@ -98,7 +98,7 @@ def get_proxy():
'/net/hadess/PowerProfiles',
'org.freedesktop.DBus.Properties', None)
except:
- raise SystemError
+ raise
return proxy
def _get():
@@ -117,13 +117,13 @@ def get_profiles_property(prop):
try:
proxy = get_proxy()
except:
- raise SystemError
+ raise
profiles = None
try:
profiles = proxy.Get('(ss)', 'net.hadess.PowerProfiles', prop)
except:
- raise ReferenceError
+ raise
else:
return profiles
@@ -134,8 +134,7 @@ def _list():
degraded = (reason != '')
active = get_proxy().Get('(ss)', 'net.hadess.PowerProfiles', 'ActiveProfile')
except:
- print("Couldn\'t get Profiles: ", sys.exc_info()[0])
- raise SystemError
+ raise
else:
index = 0
for profile in reversed(profiles):
@@ -152,8 +151,7 @@ def _list_holds():
try:
holds = get_profiles_property('ActiveProfileHolds')
except:
- # print("Couldn\'t get ActiveProfileHolds: ", sys.exc_info()[0])
- raise SystemError
+ raise
else:
index = 0
for hold in holds:
@@ -173,7 +171,7 @@ def _launch(args, profile, appid, reason):
'/net/hadess/PowerProfiles',
'net.hadess.PowerProfiles', None)
except:
- raise SystemError
+ raise
cookie = proxy.HoldProfile('(sss)', profile, reason, appid)
@@ -208,16 +206,32 @@ def main(): # pylint: disable=too-many-branches, disable=too-many-statements
elif command == 'version':
version()
elif command == 'get':
- _get()
+ try:
+ _get()
+ except GLib.Error as error:
+ sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
+ sys.exit(1)
elif command == 'set':
if len(args) != 1:
usage_set()
sys.exit(1)
- _set(args[0])
+ try:
+ _set(args[0])
+ except GLib.Error as error:
+ sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
+ sys.exit(1)
elif command == 'list':
- _list()
+ try:
+ _list()
+ except GLib.Error as error:
+ sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
+ sys.exit(1)
elif command == 'list-holds':
- _list_holds()
+ try:
+ _list_holds()
+ except GLib.Error as error:
+ sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
+ sys.exit(1)
elif command == 'launch':
if len(args) == 0:
sys.exit(0)
@@ -256,7 +270,11 @@ def main(): # pylint: disable=too-many-branches, disable=too-many-statements
reason = 'Running ' + appid
if not profile:
profile = 'performance'
- _launch(args, profile, appid, reason)
+ try:
+ _launch(args, profile, appid, reason)
+ except GLib.Error as error:
+ sys.stderr.write(f'Failed to communicate with power-profiles-daemon: {format(error)}\n')
+ sys.exit(1)
if __name__ == '__main__':
main()
--
GitLab