From 2c223d412e8dfcb89efaf715f1e1f657a8c7e509 Mon Sep 17 00:00:00 2001 From: Jami Kettunen Date: Sun, 15 Jan 2023 06:17:23 +0200 Subject: [PATCH] session: Add strict WAYLAND_DISPLAY validity checks 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 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/actions/session_manager.py b/tools/actions/session_manager.py index abb4f35..c1d4271 100644 --- a/tools/actions/session_manager.py +++ b/tools/actions/session_manager.py @@ -39,13 +39,30 @@ def start(args, unlocked_cb=None): 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"] = "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) + dpi = tools.helpers.props.host_get(args, "ro.sf.lcd_density") if dpi == "": dpi = os.getenv("GRID_UNIT_PX") -- 2.47.3