config: specify dom0 services path

This commit is contained in:
Frédéric Pierret (fepitre) 2020-02-18 11:44:57 +01:00
parent a7e7166f7a
commit 0b8e5400a3
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2
2 changed files with 14 additions and 7 deletions

View File

@ -44,6 +44,8 @@ system_path = {
# qubes_icon_dir is obsolete # qubes_icon_dir is obsolete
# use QIcon.fromTheme() where applicable # use QIcon.fromTheme() where applicable
'qubes_icon_dir': '/usr/share/icons/hicolor/128x128/devices', 'qubes_icon_dir': '/usr/share/icons/hicolor/128x128/devices',
'dom0_services_dir': '/var/lib/qubes-services',
} }
defaults = { defaults = {

View File

@ -22,6 +22,9 @@
import os import os
import qubes.ext import qubes.ext
import qubes.config
dom0_services_dir = qubes.config.system_path['dom0_services_dir']
class ServicesExtension(qubes.ext.Extension): class ServicesExtension(qubes.ext.Extension):
@ -32,19 +35,21 @@ class ServicesExtension(qubes.ext.Extension):
@staticmethod @staticmethod
def add_dom0_services(vm, service): def add_dom0_services(vm, service):
try: try:
os.makedirs('/var/run/qubes-service/', exist_ok=True) os.makedirs(dom0_services_dir, exist_ok=True)
if not os.path.exists('/var/run/qubes-service/{}'.format(service)): service = '{}/{}'.format(dom0_services_dir, service)
os.mknod('/var/run/qubes-service/{}'.format(service)) if not os.path.exists(service):
os.mknod(service)
except PermissionError: except PermissionError:
vm.log.warning("Cannot write to /var/run/qubes-service") vm.log.warning("Cannot write to {}".format(dom0_services_dir))
@staticmethod @staticmethod
def remove_dom0_services(vm, service): def remove_dom0_services(vm, service):
try: try:
if os.path.exists('/var/run/qubes-service/{}'.format(service)): service = '{}/{}'.format(dom0_services_dir, service)
os.remove('/var/run/qubes-service/{}'.format(service)) if os.path.exists(service):
os.remove(service)
except PermissionError: except PermissionError:
vm.log.warning("Cannot write to /var/run/qubes-service") vm.log.warning("Cannot write to {}".format(dom0_services_dir))
# pylint: disable=no-self-use # pylint: disable=no-self-use
@qubes.ext.handler('domain-qdb-create') @qubes.ext.handler('domain-qdb-create')