X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/7046fb2fd32b73fde5642187c914c2f637e666b1..2fa63fdef4ed773f30b5166662fb5bc7ca87d8df:/tools/helpers/lxc.py diff --git a/tools/helpers/lxc.py b/tools/helpers/lxc.py index a13f838..19a7ceb 100644 --- a/tools/helpers/lxc.py +++ b/tools/helpers/lxc.py @@ -91,6 +91,8 @@ def generate_nodes_lxc_config(args): # Recursive mount /run to provide necessary host sockets make_entry("/run", options="rbind,create=dir 0 0") + # And /dev/shm + make_entry("/dev/shm", options="rbind,create=dir,optional 0 0") # Necessary sw_sync node for HWC make_entry("/dev/sw_sync") @@ -127,26 +129,49 @@ def generate_nodes_lxc_config(args): return nodes +LXC_APPARMOR_PROFILE = "lxc-waydroid" +def get_apparmor_status(args): + enabled = False + if shutil.which("aa-status"): + enabled = (tools.helpers.run.user(args, ["aa-status", "--quiet"], check=False) == 0) + if not enabled and shutil.which("systemctl"): + enabled = (tools.helpers.run.user(args, ["systemctl", "is-active", "-q", "apparmor"], check=False) == 0) + try: + with open("/sys/kernel/security/apparmor/profiles", "r") as f: + enabled &= (LXC_APPARMOR_PROFILE in f.read()) + except: + enabled = False + return enabled def set_lxc_config(args): lxc_path = tools.config.defaults["lxc"] + "/waydroid" - config_file = "config_2" lxc_ver = get_lxc_version(args) if lxc_ver == 0: raise OSError("LXC is not installed") - elif lxc_ver <= 2: - config_file = "config_1" - config_path = tools.config.tools_src + "/data/configs/" + config_file + config_paths = tools.config.tools_src + "/data/configs/config_" seccomp_profile = tools.config.tools_src + "/data/configs/waydroid.seccomp" + config_snippets = [ config_paths + "base" ] + # lxc v1 and v2 are bit special because some options got renamed later + if lxc_ver <= 2: + config_snippets.append(config_paths + "1") + else: + for ver in range(3, 5): + snippet = config_paths + str(ver) + if lxc_ver >= ver and os.path.exists(snippet): + config_snippets.append(snippet) + command = ["mkdir", "-p", lxc_path] tools.helpers.run.user(args, command) - command = ["cp", "-fpr", config_path, lxc_path + "/config"] + command = ["sh", "-c", "cat {} > \"{}\"".format(' '.join('"{0}"'.format(w) for w in config_snippets), lxc_path + "/config")] tools.helpers.run.user(args, command) command = ["sed", "-i", "s/LXCARCH/{}/".format(platform.machine()), lxc_path + "/config"] tools.helpers.run.user(args, command) command = ["cp", "-fpr", seccomp_profile, lxc_path + "/waydroid.seccomp"] tools.helpers.run.user(args, command) + if get_apparmor_status(args): + command = ["sed", "-i", "-E", "/lxc.aa_profile|lxc.apparmor.profile/ s/unconfined/{}/g".format(LXC_APPARMOR_PROFILE), lxc_path + "/config"] + tools.helpers.run.user(args, command) nodes = generate_nodes_lxc_config(args) config_nodes_tmp_path = args.work + "/config_nodes" @@ -243,10 +268,10 @@ def make_base_props(args): opengles = tools.helpers.props.host_get(args, "ro.opengles.version") if opengles == "": - opengles = "196608" + opengles = "196609" props.append("ro.opengles.version=" + opengles) - if args.images_path != tools.config.defaults["preinstalled_images_path"]: + if args.images_path not in tools.config.defaults["preinstalled_images_paths"]: props.append("waydroid.system_ota=" + args.system_ota) props.append("waydroid.vendor_ota=" + args.vendor_ota) else: @@ -348,7 +373,7 @@ def shell(args): command = ["lxc-attach", "-P", tools.config.defaults["lxc"], "-n", "waydroid", "--"] if args.COMMAND: - command.append(args.COMMAND) + command.extend(args.COMMAND) else: command.append("/system/bin/sh") subprocess.run(command, env={"PATH": os.environ['PATH'] + ":/system/bin:/vendor/bin"})