On 07/31/2018 05:19 AM, Brian J. Murrell wrote:
> On Tue, 2018-07-31 at 10:48 +0200, Matt Darfeuille wrote:
>>
>> The attached patch (MUTEX_ON_TAKE1.patch) includes:
>> - MUTEX_ON.patch
>> - MUTEX_ON1.patch
>> - The above correction (changing 'openwrt' to 'lockbin')
>> - My take on fixing the above error ( "/sbin/shorewall-lite: line 14:
>> -n: not found")
>>
>> Brian/Tom, thoughts?
> 
> Yeah.  The use of "test" in that patch was a new one on me so I had
> just assumed the use was correct.  But even in a bash shell here, that
> syntax doesn't work:
> 
> $ foo=[ -n "$foobar" ]
> bash: -n: command not found
> 
> Nor do any more fully qualified uses of it (to eliminate shell
> interpretation as being the cause of the problem):
> 
> $ foo=\[ -n "$foobar" ]
> bash: -n: command not found
> $ foo=/bin/[ -n "$foobar" ]
> bash: -n: command not found
> $ foo=/bin/test -n "$foobar"
> bash: -n: command not found
> 
> What does work (doesn't produce a syntax error) is:
> 
> $ foo=$([ -n "$foobar" ])
> $ echo $foo
> $ foobar=foobar
> $ foo=$([ -n "$foobar" ])
> $ echo $foo
> 
> $
> 
> but I can't see how that helps us since $foo is the same when the test
> passes and fails.  The best approximation of what I think Tom was
> trying to achieve is:
> 
> $ unset foobar
> $ [ -n "$foobar" ]
> $ echo $?
> 1
> $ foobar=foobar
> $ [ -n "$foobar" ]
> $ echo $?
> 0
> 
> But that still doesn't give us a "boolean" type value in $openwrt that
> we can use in if statements.  So, I think what we want is:
> 
> if [ -n "$lockbin" -a -h "$lockbin" ]; then
>     openwrt=true
> else
>     openwrt=false
> fi
> 

In addition to that issue, the preceding line was incorrect ('qt' was
incorrect). Revised second patch attached.

-Tom
-- 
Tom Eastep        \   Q: What do you get when you cross a mobster with
Shoreline,         \     an international standard?
Washington, USA     \ A: Someone who makes you an offer you can't
http://shorewall.org \   understand
                      \_______________________________________________
diff --git a/Shorewall-core/lib.common b/Shorewall-core/lib.common
index 205fc705f..7df2879c7 100644
--- a/Shorewall-core/lib.common
+++ b/Shorewall-core/lib.common
@@ -751,6 +751,8 @@ mutex_on()
     lockf=${LOCKFILE:=${VARDIR}/lock}
     local lockpid
     local lockd
+    local lockbin
+    local openwrt
 
     MUTEX_TIMEOUT=${MUTEX_TIMEOUT:-60}
 
@@ -760,28 +762,33 @@ mutex_on()
 
 	[ -d "$lockd" ] || mkdir -p "$lockd"
 
+	lockbin=$(mywhich lock)
+	[ -n "$lockbin" -a -h "$lockbin" ] && openwrt=Yes
+
 	if [ -f $lockf ]; then
 	    lockpid=`cat ${lockf} 2> /dev/null`
 	    if [ -z "$lockpid" ] || [ $lockpid = 0 ]; then
 		rm -f ${lockf}
 		error_message "WARNING: Stale lockfile ${lockf} removed"
-	    elif [ $lockpid -eq $$ ]; then
-                fatal_error "Mutex_on confusion"
-	    elif ! qt ps --pid ${lockpid}; then
-		rm -f ${lockf}
-		error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
+	    elif [ -z "$openwrt" ]; then
+		if [ $lockpid -eq $$ ]; then
+                    fatal_error "Mutex_on confusion"
+		elif ! qt ps --pid ${lockpid}; then
+		    rm -f ${lockf}
+		    error_message "WARNING: Stale lockfile ${lockf} from pid ${lockpid} removed"
+		fi
 	    fi
 	fi
 
-	if qt mywhich lockfile; then
+	if [ -n "$openwrt" ]; then
+	    lock ${lockf} || fatal_error "Can't lock ${lockf}"
+	    g_havemutex="lock -u ${lockf}"
+	elif qt mywhich lockfile; then
 	    lockfile -${MUTEX_TIMEOUT} -r1 ${lockf} || fatal_error "Can't lock ${lockf}"
 	    g_havemutex="rm -f ${lockf}"
 	    chmod u+w ${lockf}
 	    echo $$ > ${lockf}
 	    chmod u-w ${lockf}
-	elif qt mywhich lock; then
-	    lock ${lockf} || fatal_error "Can't lock ${lockf}"
-	    g_havemutex="lock -u ${lockf}"
 	else
 	    while [ -f ${lockf} -a ${try} -lt ${MUTEX_TIMEOUT} ] ; do
 		sleep 1

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Shorewall-users mailing list
Shorewall-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/shorewall-users

Reply via email to