From d4b2ee12baba4527874ce5e39605040f9adc1c18 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 1 Sep 2016 13:35:15 +0200 Subject: scripts/functions: make setsec support empty sections It's useful to be able to write an empty configuration to delete a section. Till now sections of 0 length were rejected. --- sbin/init.d/functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbin/init.d/functions b/sbin/init.d/functions index 924c863..0f79ec6 100644 --- a/sbin/init.d/functions +++ b/sbin/init.d/functions @@ -1125,7 +1125,7 @@ do_checksec() { local svc=$1 local instance=$2 local tmpconfig="/tmp/$svc${instance:+.$instance}.sec" - local length=0 + local length=-1 local hread=0 if [ ! -t 0 ] ; then eval $( @@ -1140,7 +1140,7 @@ do_checksec() { exit 0 ) if [ "$hread" = "1" ] ; then - [ "$length" = "0" ] && echo "Invalid configuration" >&2 && return 1 + [ "$length" = "-1" ] && echo "Invalid configuration" >&2 && return 1 cat > "$tmpconfig" [ ! -e "$tmpconfig" ] && echo "Unable to retrieve configuration" >&2 && return 1 [ "$length" != "$( cat $tmpconfig | wc -c )" ] && echo "Truncated configuration" >&2 && return 1 -- 1.7.12.1