From 2a94d4abda15301d62a3cd24a5d336e51f6cfb6a Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Sun, 13 Nov 2022 14:44:49 -0800 Subject: [PATCH 1/2] Fix cpu count on macOS. Fixes the following error observed on macOS hosts: Traceback (most recent call last): File "/Users/nick/Code/python/boot-utils/boot-qemu.py", line 724, in cfg = setup_cfg(args) File "/Users/nick/Code/python/boot-utils/boot-qemu.py", line 242, in setup_cfg "smp_value": get_smp_value(args), File "/Users/nick/Code/python/boot-utils/boot-qemu.py", line 198, in get_smp_value usable_cpus = len(os.sched_getaffinity(0)) AttributeError: module 'os' has no attribute 'sched_getaffinity' The issue is that the `os` module in python does not have a `sched_getaffinity` method on macOS. Signed-off-by: Nick Desaulniers --- boot-qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot-qemu.py b/boot-qemu.py index 63b77ec..c8edec1 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -195,7 +195,7 @@ def get_smp_value(args): # Use the minimum of the number of usable processors for the script or # CONFIG_NR_CPUS. - usable_cpus = len(os.sched_getaffinity(0)) + usable_cpus = os.cpu_count() return min(usable_cpus, config_nr_cpus) From c5b96f81e432cd8c6ef7ea717a54fda4d44ea51f Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Sun, 13 Nov 2022 14:52:08 -0800 Subject: [PATCH 2/2] ignore unicode decode errors on macOS Fixes the following observed exceptions: Traceback (most recent call last): File "/Users/nick/Code/python/boot-utils/boot-qemu.py", line 725, in cfg = get_qemu_args(cfg) File "/Users/nick/Code/python/boot-utils/boot-qemu.py", line 451, in get_qemu_args linux_ver_code = get_linux_ver_code(gzip_kernel_cmd) File "/Users/nick/Code/python/boot-utils/boot-qemu.py", line 329, in get_linux_ver_code for line in strings.stdout.decode("UTF-8").split("\n"): UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfa in position 3: invalid start byte I'm not sure precisely why we get non-utf8-decodable bytes from Apple strings command. Signed-off-by: Nick Desaulniers --- boot-qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot-qemu.py b/boot-qemu.py index c8edec1..187d9f2 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -326,7 +326,7 @@ def get_linux_ver_code(decomp_cmd): input=decomp.stdout) linux_version = None - for line in strings.stdout.decode("UTF-8").split("\n"): + for line in strings.stdout.decode("UTF-8", "ignore").split("\n"): if re.search(r"Linux version \d+\.\d+\.\d+", line): linux_version = re.search(r"\d+\.\d+\.\d+", line)[0].split(".") break