From 5f87974748f5b84a9e61d933a72bf6c55d0fecbc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 4 Mar 2022 16:04:47 +0100 Subject: [remoteaccess] Delay submission of VNC password to avoid race If for some reason the ~poweron POST arrives/gets processed later on the server than our VNC data submission, the password would get set to NULL again immediately, making this client inaccessible. --- .../data/etc/X11/Xsetup.d/50-launch-vncserver | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'core/modules/remote-access') diff --git a/core/modules/remote-access/data/etc/X11/Xsetup.d/50-launch-vncserver b/core/modules/remote-access/data/etc/X11/Xsetup.d/50-launch-vncserver index 4449a0fa..ae48a87f 100755 --- a/core/modules/remote-access/data/etc/X11/Xsetup.d/50-launch-vncserver +++ b/core/modules/remote-access/data/etc/X11/Xsetup.d/50-launch-vncserver @@ -29,11 +29,6 @@ # dd since busybox head doesn't know -c passwd="$( < /dev/urandom tr -c -d 'a-zA-Z0-9#&/=()[]{}' | dd bs=8 count=1 status=none )" printf "%s" "$passwd" > "/tmp/vnc-passwd" - url="http://${SLX_PXE_SERVER_IP}/slx-admin/api.php?do=remoteaccess" - curl -s -S -L --retry 4 --retry-connrefused --max-time 3 --retry-max-time 10 \ - --data-urlencode "password=$passwd" \ - --data-urlencode "vncport=$vnc_port" \ - "$url" > /dev/null ( # Make a copy of xauth, so if the xserver restarts, we'll use the old one and fail to connect if [ -n "$XAUTHORITY" ]; then @@ -60,6 +55,17 @@ done ) &> "/tmp/x11vnc-log-$$" & vncpid=$! + # Delay this a bit until x11vnc is ready, and since we might potentially have had a race + # with the ~poweron event, which would reset the password in the database. + ( + url="http://${SLX_PXE_SERVER_IP}/slx-admin/api.php?do=remoteaccess" + sleep 6 + [ -d "/proc/${vncpid}" ] || exit 1 # Something is wrong, bail + curl -s -S -L --retry 4 --retry-connrefused --max-time 3 --retry-max-time 10 \ + --data-urlencode "password=$passwd" \ + --data-urlencode "vncport=$vnc_port" \ + "$url" > /dev/null + ) & gotone=false vmvnc=false idle=0 -- cgit v1.2.3-55-g7522