Skip to content

Commit

Permalink
MSYS2/Cygwin/WSL: watch container with 'docker inspect' instead of co…
Browse files Browse the repository at this point in the history
…ntainer PID (#55)
  • Loading branch information
mviereck committed Jul 31, 2018
1 parent f36d7c9 commit 1925f63
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions x11docker
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,17 @@ watchpidlist() { # watch list of important pids
# terminate x11docker if a PID in $Watchpidlist terminates
# serves mainly watching X server, Wayland compositor, container and hostexe
# echo PIDs to watch into >&9
local Pid=
local Pid= Containername=
while rocknroll ; do
read -t1 Pid <&9 ||:
[ "$Pid" ] && {
Watchpidlist="$Watchpidlist $Pid"
debugnote "Watching pids: $Watchpidlist"
[ "${Pid:0:9}" = "CONTAINER" ] && {
Containername=${Pid#CONTAINER}
debugnote "Watching Container: $Containername"
} || {
Watchpidlist="$Watchpidlist $Pid"
debugnote "Watching pids: $Watchpidlist"
}
} || sleep 2 # sleep for MSYS2/CYGWIN workaround
case $Winsubsystem in
""|WSL)
Expand All @@ -620,14 +625,20 @@ watchpidlist() { # watch list of important pids
}
done
;;
MSYS|CYGWIN)
MSYS2|CYGWIN)
for Pid in $Watchpidlist; do
ps -p $Pid --windows >/dev/null 2>&1 || {
debugnote "watchpidlist: PID $Pid has terminated"
saygoodbye "watchpidlist $Pid"
}
done;;
esac
[ "$Containername" ] && {
docker inspect $Containername >/dev/null 2>&1 || {
debugnote "watchpidlist: Container $Containername has terminated"
saygoodbye "watchpidlist $Containername"
}
}
done
saygoodbye "watchpidlist"
}
Expand Down Expand Up @@ -675,7 +686,7 @@ waitfortheend() { # wait for end of x11docker
bash -c "read -n1 -t1 <&8 ||:"
done
;;
MSYS|CYGWIN)
MSYS2|CYGWIN)
while rocknroll; do
sleep 2
done
Expand Down Expand Up @@ -1394,11 +1405,11 @@ Ttyinuse=""
Winsubsystem=""
Winsubmount=""
Winsubpath=""
[ "${MSYSTEM:-}" ] && Winsubsystem="MSYS"
[ "${MSYSTEM:-}" ] && Winsubsystem="MSYS2"
[ -d "/cygdrive" ] && Winsubsystem="CYGWIN"
grep -q "/mnt/c/Windows/System32" <<< ${PATH:-} && Winsubsystem="WSL"
case $Winsubsystem in
MSYS) Winsubpath="/c/msys64" ; Winsubmount="" ;;
MSYS2) Winsubpath="/c/msys64" ; Winsubmount="" ;;
CYGWIN) Winsubpath="/c/cygwin64" ; Winsubmount="/cygdrive" ;;
WSL) Winsubpath="FAILURE" ; Winsubmount="/mnt" ;;
esac
Expand Down Expand Up @@ -2181,8 +2192,8 @@ $(cowsay "$Wisdom" 2>/dev/null || echo "Wanda the fish says: $Wisdom")"
case $Xserver in
--vcxsrv)
case $Winsubsystem in
MSYS)
warning "Disabling X authentication for X server --vcxsrv in MSYS.
MSYS2)
warning "Disabling X authentication for X server --vcxsrv in MSYS2.
An upcoming release of VcXsrv will allow it."
Xauthentication="no"
;;
Expand Down Expand Up @@ -4106,7 +4117,7 @@ done
}

case $Winsubsystem in
MSYS|CYGWIN|WSL)
MSYS2|CYGWIN|WSL)
Watchpidfifo="$Cachefolder/$Watchpidfifo" && mkfile $Watchpidfifo
Messagefifo="$Sharefolder/$Messagefifo" && mkfile $Messagefifo && chmod 666 $Messagefifo
Timetosaygoodbyefifo="$Sharefolder/$Timetosaygoodbyefifo" && mkfile $Timetosaygoodbyefifo && chmod 666 $Timetosaygoodbyefifo
Expand Down Expand Up @@ -4890,7 +4901,7 @@ DefaultEnvironment=DISPLAY=$Newdisplay XAUTHORITY=$Cshare/Xclientcookie $(IFS=$'
}
#### run docker image ####
[ "$Winsubsystem" = "MSYS" ] && echo "export MSYS2_ARG_CONV_EXCL='*'"
[ "$Winsubsystem" = "MSYS2" ] && echo "export MSYS2_ARG_CONV_EXCL='*'"
echo "read Containerid < <($Dockercommand 2>>$Containerlogfile | rmcr)"
##########################
Expand Down Expand Up @@ -5977,6 +5988,9 @@ $(tail $Cmdstdoutlogfile)"
}
}
;;
*)
setonwatchpidlist CONTAINER$Containername
;;
esac
;;
Expand Down Expand Up @@ -6067,7 +6081,7 @@ $(tail $Compositorlogfile)"
$(tasklist.exe | rmcr | grep vcxsrv.exe | awk '{print $2}')"
$Mksu "exec env MSYS2_ARG_CONV_EXCL='*' $Xcommand 2>&1 | rmcr >> $Xinitlogfile &"
case $Winsubsystem in
MSYS|CYGWIN)
MSYS2|CYGWIN)
Tasklistnew="$Tasklistold
$(tasklist.exe | rmcr | grep vcxsrv.exe | awk '{print $2}')"
Xserverpid="$(cat <<<"$Tasklistnew" | rmcr | sort | uniq -u)"
Expand Down

0 comments on commit 1925f63

Please sign in to comment.