clipmenu

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

commit 5c53e5f1cde8aa0fd98ecbe3e6fd6cc3acd4d5f1
parent 74c479fa2fa09d1272c29b93e0528cd85d0c48e9
Author: Matthew White <mehw.is.me@inventati.org>
Date:   Thu, 18 Nov 2021 00:54:20 +0000

clipmenud: prevent another clipnotify job when trapping a signal

Since trapping a signal breaks `wait $_CM_CLIPNOTIFY_PID` w/o killing
the clipnotify job, call kill_background_jobs before restarting the
loop.  This prevents `clipctl enable` from spawning another job.

Diffstat:
Mclipmenud | 21+++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/clipmenud b/clipmenud @@ -58,9 +58,7 @@ debug() { (( CM_DEBUG )) && printf '%s\n' "$@" >&2; } sig_disable() { info "Received disable signal, suspending clipboard capture" _CM_DISABLED=1 - _CM_FIRST_DISABLE=1 echo "disabled" > "$status_file" - [[ -v _CM_CLIPNOTIFY_PID ]] && kill "$_CM_CLIPNOTIFY_PID" } sig_enable() { @@ -135,8 +133,8 @@ fi exec {lock_fd}> "$lock_file" -trap sig_disable USR1 -trap sig_enable USR2 +trap '_CM_TRAP=1; sig_disable' USR1 +trap '_CM_TRAP=1; sig_enable' USR2 trap 'trap - INT TERM EXIT; kill_background_jobs; exit 0' INT TERM EXIT while true; do @@ -147,13 +145,16 @@ while true; do wait "$_CM_CLIPNOTIFY_PID" fi + # Trapping a signal breaks the `wait` + if (( _CM_TRAP )); then + # Prevent spawning another clipnotify job restarting the loop + kill_background_jobs + unset _CM_TRAP + continue + fi + if (( _CM_DISABLED )); then - # The first one will just be from interrupting `wait`, so don't print - if (( _CM_FIRST_DISABLE )); then - unset _CM_FIRST_DISABLE - else - info "Got a clipboard notification, but we are disabled, skipping" - fi + info "Got a clipboard notification, but we are disabled, skipping" continue fi