swaync-fbcli: fix so that the child actually exits when killed (critical is to use SIGINT)
This commit is contained in:
@@ -11,6 +11,8 @@ log() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
child=
|
||||||
|
|
||||||
# kill children if killed, to allow that killing this parent process will end the real fbcli call
|
# kill children if killed, to allow that killing this parent process will end the real fbcli call
|
||||||
cleanup() {
|
cleanup() {
|
||||||
log "aborting fbcli notification (PID $child)"
|
log "aborting fbcli notification (PID $child)"
|
||||||
@@ -18,6 +20,28 @@ cleanup() {
|
|||||||
exit 0 # exit cleanly to avoid swaync alerting a script failure
|
exit 0 # exit cleanly to avoid swaync alerting a script failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startInline() {
|
||||||
|
local timeout=
|
||||||
|
case "$event" in
|
||||||
|
phone-incoming-call)
|
||||||
|
timeout=20
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
fbcliArgs=(fbcli --event "$event")
|
||||||
|
if [ -n "$timeout" ]; then
|
||||||
|
fbcliArgs+=(-t "$timeout")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# feedbackd stops playback when the caller exits
|
||||||
|
# and fbcli will exit immediately if it has no stdin.
|
||||||
|
# so spoof a stdin.
|
||||||
|
log "${fbcliArgs[*]}"
|
||||||
|
sleep $((3 + ${timeout:+ + $timeout})) | ${fbcliArgs[@]}
|
||||||
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
# if in Do Not Disturb, don't do any feedback
|
# if in Do Not Disturb, don't do any feedback
|
||||||
# TODO: better solution is to actually make use of feedbackd profiles.
|
# TODO: better solution is to actually make use of feedbackd profiles.
|
||||||
@@ -28,34 +52,22 @@ start() {
|
|||||||
|
|
||||||
trap cleanup SIGINT SIGQUIT SIGTERM
|
trap cleanup SIGINT SIGQUIT SIGTERM
|
||||||
|
|
||||||
local timeout=
|
startInline &
|
||||||
case "$event" in
|
|
||||||
phone-incoming-call)
|
|
||||||
timeout=20
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
local cli="fbcli --event $event ${timeout:+ -t $timeout}"
|
|
||||||
|
|
||||||
# feedbackd stops playback when the caller exits
|
|
||||||
# and fbcli will exit immediately if it has no stdin.
|
|
||||||
# so spoof a stdin.
|
|
||||||
log "$cli"
|
|
||||||
/bin/sh -c "sleep $((3 ${timeout:+ + $timeout})) | $cli" &
|
|
||||||
child=$!
|
child=$!
|
||||||
wait
|
wait
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
pkill -e -f "swaync-fbcli(-wrapped)? start $event"
|
pkill --echo --signal SIGINT --full "swaync-fbcli(-wrapped)? start $event"
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
start)
|
start)
|
||||||
start
|
start
|
||||||
;;
|
;;
|
||||||
|
startInline)
|
||||||
|
startInline # support this for debugging
|
||||||
|
;;
|
||||||
stop)
|
stop)
|
||||||
stop
|
stop
|
||||||
;;
|
;;
|
||||||
|
Reference in New Issue
Block a user