args.sudo_timer = True
args.timeout = 1800
- if not os.path.isfile(args.config):
+ if not actions.initializer.is_initialized(args):
if args.action and (args.action != "init" and args.action != "log"):
- print('ERROR: WayDroid is not initialized, run "waydroid init"')
- return 0
+ if not args.wait_for_init:
+ print('ERROR: WayDroid is not initialized, run "waydroid init"')
+ return 0
+
+ print('WayDroid waiting for initialization...')
+ while helpers.ipc.listen(channel="init") != "done":
+ pass
+
elif os.geteuid() == 0 and args.action == "init":
if not os.path.exists(args.work):
os.mkdir(args.work)
from tools import helpers
import tools.config
+def is_initialized(args):
+ return os.path.isfile(args.config) and os.path.isdir(tools.config.defaults["rootfs"])
def get_vendor_type(args):
vndk_str = helpers.props.host_get(args, "ro.vndk.version")
tools.config.save(args, cfg)
def init(args):
- if not os.path.isfile(args.config) or not os.path.isdir(tools.config.defaults["rootfs"]) or args.force:
+ if not is_initialized(args) or args.force:
setup_config(args)
status = "STOPPED"
if os.path.exists(tools.config.defaults["lxc"] + "/waydroid"):
logging.info("Starting container")
helpers.images.mount_rootfs(args, args.images_path)
helpers.lxc.start(args)
+
+ helpers.ipc.notify(channel="init", msg="done")
else:
logging.info("Already initialized")
import tools.helpers.drivers
import tools.helpers.mount
import tools.helpers.http
+import tools.helpers.ipc
" logfiles (this may reduce performance)")
parser.add_argument("-q", "--quiet", dest="quiet", action="store_true",
help="do not output any log messages")
+ parser.add_argument("-w", "--wait", dest="wait_for_init", action="store_true",
+ help="wait for init before running")
# Actions
sub = parser.add_subparsers(title="action", dest="action")
--- /dev/null
+# Copyright 2022 Alessandro Astone
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Currently implemented as FIFO
+import os
+
+BASE_DIR = "/var/run/"
+
+def listen(channel):
+ pipe = BASE_DIR + "waydroid-" + channel
+ if not os.path.exists(pipe):
+ os.mkfifo(pipe)
+ with open(pipe) as fifo:
+ while True:
+ data = fifo.read()
+ if len(data) != 0:
+ return data
+
+def notify(channel, msg):
+ pipe = BASE_DIR + "waydroid-" + channel
+ try:
+ fd = os.open(pipe, os.O_WRONLY | os.O_NONBLOCK)
+ with os.fdopen(fd, "w") as fifo:
+ fifo.write(msg)
+ except Exception:
+ pass