weston-init: wait for a wayland socket before logging in

The login prompt appears before Wayland is fully initialized and
has created a wayland socket.

Logging in too early as root in this scenario caused the
WAYLAND_DISPLAY environment variable to be left empty. As a
consequence, gstreamer failed to use waylandsink to print contents
in the display.

Introduce a 10-seconds polling loop to wait for the wayland socket to
be available before proceeding with the login.

Signed-off-by: Gonzalo Ruiz <Gonzalo.Ruiz@digi.com>
This commit is contained in:
Gonzalo Ruiz 2025-06-19 10:59:04 +02:00
parent 5947b0cc9c
commit f3c9b3c57a
1 changed files with 15 additions and 6 deletions

View File

@ -8,11 +8,20 @@ if [ "$USER" == "root" ]; then
export PULSE_RUNTIME_PATH=/run/user/`id -u root`/pulse
export USE_PLAYBIN3=1
if [ -e $XDG_RUNTIME_DIR/wayland-0 ]; then
export WAYLAND_DISPLAY=wayland-0
else
if [ -e $XDG_RUNTIME_DIR/wayland-1 ]; then
export WAYLAND_DISPLAY=wayland-1
fi
# 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
sleep 1
fi
done
if [ -z "$WAYLAND_DISPLAY" ]; then
echo "WARNING: No Wayland socket found"
fi
fi