aboutsummaryrefslogtreecommitdiffstats
path: root/package/system
diff options
context:
space:
mode:
authorRoman Yeryomin <roman@advem.lv>2017-12-14 23:54:26 +0200
committerJohn Crispin <john@phrozen.org>2018-01-02 07:52:27 +0100
commite410f785a4d5676eb71715e8c5c4b3445c6478e3 (patch)
tree804b9ae212e5b7de57a0945bbc355a6cb55a518a /package/system
parent2277cd1249a6952228f36b768beea117c91123a0 (diff)
downloadupstream-e410f785a4d5676eb71715e8c5c4b3445c6478e3.tar.gz
upstream-e410f785a4d5676eb71715e8c5c4b3445c6478e3.tar.bz2
upstream-e410f785a4d5676eb71715e8c5c4b3445c6478e3.zip
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>
Diffstat (limited to 'package/system')
-rw-r--r--package/system/procd/files/procd.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh
index 91e2371d62..b8d3513b1e 100644
--- a/package/system/procd/files/procd.sh
+++ b/package/system/procd/files/procd.sh
@@ -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