Skip to content

Commit

Permalink
minor fixes: #165
Browse files Browse the repository at this point in the history
 - use wincmd instead of cmd.exe
 - use FDdockerstop only if declared
 - avoid xpraloop if not running xpra
 - storeinfo(): fix grep check
  • Loading branch information
mviereck committed Oct 31, 2019
1 parent 44eeee4 commit 1e183e0
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions x11docker
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,14 @@ finish() { # trap EXIT routine to clean up background proce
}

# Check if 'docker logs' is still running
checkpid $Dockerlogspid && echo "stop" >&${FDdockerstop}
# Check if window manager container is still running
checkpid $Wmcontainerpid1 && echo "stop" >&${FDdockerstop}
# Terminate watching subshell in dockerrc
[ -e "$Dockerstopsignalfifo" ] && echo "exit" >&${FDdockerstop}
checkpid $Dockerstopshellpid && sleep 1
[ "$FDdockerstop" ] && {
checkpid $Dockerlogspid && echo "stop" >&${FDdockerstop}
# Check if window manager container is still running
checkpid $Wmcontainerpid1 && echo "stop" >&${FDdockerstop}
# Terminate watching subshell in dockerrc
[ -e "$Dockerstopsignalfifo" ] && echo "exit" >&${FDdockerstop}
checkpid $Dockerstopshellpid && sleep 1
}

# Stop watching for messages, check others again
while read -r Line ; do
Expand Down Expand Up @@ -623,10 +625,10 @@ finish() { # trap EXIT routine to clean up background proce
for Descriptor in ${FDcmdstdin} ${FDdockerstop} ${FDmessage} ${FDstderr} ${FDtimetosaygoodbye} ${FDwatchpid} ; do
exec {Descriptor}>&-
done

# remove cache files
[ "$Preservecachefiles" = "no" ] && grep -q cache <<<$Cachefolder && grep -q x11docker <<<$Cachefolder && [ "x11docker" != "$(basename "$Cachefolder")" ] && unpriv "rm -f -R '$Cachefolder'"

case $Runssourced in
yes) return $Exitcode ;;
*) exit $Exitcode ;;
Expand Down Expand Up @@ -877,7 +879,7 @@ storeinfo() { # store some information for later use
test) grep -q "^${2:-}=" $Storeinfofile ;; # test for entry
*) # store entry
debugnote "storeinfo(): ${1:-}"
grep -q "/^$(echo "${1:-}" | cut -d= -f1)=" $Storeinfofile && {
grep -q "^$(echo "${1:-}" | cut -d= -f1)=" $Storeinfofile && {
sed -i "/^$(echo "${1:-}" | cut -d= -f1)=/d" $Storeinfofile # drop possible old entry
}
echo "${1:-}" >> $Storeinfofile
Expand Down Expand Up @@ -909,7 +911,7 @@ verlte() { # version number check $1 less than or equal $2
[ "${1:-}" = "$(echo -e "${1:-}\n${2:-}" | sort -V | head -n1)" ] && return 0 || return 1
}
wincmd() { # execute a command on MS Windows with cmd.exe
cmd /C "${@//&/^&}" 2>&1 | rmcr
MSYS2_ARG_CONV_EXCL='*' cmd /C "${@//&/^&}" 2>&1 | rmcr
}

#### file routines
Expand Down Expand Up @@ -3606,7 +3608,7 @@ check_containerhome() { # options --home, --homedir, --homebasedir: chec
}
[ "$Homebasefolder" ] || case $Winsubsystem in
"") Homebasefolder="$Containeruserhome/.local/share/x11docker" ;;
*) Homebasefolder="$(convertpath subsystem "$(wincmd '/C "echo %userprofile%"') ")/x11docker/home" ;;
*) Homebasefolder="$(convertpath subsystem "$(wincmd 'echo %userprofile%') ")/x11docker/home" ;;
esac

[ "$Sharehosthome" = "yes" ] && {
Expand Down Expand Up @@ -6839,7 +6841,8 @@ create_cachefiles() { # create empty cache files owned by unprivileged
#Cachebasefolder="$Hostuserhome/.cache/x11docker" ### FIXME really a good idea for MS Windows? WSL cache provides performance, but maybe must not be shared with container to avoid file access errors.
case $Winsubsystem in
""|MSYS2|CYGWIN) Cachebasefolder="$Hostuserhome/.cache/x11docker" ;;
WSL) Cachebasefolder="$(convertpath subsystem "$(cmd.exe /C "echo %userprofile%")" | rmcr)/x11docker/cache" ;;
# WSL) Cachebasefolder="$(convertpath subsystem "$(cmd.exe /C "echo %userprofile%")" | rmcr)/x11docker/cache" ;;
WSL) Cachebasefolder="$(convertpath subsystem "$(wincmd "echo %userprofile%")")/x11docker/cache" ;;
esac
}
[ "$Cachebasefolder" = "/x11docker/cache" ] && error "Failed to find a valid path for cache directory.
Expand Down Expand Up @@ -8324,10 +8327,12 @@ $(cat $Storepidfile)"
#### Start X server [and/or Wayland compositor] [and xpra]
waitforlogentry "start_xserver()" $Storeinfofile "readyforX=ready" infinity
[ "$Xpraservercommand" ] && {
waitforlogentry xpra $Storeinfofile "xinitrc=ready" infinity
rocknroll || exit 0
start_xpra # --xpra, --xpra-xwayland
} & storepid $! xpraloop
{
waitforlogentry xpra $Storeinfofile "xinitrc=ready" infinity
rocknroll || exit 0
start_xpra # --xpra, --xpra-xwayland
} & storepid $! xpraloop
}
rocknroll && [ "$Compositorcommand" ] && start_compositor
rocknroll && start_xserver

Expand Down

0 comments on commit 1e183e0

Please sign in to comment.