clipmenu

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

commit 9c7f1b9bf3697ac72c5ae0c7ab0d7207f88d1520
parent 53215efd838aa0bbb1c2c9092fa8638e7580c897
Author: Chris Down <chris@chrisdown.name>
Date:   Wed, 14 Oct 2020 12:54:26 +0100

clipmenud: Don't assume that we're the process group leader

We usually are, but this is more robust in light of #139.

Diffstat:
Mclipmenud | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/clipmenud b/clipmenud @@ -79,6 +79,18 @@ sig_enable() { _CM_DISABLED=0 } +kill_background_jobs() { + # While we usually _are_, there are no guarantees that we're the process + # group leader. As such, all we can do is look at the pending jobs. Bash + # avoids a subshell here, so the job list is in the right shell. + local bg + bg=$(jobs -p) + + # Don't log `kill' failures, since with KillMode=control-group, we're + # racing with init. + [[ $bg ]] && kill -- "$bg" 2>/dev/null +} + if [[ $1 == --help ]] || [[ $1 == -h ]]; then cat << 'EOF' clipmenud collects and caches what's on the clipboard. You can manage its @@ -120,9 +132,7 @@ exec {lock_fd}> "$lock_file" trap sig_disable USR1 trap sig_enable USR2 - -# Kill all background processes on exit -trap 'trap - TERM; kill -- -$$' INT TERM EXIT +trap 'trap - INT TERM EXIT; kill_background_jobs; exit 0' INT TERM EXIT while true; do if ! (( CM_ONESHOT )); then