weston-init: skip socket wait without a display

The previous socket wait fixed a race where the login prompt could appear
before Weston had created its Wayland socket. In that case, logging in as
root left WAYLAND_DISPLAY empty and applications could not use waylandsink.

Only wait for the socket when a DRM display is connected, or when the kernel
does not expose DRM connector status files. This keeps the race fix for
display boots while allowing immediate headless logins.
Keep showing a warning when there is no wayland socket.

https://onedigi.atlassian.net/browse/DEL-10141

Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
This commit is contained in:
Isaac Hermida 2026-05-19 17:34:12 +02:00
parent 6325cddb21
commit d9e2154ddc
1 changed files with 45 additions and 15 deletions

View File

@ -1,4 +1,38 @@
if [ "$USER" == "root" ]; then
find_wayland_display()
{
if [ -e "$XDG_RUNTIME_DIR/wayland-0" ]; then
export WAYLAND_DISPLAY=wayland-0
return 0
fi
if [ -e "$XDG_RUNTIME_DIR/wayland-1" ]; then
export WAYLAND_DISPLAY=wayland-1
return 0
fi
return 1
}
has_connected_drm_display()
{
local drm_status
local drm_status_found=false
local drm_state
for drm_status in /sys/class/drm/card*-*/status; do
[ -e "$drm_status" ] || continue
drm_status_found=true
read -r drm_state < "$drm_status" || continue
if [ "$drm_state" = "connected" ]; then
return 0
fi
done
[ "$drm_status_found" = "false" ]
}
if [ "$USER" = "root" ]; then
export XDG_RUNTIME_DIR=/run/user/`id -u root`
export ELM_ENGINE=wayland_shm
@ -8,20 +42,16 @@ if [ "$USER" == "root" ]; then
export PULSE_RUNTIME_PATH=/run/user/`id -u root`/pulse
export USE_PLAYBIN3=1
# Wait for 10 seconds until a Wayland socket is available
for i in {1..10}; do
if [ -e $XDG_RUNTIME_DIR/wayland-0 ]; then
export WAYLAND_DISPLAY=wayland-0
break
elif [ -e $XDG_RUNTIME_DIR/wayland-1 ]; then
export WAYLAND_DISPLAY=wayland-1
break
else
if ! find_wayland_display && has_connected_drm_display; then
# Weston may still be creating its socket after the login prompt
# appears, but do not delay headless serial logins.
for i in {1..10}; do
sleep 1
fi
done
if [ -z "$WAYLAND_DISPLAY" ]; then
echo "WARNING: No Wayland socket found"
find_wayland_display && break
done
fi
[ -z "$WAYLAND_DISPLAY" ] && echo "WARNING: No Wayland socket found"
fi
unset -f find_wayland_display
unset -f has_connected_drm_display