corrected instant play that could only be launched once

This commit is contained in:
Vincent-FK 2021-06-19 00:14:04 +02:00
parent 305aa2ba83
commit 5cd95016d9
3 changed files with 21 additions and 9 deletions

View File

@ -7,6 +7,8 @@ SELF="$(basename ${0})"
INSTANT_PLAY_FILE="/mnt/instant_play"
RESUME_PLAY_FILE="/mnt/resume_play"
LAST_OPK_FILE="/mnt/last_opk"
PID_PATH="/var/run/pid_path"
REBOOTING_FILE="/run/rebooting"
usage() {
>&2 echo "Usage: ${SELF} load"
@ -50,7 +52,7 @@ load)
fi
# Unmount last OPK, if any
if [ -r "${LAST_OPK_FILE}" ]; then
if [ -r "${LAST_OPK_FILE}" -a ! -f "${REBOOTING_FILE}" ]; then
umount /opk
rm "${LAST_OPK_FILE}"
fi
@ -64,23 +66,22 @@ save)
# Write quick load file args
echo -n "" > "${INSTANT_PLAY_FILE}"
# First arg is prog name, forcing real path
printf "'" >> "${INSTANT_PLAY_FILE}"
bin_name=$(printf %s "$1" | sed "s/'/'\\\\''/g")
bin_path="$(pwd)"/"$(basename "$bin_name")"
# First arg is prog name, forcing real path
bin=$(printf %s "$1" | sed "s/'/'\\\\''/g")
bin_name=$(basename "$bin")
bin_path="$(cat $PID_PATH)"/"$bin_name"
echo -n "$bin_path" >> "${INSTANT_PLAY_FILE}"
shift
printf "' " >> "${INSTANT_PLAY_FILE}"
shift
while :
while [ "$#" != "0" ]
do
printf "'" >> "${INSTANT_PLAY_FILE}"
printf %s "$1" | sed "s/'/'\\\\''/g" >> "${INSTANT_PLAY_FILE}"
shift
case $# in 0) break; esac
printf "' " >> "${INSTANT_PLAY_FILE}"
shift
done
printf "'\n" >> "${INSTANT_PLAY_FILE}"
# Add the magic sauce to launch the process in background,
# record the PID into a file, wait for the process to

View File

@ -9,6 +9,7 @@ PID_FILE="/var/run/funkey.pid"
usage() {
>&2 echo "Usage: ${SELF} record pid"
>&2 echo " ${SELF} erase"
>&2 echo " ${SELF} print"
exit 1
}
@ -40,6 +41,10 @@ case "${1}" in
erase_pid
;;
print)
cat "${PID_FILE}"
;;
*)
usage
;;

View File

@ -5,6 +5,7 @@
SELF="$(basename ${0})"
PID_FILE="/var/run/funkey.pid"
PID_PATH="/var/run/pid_path"
REBOOTING_FILE="/run/rebooting"
usage() {
@ -16,6 +17,11 @@ usage() {
schedule_powerdown() {
# Save current pid path before closing bin
# (won't work if bin is already closed)
pid_path=$(dirname $(readlink /proc/$(pid print)/exe))
echo -n "$pid_path" > "$PID_PATH"
# Send USR1 signal to the running FunKey process to warn about
# impending shutdown
pkill -USR1 -F "${PID_FILE}" > /dev/null 2>&1