Skip to content

Commit 0786eab

Browse files
committed
joy2key: refactor stop action
Modified the 'stop' action to use `start-stop-daemon` [1] instead of a simple `pkill`. The advantage is that we don't need to use `sleep` to ensure the script is stopped, since `start-stop-daemon` monitors the process and will exit when is stopped. The `retry` action is to send a SIGKILL after 1 second, to ensure the process is stopped. The modification will shorten the time it takes to 'stop' the joystick handling utility, since we don't have to wait - unconditionally - for 1 sec every stop. This will shorten the runtime of `runcommand` . [1] https://man7.org/linux/man-pages/man8/start-stop-daemon.8.html. Since it's part of `dpkg`, it's basically present on every Debian based system.
1 parent ae10c36 commit 0786eab

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

scriptmodules/admin/joy2key.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ case "\$mode" in
7070
"$md_inst/\$script" "\$device" "\${params[@]}" || exit 1
7171
;;
7272
stop)
73-
pkill -f "\$script"
74-
sleep 1
73+
if pid=\$(pgrep -f "\$script"); then
74+
/sbin/start-stop-daemon --stop --oknodo --pid \$pid --retry 1
75+
fi
7576
;;
7677
esac
7778
exit 0

0 commit comments

Comments
 (0)