clipmenu

Simple clipboard management using dmenu
git clone https://git.sinitax.com/cdown/clipmenu
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 1cb46143f3ab460472f4646f9f98cf4c0640f376
parent 640e8a1fcf79053764742f5aa5e54c99e6f16ebb
Author: Chris Down <chris@chrisdown.name>
Date:   Wed,  1 May 2019 11:22:48 -0400

clipmenud: Add a sessionwide lock

Diffstat:
Mclipmenud | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/clipmenud b/clipmenud @@ -13,7 +13,12 @@ major_version=5 cache_dir=$CM_DIR/clipmenu.$major_version.$USER/ cache_file_prefix=$cache_dir/line_cache + +# lock_file is the lock for *one* iteration of clipboard capture/propagation. +# session_lock_file is the lock to prevent multiple clipmenud daemons from +# running at once. lock_file=$cache_dir/lock +session_lock_file=$cache_dir/session_lock lock_timeout=2 has_clipnotify=0 has_xdotool=0 @@ -104,6 +109,13 @@ fi # shellcheck disable=SC2174 mkdir -p -m0700 "$cache_dir" +exec {session_lock_fd}> "$session_lock_file" + +if ! flock -x -n "$session_lock_fd"; then + printf 'ERROR: %s\n' "Can't lock session file" + exit 2 +fi + declare -A last_data declare -A last_filename declare -A last_cache_file_output