1
0
mirror of https://git.openwrt.org/openwrt/openwrt.git synced 2024-10-19 05:58:53 +02:00

procd: introduce procd_lock for init script protection

Use flock to protect init script from concurrent execution
(of the same script).
Important for services which generate native config files.

Signed-off-by: Roman Yeryomin <roman@advem.lv>
Signed-off-by: Andrejs Hanins <ahanins@gmail.com>
This commit is contained in:
Roman Yeryomin 2017-12-14 23:54:26 +02:00 committed by John Crispin
parent 2277cd1249
commit e410f785a4

@ -38,6 +38,20 @@
PROCD_RELOAD_DELAY=1000
_PROCD_SERVICE=
procd_lock() {
local basescript=$(readlink "$initscript")
local service_name="$(basename ${basescript:-$initscript})"
flock -n 1000 &> /dev/null
if [ "$?" != "0" ]; then
exec 1000>/var/lock/procd_${service_name}.lock
flock 1000
if [ "$?" != "0" ]; then
logger "warning: procd flock for $service_name failed"
fi
fi
}
_procd_call() {
local old_cb
@ -47,6 +61,7 @@ _procd_call() {
}
_procd_wrapper() {
procd_lock
while [ -n "$1" ]; do
eval "$1() { _procd_call _$1 \"\$@\"; }"
shift