]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/__init__.py
.desktop files should not be executable (#815)
[waydroid.git] / tools / __init__.py
index df427524901becd9d281269006948f4df45611e6..819d54ac9a177d401c5cf4bcdbcc8e5c3507ef37 100644 (file)
@@ -5,7 +5,9 @@ import sys
 import logging
 import os
 import traceback
 import logging
 import os
 import traceback
-import subprocess
+import dbus.mainloop.glib
+import dbus
+import dbus.exceptions
 
 from . import actions
 from . import config
 
 from . import actions
 from . import config
@@ -22,7 +24,6 @@ def main():
     # Wrap everything to display nice error messages
     args = None
     try:
     # Wrap everything to display nice error messages
     args = None
     try:
-        os.umask(0o000)
         # Parse arguments, set up logging
         args = helpers.arguments()
         args.cache = {}
         # Parse arguments, set up logging
         args = helpers.arguments()
         args.cache = {}
@@ -32,28 +33,30 @@ def main():
         args.sudo_timer = True
         args.timeout = 1800
 
         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":
 
         # 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":
         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)
                 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":
                     "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":
             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))
             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":
         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":
             if actions.initializer.is_initialized(args):
                 actions.app_manager.showFullUI(args)
         elif args.action == "status":