Skip to content

Commit

Permalink
Update auto.md
Browse files Browse the repository at this point in the history
Explicitly delete the lock files before starting wsld following the nbdd0121@c3a2bb7 commit.

WSL2 never deletes the tmp directory - microsoft/WSL#6999
  • Loading branch information
codebymikey authored Nov 1, 2021
1 parent 8eed80c commit 3552857
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions docs/auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,35 @@ created task and clicking `Run`.
* Add this to your `~/.profile` or `~/.bash_profile` or `~/.zlogin`:

``` bash
export DISPLAY=:0

if ! pgrep wsld >> /dev/null 2>&1 ; then
function _wsl_x11_vsock() {
# https://github.com/nbdd0121/wsld/blob/master/docs/auto.md#on-wsl2
export DISPLAY=:0
if ! pgrep wsld >> /dev/null 2>&1 ; then
# https://github.com/nbdd0121/wsld/commit/c3a2bb7ccab8c11710fa6b49cf10434a80a853dd
# Delete lock files/directories.
rm -rf "/tmp/.X${DISPLAY/:/}-lock" "/tmp/.X11-unix/X${DISPLAY/:/}"
nohup wsld > /dev/null < /dev/null 2>&1 &
disown

# sleep until $DISPLAY is up
while ! xset q > /dev/null 2>&1 ; do
sleep 0.3
# sleep for N seconds until $DISPLAY is up
local START;
START=$(date +%s)
local CURRENT=$START
local WAIT=5
while [[ $((CURRENT - START)) -le "$WAIT" ]]; do
{ xset q > /dev/null 2>&1 && break; } || sleep 0.3;
CURRENT=$(date +%s)
done
fi
if [[ $((CURRENT - START)) -gt "$WAIT" ]]; then
echo >&2 "Please ensure that 'wsldhost.exe --daemon' and a X11 server is running on the Windows host."
# Kill the current instance so it can be re-initialized.
pkill wsld
fi
fi
}

# Initialize wsld
_wsl_x11_vsock
```

Using `xset q` to test the `$DISPLAY` makes it possible to run a command like `wsl.exe bash --login -c some-terminal`, otherwise `some-terminal` will fail because the `$DISPLAY` isn't ready yet.

0 comments on commit 3552857

Please sign in to comment.