Skip to content

Commit

Permalink
qvm-start-daemon: make pylint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed Apr 23, 2024
1 parent 38e8c83 commit 6acebbf
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions qubesadmin/tools/qvm_start_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import qubesadmin.exc
import qubesadmin.tools
import qubesadmin.vm
import qubesadmin.tools.xcffibhelpers as xcffibhelpers
from qubesadmin.tools import xcffibhelpers

GUI_DAEMON_PATH = '/usr/bin/qubes-guid'
PACAT_DAEMON_PATH = '/usr/bin/pacat-simple-vchan'
Expand All @@ -55,7 +55,8 @@
('startup_timeout', 'int'),
]

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -129,7 +130,7 @@ def retrieve_gui_daemon_options(vm, guivm):

def serialize_gui_daemon_options(options):
'''
Prepare configuration file content for GUI daemon. Currently uses libconfig
Prepare configuration file content for GUI daemon. Currently, uses libconfig
format.
'''

Expand Down Expand Up @@ -637,7 +638,7 @@ async def start_audio(self, vm):
if not os.path.exists(self.pacat_pidfile(xid)):
await self.start_audio_for_vm(vm)
else:
vm.log.info('AUDIO process exists. Skipping.'.format(audiovm))
vm.log.info('AUDIO process exists. Skipping.')

def on_domain_spawn(self, vm, _event, **kwargs):
"""Handler of 'domain-spawn' event, starts GUI daemon for stubdomain"""
Expand Down Expand Up @@ -732,12 +733,12 @@ def on_domain_stopped(self, vm, _event, **_kwargs):
self.cleanup_pacat_process(stubdom_xid)

def on_property_audiovm_set(self, vm, _event, **_kwargs):
log.debug(f"{vm} - {_event} - {_kwargs}")
"""Handler for catching event related to dynamic AudioVM set/unset"""
if vm.name not in self.xid_cache:
try:
self.xid_cache[vm.name] = vm.xid, vm.stubdom_xid
except qubesadmin.exc.QubesDaemonAccessError as e:
log.error(f"vm.name: failed to determine XID: {str(e)}")
log.error("vm.name: failed to determine XID: %s", str(e))
return
xid, stubdom_xid = self.xid_cache[vm.name]
oldvalue = _kwargs.get("oldvalue", None)
Expand Down Expand Up @@ -778,12 +779,14 @@ def cleanup_pacat_process(self, xid):
if not os.path.exists(config_file):
return
try:
with open(config_file) as f:
pid = int(f.readline())
with open(config_file, encoding="ascii") as fd:
pid = int(fd.readline())
os.kill(pid, signal.SIGTERM)
log.info(f"Sent SIGTERM signal to pacat-simple-vchan process {pid}")
log.info(
"Sent SIGTERM signal to pacat-simple-vchan process %d", pid)
except OSError:
log.error(f"Failed to send SIGTERM signal for the pacat-simple-vchan with xid of {xid}")
log.error("Failed to send SIGTERM signal for the"
" pacat-simple-vchan with xid of %d", xid)
os.unlink(config_file)

def register_events(self, events):
Expand All @@ -794,9 +797,9 @@ def register_events(self, events):
self.on_connection_established)
events.add_handler('domain-stopped', self.on_domain_stopped)

events.add_handler("property-set:audiovm", self.on_property_audiovm_set)
events.add_handler("property-pre-set:audiovm", self.on_property_audiovm_set)
events.add_handler("property-pre-del:audiovm", self.on_property_audiovm_set)
for event in ["property-set:audiovm", "property-pre-set:audiovm",
"property-pre-del:audiovm"]:
events.add_handler(event, self.on_property_audiovm_set)

def is_watched(self, vm):
"""
Expand Down Expand Up @@ -849,7 +852,8 @@ def main():
for qube in launcher.app.domains:
if qube.name == "dom0":
continue
launcher.on_connection_established(qube, _event="connection-established")
launcher.on_connection_established(
qube, _event="connection-established")

fd = os.open(
args.pidfile,
Expand All @@ -864,7 +868,8 @@ def main():
pid = int(lock_f.read().strip())
except ValueError:
pid = 'unknown'
log.error(f'Another daemon launcher process (with PID {pid}) is already running')
log.error('Another daemon launcher process (with PID %d)'
' is already running', pid)
sys.exit(1)
print(os.getpid(), file=lock_f)
lock_f.flush()
Expand Down

0 comments on commit 6acebbf

Please sign in to comment.