From: Alessandro Astone Date: Wed, 4 Jan 2023 14:03:09 +0000 (+0100) Subject: lxc: Workaround against lxc changing logfile permissions X-Git-Tag: 1.4.0~55 X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/commitdiff_plain/fb92d3a016a956e8520e938b59f55bd0fe9c2deb lxc: Workaround against lxc changing logfile permissions Running lxc-start changes the permissions of stdout/stderr to 700. The previous workaround of changing the permissions back after lxc-status only worked because of the lxc-status loop in container_manager.start Make it more generic by applying it to every caller of helpers.lxc.start See: https://github.com/lxc/lxc/blob/6564e6ccb22e6e3c6cf36e6ae3cb5d5f73122486/src/lxc/utils.c#L1859 --- diff --git a/tools/actions/container_manager.py b/tools/actions/container_manager.py index e36cfbf..29ba552 100644 --- a/tools/actions/container_manager.py +++ b/tools/actions/container_manager.py @@ -165,17 +165,6 @@ def do_start(args, session): set_permissions(args) helpers.lxc.start(args) - lxc_status = helpers.lxc.status(args) - timeout = 10 - while lxc_status != "RUNNING" and timeout > 0: - lxc_status = helpers.lxc.status(args) - logging.info( - "waiting {} seconds for container to start...".format(timeout)) - timeout = timeout - 1 - time.sleep(1) - if lxc_status != "RUNNING": - raise OSError("container failed to start") - services.hardware_manager.start(args) def stop(args): diff --git a/tools/helpers/lxc.py b/tools/helpers/lxc.py index cac4bb5..0808d98 100644 --- a/tools/helpers/lxc.py +++ b/tools/helpers/lxc.py @@ -6,6 +6,7 @@ import re import logging import glob import shutil +import time import platform import gbinder import tools.config @@ -344,13 +345,27 @@ def setup_host_perms(args): def status(args): command = ["lxc-info", "-P", tools.config.defaults["lxc"], "-n", "waydroid", "-sH"] out = subprocess.run(command, stdout=subprocess.PIPE).stdout.decode('utf-8').strip() - os.chmod(args.log, 0o666) return out +def wait_for_running(args): + lxc_status = status(args) + timeout = 10 + while lxc_status != "RUNNING" and timeout > 0: + lxc_status = status(args) + logging.info( + "waiting {} seconds for container to start...".format(timeout)) + timeout = timeout - 1 + time.sleep(1) + if lxc_status != "RUNNING": + raise OSError("container failed to start") + def start(args): command = ["lxc-start", "-P", tools.config.defaults["lxc"], "-F", "-n", "waydroid", "--", "/init"] tools.helpers.run.user(args, command, output="background") + wait_for_running(args) + # Workaround lxc-start changing stdout/stderr permissions to 700 + os.chmod(args.log, 0o666) def stop(args): command = ["lxc-stop", "-P",