Skip to content

Commit

Permalink
remove mywatch(). Add makecookie()
Browse files Browse the repository at this point in the history
  • Loading branch information
mviereck committed Mar 3, 2019
1 parent 7c524da commit 00ee566
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions x11docker
Original file line number Diff line number Diff line change
Expand Up @@ -743,23 +743,6 @@ storepid () { # store pid $1 and name $2 of background process
verbose -d "Stored background pid ${1:-} of ${2:-}"
disown ${1:-} 2>/dev/null ||:
}
mywatch() { # repeat $1 untils its output changes
local Watchoutput=
Watchoutput="$(sh -c "${1:-}" 2>&1)"

verbose -d "Watching output of: sh -c \"'${1:-}'\" 2>&1
Current output:
$Watchoutput"

while rocknroll; do
[ "$Watchoutput" = "$(sh -c "${1:-}" 2>&1)" ] || break
sleep 1
done

verbose -d "Stopped watching output of: sh -c \"'${1:-}'\" 2>&1
Current output:
$(sh -c "${1:-}" 2>&1)"
}
checkpid() { # check if PID $1 is active
#ps -p ${1:-} >/dev/null 2>&1
[ -e "/proc/${1:-NONSENSE}" ]
Expand Down Expand Up @@ -834,6 +817,9 @@ download() { # download file at URL $1 and store it in file $
curl) curl -L "${1:-}" --output "${2:-}" ;;
esac
}
makecookie() { # bake a cookie
mcookie 2>/dev/null || echo $RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM | cut -b1-32
}

#### file routines
waitforfilecreation() { # similar to inotify-wait: wait up to 15s for file $1 to be created
Expand Down Expand Up @@ -1028,7 +1014,7 @@ getwslpath() { # get path to currently running WSL system

local RUN_ID= BASE_PATH=

RUN_ID="/tmp/$(mcookie)"
RUN_ID="/tmp/$(makecookie)"

# Mark our filesystem with a temporary file having an unique name.
touch "${RUN_ID}"
Expand Down Expand Up @@ -2929,7 +2915,7 @@ mode=$Screensize
# workaround as nxagent ignores XAUTHORITY and fails to start if option -auth is given. Option -ac above complies "xhost +" and is disabled in xinitrc
[ "$Xauthentication" = "yes" ] && {
$Mksu "cp '$Hostxauthority' '$Xservercookie'"
$Mksu "$Xauthexe -f '$Xclientcookie' add $Newdisplay . $(mcookie)"
$Mksu "$Xauthexe -f '$Xclientcookie' add $Newdisplay . $(makecookie)"
$Mksu "$Xauthexe -f '$Xclientcookie' nlist $Newdisplay | $Xauthexe -f '$Xservercookie' nmerge -"
}
# fake NXclient
Expand Down Expand Up @@ -3103,7 +3089,7 @@ create_xinitrc() { # create xinitrc: set up X environment, create c
echo " # still no cookie? try to create one without extension security"
echo " verbose -d 'Failed to retrieve trusted cookie from X server. Will bake one myself.'"
echo " echo 'Failed to retrieve trusted cookie from X server. Will bake one myself.'"
echo " $Xauthexe -v -i -f Xclientcookie add :$Newdisplaynumber . $(mcookie) | rmcr"
echo " $Xauthexe -v -i -f Xclientcookie add :$Newdisplaynumber . $(makecookie) | rmcr"
echo " ls -l $Xclientcookie"
echo "}"
echo "# create prepared cookie with localhost identification disabled by ffff, needed if X socket is shared. ffff means 'familiy wild'"
Expand Down Expand Up @@ -3982,7 +3968,7 @@ create_dockerrc() { # create dockerrc: This script runs as root (or
esac
echo "[ \"\$Dockerpull\" = 'yes' ] && {"
echo " note 'Pulling image $Imagename from docker hub'"
echo " notify-send 'x11docker: Pulling image $Imagename from docker hub' 2>/dev/null"
echo " env DISPLAY='$Hostdisplay' DBUS_SESSION_BUS_ADDRESS='$DBUS_SESSION_BUS_ADDRESS' su '$Hostuser' -c \"notify-send 'x11docker: Pulling image $Imagename from docker hub'\" 2>/dev/null"
echo " $Sudo $Dockerexe pull $Imagename 1>&2"
echo "}"
echo "$Dockerexe inspect --type=image $Imagename >>$Containerlogfile 2>&1 || {"
Expand Down Expand Up @@ -4958,7 +4944,9 @@ $(tail $Xpraserverlogfile)"
[ -n "$Xpraclientpid" ] && note "Restarting Xpra client."
$Mksu "env $Hostxenv XPRA_PADDING_COLORS='0,0.2,1' $Xpraclientcommand" >> $Xpraclientlogfile 2>&1 &
Xpraclientpid=$! && storepid $Xpraclientpid xpraclient
checkpid $Xpraclientpid && mywatch "ps -p $Xpraserverpid -o pid ; ps -p $Xpraclientpid -o pid #xpra"
checkpid $Xpraclientpid && {
while { checkpid $Xpraserverpid && checkpid $Xpraclientpid ; } do sleep 1 ; done
}
tail $Xpraserverlogfile | grep -q "client ping timeout" || saygoodbye xpraclient
done & storepid $! xpraloop
;;
Expand Down Expand Up @@ -6219,7 +6207,7 @@ declare_variables() { # declare global variables
Logmessages="" # stores messages until logfile is available, needed by logentry()
Logfile="" # x11docker.log

Mycookie=$(mcookie 2>/dev/null || echo $RANDOM | cut -b1-6) # random number used for container name and cache folder name
Mycookie=$(makecookie | cut -b1-6) # random number used for container name and cache folder name

# terminal colors used for messages and --verbose=c
Esc="$(printf '\033')"
Expand Down Expand Up @@ -6910,33 +6898,25 @@ main "$@"
#### ToDo notes for development
todo() {
# BUG --xpra-xwayland/py3 fails with tor-browser, but not with wine pcmanfm
# BUG notify-send in dockerrc does not show up
# BUG mywatch "ps -p $Xpraserverpid will fail on busybox systems
# BUG mcookie not available on play-with-docker

# BUG --dbus-system: slow startup (90s timeout) e.g. in arch and debian buster containers for unknown reasons.
# BUG --interactive with --systemd, --runit, --openrc, --sysvinit: no job control in shell

# BUG x11docker/deepin: new builds have strange issues
# BUG x11docker/fluxbox on arch host: background missing, sometimes no context menu. where is the difference?

# BUG error message window in wayland fails: xterm: no display. should use konsole
# BUG: x11docker/xwayland in a nested setup: where is the X socket ??

# Enhancement:
# --update: regard possible location in /opt
# x11docker-gui: menu entry management? persistant command storage?
# --group-add: further checks? mismatch messagebus-101-systemd-journal, works nonetheless.
# further checks of pam.d
# check multimonitor behaviour
# further checks of multimonitor behaviour

# MSYS2/Cygwin/WSL:
# needs test:
# --pulseaudio
# --wayland: Nested setup in WSL with weston might work if socket sharing succeeds:
# x11docker --stderr --exe -- x11docker --wayland x11docker/xfce xfce4-terminal
# not implemented, but maybe possible:
# --sharessh: socket sharing impossible, but maybe similar setup?
# --printer: CUPS not available, but lpr in Cygwin.
# impossible:
# --alsa
Expand Down

0 comments on commit 00ee566

Please sign in to comment.