onnode: update algorithm for finding nodes file.
authorMartin Schwenke <martin@meltin.net>
Thu, 21 Jan 2010 02:40:03 +0000 (13:40 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 21 Jan 2010 07:52:44 +0000 (18:52 +1100)
2 changes:

* If a relative nodes file is specified via -f or $CTDB_NODES_FILE but
  this file does not exist then try looking for the file in /etc/ctdb
  (or $CTDB_BASE if set).

* If a nodes file is specified via -f or $CTDB_NODES_FILE but this
  file does not exist (even when checked as per above) then do not
  fall back to /etc/ctdb/nodes ((or $CTDB_BASE if set).  The old
  behaviour was surprising and hid errors.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tools/onnode

index c44b89ad5d29e3b6393f41a4803cfa32656fad9a..fa61b47e5bd6f50c7a0f55bd142ebf3aacd917bc 100755 (executable)
@@ -231,8 +231,21 @@ get_nodes ()
     if [ -n "$CTDB_NODES_SOCKETS" ] ; then 
        all_nodes="$CTDB_NODES_SOCKETS"
     else
-       [ -e "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE="${ctdb_base}/nodes"
-       all_nodes=$(sed -e 's@#.*@@g' -e 's@ *@@g' -e 's@^$@#DEAD@' $CTDB_NODES_FILE)
+       local f="${ctdb_base}/nodes"
+       if [ -n "$CTDB_NODES_FILE" ] ; then
+           f="$CTDB_NODES_FILE"
+           if [ ! -e "$f" -a "${f#/}" = "$f" ] ; then
+               # $f is relative, try in $ctdb_base
+               f="${ctdb_base}/${f}"
+           fi
+       fi
+
+       if [ ! -r "$f" ] ; then
+           echo "${prog}: unable to open nodes file  \"${f}\"" >&2
+           exit 1
+       fi
+
+       all_nodes=$(sed -e 's@#.*@@g' -e 's@ *@@g' -e 's@^$@#DEAD@' "$f")
     fi
 
     local nodes=""