X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/a2804841ed52f812b1d666cb3df01239ee906f5f..b67b4415c1aef525153cc156806ef7e41f38756c:/tools/__init__.py diff --git a/tools/__init__.py b/tools/__init__.py index df42752..819d54a 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -5,7 +5,9 @@ import sys import logging import os import traceback -import subprocess +import dbus.mainloop.glib +import dbus +import dbus.exceptions from . import actions from . import config @@ -22,7 +24,6 @@ def main(): # Wrap everything to display nice error messages args = None try: - os.umask(0o000) # Parse arguments, set up logging args = helpers.arguments() args.cache = {} @@ -32,28 +33,30 @@ def main(): args.sudo_timer = True args.timeout = 1800 - if not actions.initializer.is_initialized(args): - if args.action and (args.action not in ("init", "first-launch", "log")): - if not args.wait_for_init: - print('ERROR: WayDroid is not initialized, run "waydroid init"') - return 0 + if os.geteuid() == 0: + if not os.path.exists(args.work): + os.mkdir(args.work) + elif not os.path.exists(args.log): + args.log = "/tmp/tools.log" - print('WayDroid waiting for initialization...') - while helpers.ipc.listen(channel="init") != "done": - pass + tools_logging.init(args) - elif os.geteuid() == 0 and args.action == "init": - if not os.path.exists(args.work): - os.mkdir(args.work) - else: - # This branch is taken if: - # - waydroid is not yet initialized - # - waydroid is invoked with no command or with log - if not os.path.exists(args.log): - # The log could have been already created if init was used and failed, if its not the case we use a temporary one - args.log = "/tmp/tools.log" + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + dbus.mainloop.glib.threads_init() + dbus_name_scope = None - tools_logging.init(args) + if not actions.initializer.is_initialized(args) and \ + args.action and args.action not in ("init", "first-launch", "log"): + if args.wait_for_init: + try: + dbus_name_scope = dbus.service.BusName("id.waydro.Container", dbus.SystemBus(), do_not_queue=True) + actions.wait_for_init(args) + except dbus.exceptions.NameExistsException: + print('ERROR: WayDroid service is already awaiting initialization') + return 1 + else: + print('ERROR: WayDroid is not initialized, run "waydroid init"') + return 0 # Initialize or require config if args.action == "init": @@ -73,6 +76,12 @@ def main(): elif args.action == "container": actionNeedRoot(args.action) if args.subaction == "start": + if dbus_name_scope is None: + try: + dbus_name_scope = dbus.service.BusName("id.waydro.Container", dbus.SystemBus(), do_not_queue=True) + except dbus.exceptions.NameExistsException: + print('ERROR: WayDroid container service is already running') + return 1 actions.container_manager.start(args) elif args.subaction == "stop": actions.container_manager.stop(args) @@ -101,11 +110,9 @@ def main(): "Run waydroid {} -h for usage information.".format(args.action)) elif args.action == "prop": if args.subaction == "get": - ret = helpers.props.get(args, args.key) - if ret: - print(ret) + actions.prop.get(args) elif args.subaction == "set": - helpers.props.set(args, args.key, args.value) + actions.prop.set(args) else: logging.info( "Run waydroid {} -h for usage information.".format(args.action)) @@ -118,7 +125,7 @@ def main(): elif args.action == "show-full-ui": actions.app_manager.showFullUI(args) elif args.action == "first-launch": - subprocess.run(["pkexec", sys.argv[0], "init", "--gui"]) + actions.remote_init_client(args) if actions.initializer.is_initialized(args): actions.app_manager.showFullUI(args) elif args.action == "status":