]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
session: Add strict WAYLAND_DISPLAY validity checks
authorJami Kettunen <jami.kettunen@protonmail.com>
Sun, 15 Jan 2023 04:17:23 +0000 (06:17 +0200)
committerAlessandro Astone <ales.astone@gmail.com>
Sun, 15 Jan 2023 15:59:49 +0000 (16:59 +0100)
Enough with not checking we actually have a Wayland compositor around at
all: start requiring the WAYLAND_DISPLAY socket actually exists as an
absolute path or relatively under XDG_RUNTIME_DIR.

Additionally if WAYLAND_DISPLAY isn't an absolute path to the socket
(most setups) ensure XDG_RUNTIME_DIR is set and error with a typically
appropriate message.

tools/actions/session_manager.py

index abb4f35a080fee5edebbbab90ed823e493988751..c1d4271140a220c45169f23fcc64944c66466715 100644 (file)
@@ -39,13 +39,30 @@ def start(args, unlocked_cb=None):
             unlocked_cb()
         return
 
             unlocked_cb()
         return
 
-    session = copy.copy(tools.config.session_defaults);
+    session = copy.copy(tools.config.session_defaults)
+
+    # TODO: also support WAYLAND_SOCKET?
     wayland_display = session["wayland_display"]
     if wayland_display == "None" or not wayland_display:
         logging.warning('WAYLAND_DISPLAY is not set, defaulting to "wayland-0"')
     wayland_display = session["wayland_display"]
     if wayland_display == "None" or not wayland_display:
         logging.warning('WAYLAND_DISPLAY is not set, defaulting to "wayland-0"')
+        wayland_display = session["wayland_display"] = "wayland-0"
+
+    if os.path.isabs(wayland_display):
+        wayland_socket_path = wayland_display
+    else:
+        xdg_runtime_dir = session["xdg_runtime_dir"]
+        if xdg_runtime_dir == "None" or not xdg_runtime_dir:
+            logging.error(f"XDG_RUNTIME_DIR is not set; please don't start a Waydroid session with 'sudo'!")
+            sys.exit(1)
+        wayland_socket_path = os.path.join(xdg_runtime_dir, wayland_display)
+    if not os.path.exists(wayland_socket_path):
+        logging.error(f"Wayland socket '{wayland_socket_path}' doesn't exist; are you running a Wayland compositor?")
+        sys.exit(1)
+
     waydroid_data = session["waydroid_data"]
     if not os.path.isdir(waydroid_data):
         os.makedirs(waydroid_data)
     waydroid_data = session["waydroid_data"]
     if not os.path.isdir(waydroid_data):
         os.makedirs(waydroid_data)
+
     dpi = tools.helpers.props.host_get(args, "ro.sf.lcd_density")
     if dpi == "":
         dpi = os.getenv("GRID_UNIT_PX")
     dpi = tools.helpers.props.host_get(args, "ro.sf.lcd_density")
     if dpi == "":
         dpi = os.getenv("GRID_UNIT_PX")