In some environments, such as dash, $RANDOM is empty.
This fixes up the last two references that I could find
in the tree to $RANDOM to make sure they are sensible in
this case.

Signed-off-by: Simon Horman <[EMAIL PROTECTED]>

Index: heartbeat/resources/OCF/.ocf-shellfuncs.in
===================================================================
--- heartbeat.orig/resources/OCF/.ocf-shellfuncs.in     2008-08-06 
20:05:13.000000000 +1000
+++ heartbeat/resources/OCF/.ocf-shellfuncs.in  2008-08-06 20:05:23.000000000 
+1000
@@ -58,6 +58,13 @@ ocf_is_root() {
        esac
 }
 
+ocf_maybe_random() {
+       local rnd="$RANDOM"
+       # Something sane-ish in case a shell doesn't support $RANDOM
+       [ -n "$rnd" ] || rnd=$$
+       echo $rnd
+}
+
 # Portability comments:
 # o The following rely on Bourne "sh" pattern-matching, which is usually
 #   that for filename generation (note: not regexp).
@@ -208,19 +215,15 @@ ocf_pidfile_status() {
 }
 
 ocf_take_lock() {
-    lockfile=$1
-
-    if [ ! -n $RANDOM ]; then
-       # Something sane-ish in case a shell doesn't support $RANDOM
-       RANDOM=$$
-    fi
+    local lockfile=$1
+    local rnd=$(ocf_maybe_random)
 
-    sleep 0.$RANDOM
+    sleep 0.$rnd
     while 
        ocf_pidfile_status $lockfile
     do
        ocf_log info "Sleeping until $lockfile is released..."
-       sleep 0.$RANDOM
+       sleep 0.$rnd
     done
     echo $$ > $lockfile
 }
Index: heartbeat/resources/OCF/EvmsSCC
===================================================================
--- heartbeat.orig/resources/OCF/EvmsSCC        2008-08-06 20:05:13.000000000 
+1000
+++ heartbeat/resources/OCF/EvmsSCC     2008-08-06 20:05:23.000000000 +1000
@@ -151,7 +151,7 @@ EvmsSCC_start_notify_common()
                 while [ -n "$EVMS_OUTPUT" ] ; do
                         EVMS_OUTPUT=`evms_activate 2>&1`
                         if [ -n "$EVMS_OUTPUT" ] ; then
-                                SLEEP_TIME=$(($RANDOM % 40))
+                                SLEEP_TIME=$(($(ocf_maybe_random) % 40))
                                 ocf_log info "EvmsSCC: Evms call failed - 
sleeping for $SLEEP_TIME seconds and then trying again."
                                 sleep $SLEEP_TIME
                         else
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to