Skip to content

Commit 494f36c

Browse files
committed
Fix resh-daemon-stop fallbacks
1 parent 30b254c commit 494f36c

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

scripts/resh-daemon-stop.sh

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
#!/usr/bin/env sh
2+
set -eu
23

3-
failed_to_kill() {
4-
[ "${1-}" != "-q" ] && echo "Failed to kill the RESH daemon - it probably isn't running"
5-
}
4+
q=0
5+
[ "${1-}" != "-q" ] || q=1
66

77
xdg_pid() {
88
local path="${XDG_DATA_HOME-}"/resh/daemon.pid
99
[ -n "${XDG_DATA_HOME-}" ] && [ -f "$path" ] || return 1
1010
cat "$path"
11+
rm "$path"
1112
}
1213
default_pid() {
1314
local path=~/.local/share/resh/daemon.pid
1415
[ -f "$path" ] || return 1
1516
cat "$path"
17+
rm "$path"
1618
}
17-
legacy_pid() {
18-
local path=~/.resh/resh.pid
19-
[ -f "$path" ] || return 1
20-
cat "$path"
21-
}
22-
pid=$(xdg_pid || default_pid || legacy_pid)
2319

24-
if [ -n "$pid" ]; then
25-
[ "${1-}" != "-q" ] && printf "Stopping RESH daemon ... (PID: %s)\n" "$pid"
26-
kill "$pid" || failed_to_kill
27-
else
28-
[ "${1-}" != "-q" ] && printf "Stopping RESH daemon ...\n"
29-
killall -q resh-daemon || failed_to_kill
30-
fi
20+
kill_by_pid() {
21+
[ -n "$1" ] || return 1
22+
[ "$q" = "1" ] || printf "Stopping RESH daemon ... (PID: %s)\n" "$1"
23+
kill "$1"
24+
}
25+
kill_by_name() {
26+
[ "$q" = "1" ] || printf "Stopping RESH daemon ...\n"
27+
killall -q resh-daemon
28+
}
29+
failed_to_kill() {
30+
[ "$q" = "1" ] || echo "Failed to kill the RESH daemon - it probably isn't running"
31+
return 1
32+
}
3133

34+
kill_by_pid "$(xdg_pid)" || kill_by_pid "$(default_pid)" || kill_by_name || failed_to_kill

0 commit comments

Comments
 (0)