clipmenu

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

commit 7c34ace1fbab76eb1c1dc9b30dd4ac1a7fe4b90b
parent 0011a2c3b981157f7decc2eac2c3db4adc04f77d
Author: Chris Down <chris@chrisdown.name>
Date:   Wed, 14 Oct 2020 14:13:09 +0100

Merge branch 'release/6.2.0' into master

Diffstat:
MMakefile | 8+++-----
Mclipdel | 1+
Mclipmenud | 17++++++++++++++---
Minit/clipmenud.service | 5++++-
4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,14 +1,12 @@ # `dmenu` is not a hard dependency, but you need it unless # you plan to set CM_LAUNCHER to another value like `rofi` REQUIRED_BINS := xsel clipnotify +PREFIX ?= /usr $(foreach bin,$(REQUIRED_BINS),\ $(if $(shell command -v $(bin) 2> /dev/null),$(info Found `$(bin)`),$(error Missing Dep. Please install `$(bin)`))) .PHONY: install install: - install -D -m755 clipmenu /usr/bin/clipmenu - install -D -m755 clipmenud /usr/bin/clipmenud - install -D -m755 clipdel /usr/bin/clipdel - install -D -m755 clipctl /usr/bin/clipctl - install -D -m644 init/clipmenud.service /usr/lib/systemd/user/clipmenud.service + install --target "${PREFIX}/bin" -D -m755 clipmenu clipmenud clipdel clipctl + install -D -m644 init/clipmenud.service "${PREFIX}/lib/systemd/user/clipmenud.service" diff --git a/clipdel b/clipdel @@ -63,6 +63,7 @@ exec {lock_fd}> "$lock_file" if (( CM_REAL_DELETE )) && [[ "$raw_pattern" == ".*" ]]; then flock -x -w "$lock_timeout" "$lock_fd" || exit rm -rf -- "$cache_dir" + mkdir -p -- "$cache_dir" exit 0 else mapfile -t matches < <( 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 @@ -97,6 +109,7 @@ EOF exit 0 fi +[[ $DISPLAY ]] || die 2 'The X display is unset, is your X server running?' # It's ok that this only applies to the final directory. # shellcheck disable=SC2174 @@ -119,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 diff --git a/init/clipmenud.service b/init/clipmenud.service @@ -5,7 +5,6 @@ Description=Clipmenu daemon ExecStart=/usr/bin/clipmenud Restart=always RestartSec=500ms -Environment=DISPLAY=:0 MemoryDenyWriteExecute=yes NoNewPrivileges=yes @@ -14,5 +13,9 @@ ProtectKernelTunables=yes RestrictAddressFamilies= RestrictRealtime=yes +# We don't need to do any clean up, so if something hangs (borked xclip, etc), +# it's going to stay that way. Just forcefully kill and get it over with. +TimeoutStopSec=2 + [Install] WantedBy=default.target