Permalink
Browse files

X: try to fix concurrency issues again

  • Loading branch information...
1 parent 9ed7e86 commit 60344adc29e475a39b58db900e992ba6a243f598 @meh meh committed Nov 21, 2012
Showing with 17 additions and 12 deletions.
  1. +17 −12 X/init.zsh
View
@@ -10,19 +10,21 @@ if [[ -z "$XAUTHORITY" ]]; then
export XAUTHORITY="$HOME/.Xauthority"
fi
-(function {
- # this is required so we don't clash with other concurrently opened shells
- sleep $(( (RANDOM % 10) / 100.0 ))
-
- if [[ ! -e "$(path:cache)/X" ]] || \
- [[ "${ZDOTDIR:-$HOME}/.zopporc" -nt "$(path:cache)/X" ]] || \
- [[ '/tmp/.X11-unix/X0' -nt "$(path:cache)/X" ]] \
- then
- touch "$(path:cache)/X"
- else
- return
- fi
+if [[ -e "$(path:cache)/X.lock" ]]; then
+ return
+fi
+
+touch "$(path:cache)/X.lock"
+if ! ([[ ! -e "$(path:cache)/X" ]] || \
+ [[ "${ZDOTDIR:-$HOME}/.zopporc" -nt "$(path:cache)/X" ]] || \
+ [[ '/tmp/.X11-unix/X0' -nt "$(path:cache)/X" ]]) \
+then
+ rm -f "$(path:cache)/X.lock"
+ return
+fi
+
+(function {
if zstyle -t ':zoppo:plugin:X:screen' saver; then
xscreensaver &> /dev/null &!
elif zstyle -s ':zoppo:plugin:X:screen' saver saver; then
@@ -77,6 +79,9 @@ fi
unset idle
fi
+
+ rm -f "$(path:cache)/X.lock"
+ touch "$(path:cache)/X"
}) &!
# vim: ft=zsh sts=2 ts=2 sw=2 et fdm=marker fmr={{{,}}}

0 comments on commit 60344ad

Please sign in to comment.