From 0b3d5a4280354586ba7364fd81b1e397d94ea888 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Tue, 9 Mar 2021 13:55:45 -0800 Subject: [PATCH] add dbus_systemd to handle systemctl calls --- resources/lib/dbus_systemd.py | 14 ++++++++++++++ resources/lib/modules/system.py | 7 ++++--- resources/lib/modules/updates.py | 4 ++-- resources/lib/oe.py | 3 ++- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 resources/lib/dbus_systemd.py diff --git a/resources/lib/dbus_systemd.py b/resources/lib/dbus_systemd.py new file mode 100644 index 000000000..5c4708b95 --- /dev/null +++ b/resources/lib/dbus_systemd.py @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020-present Team LibreELEC + +import dbus_utils + +BUS_NAME = 'org.freedesktop.systemd1' +PATH_SYSTEMD = '/org/freedesktop/systemd1' +INTERFACE_SYSTEMD_MANAGER = 'org.freedesktop.systemd1.Manager' + +def restart_unit(name, mode='replace'): + return dbus_utils.call_method(BUS_NAME, PATH_SYSTEMD, INTERFACE_SYSTEMD_MANAGER, 'RestartUnit', name, mode) + +def reboot(): + return dbus_utils.call_method(BUS_NAME, PATH_SYSTEMD, INTERFACE_SYSTEMD_MANAGER, 'Reboot') diff --git a/resources/lib/modules/system.py b/resources/lib/modules/system.py index 2d224e35e..93cf11362 100644 --- a/resources/lib/modules/system.py +++ b/resources/lib/modules/system.py @@ -16,6 +16,7 @@ import oeWindows from xml.dom import minidom import subprocess +import dbus_systemd xbmcDialog = xbmcgui.Dialog() @@ -394,7 +395,7 @@ def reset_xbmc(self, listItem=None): open(self.XBMC_RESET_FILE, 'a').close() oe.winOeMain.close() oe.xbmcm.waitForAbort(1) - subprocess.call(['/usr/bin/systemctl', '--no-block', 'reboot'], close_fds=True) + dbus_systemd.reboot() @log.log_function() def reset_oe(self, listItem=None): @@ -402,7 +403,7 @@ def reset_oe(self, listItem=None): open(self.LIBREELEC_RESET_FILE, 'a').close() oe.winOeMain.close() oe.xbmcm.waitForAbort(1) - subprocess.call(['/usr/bin/systemctl', '--no-block', 'reboot'], close_fds=True) + dbus_systemd.reboot() @log.log_function() def ask_sure_reset(self, part): @@ -493,7 +494,7 @@ def do_restore(self, listItem=None): if oe.reboot_counter(10, oe._(32371)) == 1: oe.winOeMain.close() oe.xbmcm.waitForAbort(1) - subprocess.call(['/usr/bin/systemctl', '--no-block', 'reboot'], close_fds=True) + dbus_systemd.reboot() else: log.log('User Abort!') oe.execute(f'rm -rf {self.RESTORE_DIR}') diff --git a/resources/lib/modules/updates.py b/resources/lib/modules/updates.py index b2c5b791c..f093c1885 100644 --- a/resources/lib/modules/updates.py +++ b/resources/lib/modules/updates.py @@ -22,7 +22,7 @@ import datetime import tempfile from functools import cmp_to_key - +import dbus_systemd class updates(modules.Module): ENABLED = False @@ -502,7 +502,7 @@ def do_autoupdate(self, listItem=None, silent=False): if silent == False: oe.winOeMain.close() oe.xbmcm.waitForAbort(1) - subprocess.call(['/usr/bin/systemctl', '--no-block', 'reboot'], close_fds=True) + dbus_systemd.reboot() else: delattr(self, 'update_in_progress') diff --git a/resources/lib/oe.py b/resources/lib/oe.py index 96877b3e9..c30bf6aa4 100644 --- a/resources/lib/oe.py +++ b/resources/lib/oe.py @@ -21,6 +21,7 @@ import defaults import shutil import hashlib, binascii +import dbus_systemd from xml.dom import minidom import imp @@ -422,7 +423,7 @@ def set_service(service, options, state): if not __oe__.is_service: if service in defaults._services: for svc in defaults._services[service]: - execute(f'systemctl restart {svc}') + dbus_systemd.restart_unit(svc) dbg_log('oe::set_service', 'exit_function', LOGDEBUG) except Exception as e: dbg_log('oe::set_service', f'ERROR: ({repr(e)})')