Merge pull request #1865 from fewtarius/dev

Adds a bit of simple locking to settings management.
This commit is contained in:
fewtarius 2023-08-03 10:48:13 -04:00 committed by GitHub
commit 4429ba8ca9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,9 +9,22 @@ export SDL_GAMECONTROLLERCONFIG_FILE="/storage/.config/SDL-GameControllerDB/game
J_DIR="/storage/.config/system"
J_CONF="${J_DIR}/configs/system.cfg"
J_CONF_LOCK="/tmp/.system.cfg.lock"
ES_CONF="/storage/.emulationstation/es_settings.cfg"
JSLISTENCONF="${J_DIR}/configs/jslisten.cfg"
function tocon() {
echo -ne "\033[1000H\033[2K==> ${*}" >/dev/console
}
function log() {
SOURCE=${1//\/*\//}
MESSAGE=${*#${1}}
MESSAGE=${MESSAGE# }
logger -t ${SOURCE} "${MESSAGE}"
echo "$(date) ${SOURCE}: ${MESSAGE}" >>/var/log/messages
}
function get_setting() {
if [ ! -z "${3}" ]
then
@ -55,16 +68,33 @@ function get_setting() {
return
}
function wait_lock() {
while true
do
if (set -o noclobber; echo "$$" > "${J_CONF_LOCK}") 2>/dev/null
then
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
break
else
sleep 1
fi
done
}
function del_setting() {
wait_lock
if [[ "${1}" =~ ^[[:alnum:]] ]]
then
sed -i "/^${1}=/d" "${J_CONF}"
fi
rm -f "${J_CONF_LOCK}"
}
function sort_settings() {
wait_lock
cat "${J_CONF}" | grep ^[a-z0-9] | sort >"${J_CONF}.tmp"
mv "${J_CONF}.tmp" "${J_CONF}"
rm -f "${J_CONF_LOCK}"
}
function set_setting() {
@ -73,10 +103,11 @@ function set_setting() {
del_setting "${1}"
if [ ! "${2}" = "default" ]
then
wait_lock
echo "${1}=${2}" >> "${J_CONF}"
rm -f "${J_CONF_LOCK}"
fi
fi
sort_settings
}
function set_audio() {
@ -144,15 +175,3 @@ function get_aspect_ratio() {
esac
echo ${ASPECT}
}
function tocon() {
echo -ne "\033[1000H\033[2K==> ${*}" >/dev/console
}
function log() {
SOURCE=${1//\/*\//}
MESSAGE=${*#${1}}
MESSAGE=${MESSAGE# }
logger -t ${SOURCE} "${MESSAGE}"
echo "$(date) ${SOURCE}: ${MESSAGE}" >>/var/log/messages
}