From: Daan De Meyer Date: Fri, 13 Oct 2023 11:13:41 +0000 (+0200) Subject: Use os.access() in qemu support checks X-Git-Tag: v19~79^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e74988dfa45bd6c13bd732399942db07f26f3af;p=thirdparty%2Fmkosi.git Use os.access() in qemu support checks --- diff --git a/mkosi/util.py b/mkosi/util.py index 61ea4210f..dec893e1e 100644 --- a/mkosi/util.py +++ b/mkosi/util.py @@ -4,7 +4,6 @@ import ast import contextlib import copy import enum -import errno import fcntl import functools import importlib @@ -104,40 +103,33 @@ def chdir(directory: PathString) -> Iterator[None]: def qemu_check_kvm_support(log: bool) -> bool: # some CI runners may present a non-working KVM device - try: - os.close(os.open("/dev/kvm", os.O_RDWR|os.O_CLOEXEC)) - except OSError as e: - if e.errno == errno.ENOENT: - if log: - logging.warning("/dev/kvm not found. Not using KVM acceleration.") - return False - elif e.errno in (errno.EPERM, errno.EACCES): - if log: - logging.warning("Permission denied to access /dev/kvm. Not using KVM acceleration") - return False - - raise e + + if not os.access("/dev/kvm", os.F_OK): + if log: + logging.warning("/dev/kvm not found. Not using KVM acceleration.") + return False + + if not os.access("/dev/kvm", os.R_OK|os.W_OK): + if log: + logging.warning("Permission denied to access /dev/kvm. Not using KVM acceleration") + return False return True def qemu_check_vsock_support(log: bool) -> bool: - try: - os.close(os.open("/dev/vhost-vsock", os.O_RDWR|os.O_CLOEXEC)) - except OSError as e: - if e.errno == errno.ENOENT: - if log: - logging.warning("/dev/vhost-vsock not found. Not adding a vsock device to the virtual machine.") - return False - elif e.errno in (errno.EPERM, errno.EACCES): - if log: - logging.warning( - "Permission denied to access /dev/vhost-vsock. " - "Not adding a vsock device to the virtual machine." - ) - return False - - raise e + if not os.access("/dev/vhost-vsock", os.F_OK): + if log: + logging.warning("/dev/vhost-vsock not found. Not adding a vsock device to the virtual machine.") + return False + + if not os.access("/dev/vhost-vsock", os.R_OK|os.W_OK): + if log: + logging.warning( + "Permission denied to access /dev/vhost-vsock. " + "Not adding a vsock device to the virtual machine." + ) + return False return True