From 5cd95016d9d0d8c90e4e586c4731d57fe3e6c338 Mon Sep 17 00:00:00 2001 From: Vincent-FK Date: Sat, 19 Jun 2021 00:14:04 +0200 Subject: [PATCH] corrected instant play that could only be launched once --- .../usr/local/sbin/instant_play | 19 ++++++++++--------- .../funkey/rootfs-overlay/usr/local/sbin/pid | 5 +++++ .../rootfs-overlay/usr/local/sbin/powerdown | 6 ++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/instant_play b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/instant_play index f4b3d86..43a5b4e 100755 --- a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/instant_play +++ b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/instant_play @@ -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 diff --git a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/pid b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/pid index 75533bd..19fca61 100755 --- a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/pid +++ b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/pid @@ -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 ;; diff --git a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/powerdown b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/powerdown index 067fc8a..8717ad2 100755 --- a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/powerdown +++ b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/powerdown @@ -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