Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

X: finally fixed it with flock

  • Loading branch information...
commit 04b23bc6c5595e575f876373f749927ed8baaf7f 1 parent 66c823b
@meh meh authored
Showing with 22 additions and 14 deletions.
  1. +22 −14 X/init.zsh
View
36 X/init.zsh
@@ -10,19 +10,30 @@ if [[ -z "$XAUTHORITY" ]]; then
export XAUTHORITY="$HOME/.Xauthority"
fi
-if [[ -e "$(path:cache)/X.lock" ]]; then
- return
-fi
+# I wish this wasn't required ( ͡° ͜ʖ ͡°)
+function {
+ integer fd
+ integer ret=0
+
+ exec {fd}>!"$(path:cache)/X.lock"
+
+ if flock -nx $fd; then
+ 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
+ ret=1
+ fi
+ else
+ ret=1
+ fi
-touch "$(path:cache)/X.lock"
+ exec {fd}>&-
-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
+ return $ret
+} || return
(function {
if zstyle -t ':zoppo:plugin:X:screen' saver; then
@@ -79,9 +90,6 @@ 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={{{,}}}
Please sign in to comment.
Something went wrong with that request. Please try again.