fix(wrapper.sh): Tried to improve safety
This commit is contained in:
parent
c8a195f5f0
commit
6c6919550b
@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#set -eux
|
||||||
|
set -eu
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
[ $# -eq 0 ] && {
|
[ $# -eq 0 ] && {
|
||||||
echo "No bar specified" ; exit 1
|
echo "No bar specified" ; exit 1
|
||||||
@ -22,17 +26,23 @@ pipe="$(mktemp -u /tmp/lemonbuddy.in.XXXXX)"
|
|||||||
|
|
||||||
mkfifo "$pipe"
|
mkfifo "$pipe"
|
||||||
|
|
||||||
# shellcheck disable=SC2094
|
cleanup_proc() {
|
||||||
lemonbuddy "$@" -p "$pipe" 2>"$logfile" | $lemonbar >"$pipe" & pid=$!
|
pid=$1
|
||||||
|
kill -0 "$pid" 2>/dev/null && {
|
||||||
sigaction() {
|
echo "$pid is running (sending term signal)..."
|
||||||
printf "\r"
|
kill -TERM "$pid"
|
||||||
kill -TERM $pid 2>/dev/null
|
}
|
||||||
echo "Waiting for processes to terminate..."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trap sigaction TERM INT PIPE CHLD
|
# shellcheck disable=SC2094
|
||||||
|
{ lemonbuddy "$@" -p "$pipe" 2>"$logfile"; kill -TERM $$; } | $lemonbar >"$pipe" &
|
||||||
|
|
||||||
while true; do
|
trap 'cleanup_proc $!' TERM INT
|
||||||
wait || break
|
|
||||||
|
while kill -0 $! 2>/dev/null; do
|
||||||
|
sleep 0.5s
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[ -e "$pipe" ] && rm "$pipe"
|
||||||
|
|
||||||
|
kill 0; wait
|
||||||
|
Loading…
Reference in New Issue
Block a user