This is actually not a bashism but a false positive from the
checkbashisms script. The "fixing" commit
http://cgit.freedesktop.org/pm-utils/commit/?id=f3821f3479a58a8453bf9219fb5933fd99b5c1a8
seems therefore not necessary and actually wrong.

The "$elapsed == $2" is inside $((...)) and is thus an arithmetic
expression, where == is indeed a valid comparison operator. On the
other hand, the = operator (introduced in the above commit) is an
assignment operator inside an arithmetic expression.

Anyway, putting this comparison inside an arithmetic expression should
not be necessary, one can simply do a plain string match as in the
attached patch. Note however that a string match will not interpret
various integer notations that an integer match or arithmetic
expression would do, so for instance specifying the timeout in
hexadecimal will not work. On the other hand a shell integer match
(-eq) would accept hexadecimal notation, but would require the extra
check for an empty $2 argument.

I also removed a superfluous semicolon in the same function.

Best regards,
Tormod
From fb407fac6c23b58a413de9fde4f39857833a92e9 Mon Sep 17 00:00:00 2001
From: Tormod Volden <debian.tor...@gmail.com>
Date: Sun, 5 Jul 2009 19:50:18 +0200
Subject: [PATCH] fix and simplify the timeout check in spin_lock()

Commit f3821f3479a58a8453bf9219fb5933fd99b5c1a8 was not fixing
a bashism since the == was inside a arithmetic expression.

Rewrite the test to not use an arithmetic expression at all.

Also remove a superfluous semicolon.

Signed-off-by: Tormod Volden <debian.tor...@gmail.com>
---
 pm/functions.in |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pm/functions.in b/pm/functions.in
index b72a449..b19c5b8 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -28,9 +28,9 @@ spin_lock()
 	# $2 = optional timeout
 	local elapsed=0
 	while ! try_lock $1; do
-		[ "x$2" != "x" ] && [ $(( $elapsed = $2 )) -ne 0 ] && return 1
+		[ $elapsed = "$2" ] && return 1
 		elapsed=$(($elapsed + 1))
-		sleep 1;
+		sleep 1
 	done
 }
 
-- 
1.6.0.4

Reply via email to