Message ID | 20180118081407.5214-1-john@phrozen.org |
---|---|
State | Changes Requested |
Delegated to: | John Crispin |
Headers | show |
Series | [LEDE-DEV,1/2] procd/base-files: move init.d locking to rc.common | expand |
On 18/01/18 09:14, John Crispin wrote: > rather than using flock for procd enabled services we add locking to the > rc.common code. > > Signed-off-by: John Crispin <john@phrozen.org> > --- > package/base-files/files/etc/rc.common | 6 ++++++ > package/system/procd/files/procd.sh | 15 --------------- > 2 files changed, 6 insertions(+), 15 deletions(-) > > diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common > index 3e237170b4..180ee83acd 100755 > --- a/package/base-files/files/etc/rc.common > +++ b/package/base-files/files/etc/rc.common > @@ -148,4 +148,10 @@ ${INIT_TRACE:+set -x} > > ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}" > list_contains ALL_COMMANDS "$action" || action=help > + > +local basescript=$(readlink "$initscript") > +local service_name="$(basename ${basescript:-$initscript})" > + > +lock -w /var/lock/init.d_${service_name}.lock the -w is wrong here and needs to be removed John` > $action "$@" > +lock -u /var/lock/init.d_${service_name}.lock > diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh > index b4b6faa662..b7d7b94ff1 100644 > --- a/package/system/procd/files/procd.sh > +++ b/package/system/procd/files/procd.sh > @@ -38,20 +38,6 @@ > 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 > > @@ -61,7 +47,6 @@ _procd_call() { > } > > _procd_wrapper() { > - procd_lock > while [ -n "$1" ]; do > eval "$1() { _procd_call _$1 \"\$@\"; }" > shift
On 2018-01-18 10:30, John Crispin wrote: > On 18/01/18 09:14, John Crispin wrote: >> rather than using flock for procd enabled services we add locking to >> the >> rc.common code. >> >> Signed-off-by: John Crispin <john@phrozen.org> >> --- >> package/base-files/files/etc/rc.common | 6 ++++++ >> package/system/procd/files/procd.sh | 15 --------------- >> 2 files changed, 6 insertions(+), 15 deletions(-) >> >> diff --git a/package/base-files/files/etc/rc.common >> b/package/base-files/files/etc/rc.common >> index 3e237170b4..180ee83acd 100755 >> --- a/package/base-files/files/etc/rc.common >> +++ b/package/base-files/files/etc/rc.common >> @@ -148,4 +148,10 @@ ${INIT_TRACE:+set -x} >> ALL_COMMANDS="start stop reload restart boot shutdown enable >> disable enabled depends ${EXTRA_COMMANDS}" >> list_contains ALL_COMMANDS "$action" || action=help >> + >> +local basescript=$(readlink "$initscript") >> +local service_name="$(basename ${basescript:-$initscript})" >> + >> +lock -w /var/lock/init.d_${service_name}.lock > > the -w is wrong here and needs to be removed > Hi John, the lock command here is OpenWrt custom patch, implementing flock (in a different way). Maybe we can use busybox flock and migrate all other scripts to flock? Can it do something what flock cannot? I have done this already in one of my branches but didn't do testing so didn't submit. Regards, Roman
diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common index 3e237170b4..180ee83acd 100755 --- a/package/base-files/files/etc/rc.common +++ b/package/base-files/files/etc/rc.common @@ -148,4 +148,10 @@ ${INIT_TRACE:+set -x} ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}" list_contains ALL_COMMANDS "$action" || action=help + +local basescript=$(readlink "$initscript") +local service_name="$(basename ${basescript:-$initscript})" + +lock -w /var/lock/init.d_${service_name}.lock $action "$@" +lock -u /var/lock/init.d_${service_name}.lock diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh index b4b6faa662..b7d7b94ff1 100644 --- a/package/system/procd/files/procd.sh +++ b/package/system/procd/files/procd.sh @@ -38,20 +38,6 @@ 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 @@ -61,7 +47,6 @@ _procd_call() { } _procd_wrapper() { - procd_lock while [ -n "$1" ]; do eval "$1() { _procd_call _$1 \"\$@\"; }" shift
rather than using flock for procd enabled services we add locking to the rc.common code. Signed-off-by: John Crispin <john@phrozen.org> --- package/base-files/files/etc/rc.common | 6 ++++++ package/system/procd/files/procd.sh | 15 --------------- 2 files changed, 6 insertions(+), 15 deletions(-)