summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2018-10-12 14:41:42 +1100
committerAmitay Isaacs <amitay@samba.org>2018-11-06 07:16:14 +0100
commit1bbc4fad434a850565fb4f74e529f8824840988a (patch)
tree2da9441e8d4f73902471462758f12908202a8a9a /ctdb
parent08469408c379e37523e76a07ac7264bded1dbf01 (diff)
downloadsamba-1bbc4fad434a850565fb4f74e529f8824840988a.tar.gz
ctdb-tools: Detect unknown node number
If there aren't enough addresses in the list then the shift will silently fail and the printed address will be the unshifted value of $1, which is incorrect/unexpected. So, sanity check the node number. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rwxr-xr-xctdb/tests/onnode/0010.sh13
-rwxr-xr-xctdb/tests/onnode/0011.sh13
-rwxr-xr-xctdb/tools/onnode8
3 files changed, 32 insertions, 2 deletions
diff --git a/ctdb/tests/onnode/0010.sh b/ctdb/tests/onnode/0010.sh
new file mode 100755
index 00000000000..241cf58aa69
--- /dev/null
+++ b/ctdb/tests/onnode/0010.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+cmd="$ONNODE 4 hostname"
+
+define_test "$cmd" "invalid pnn 4"
+
+required_result 1 <<EOF
+onnode: "node 4" does not exist
+EOF
+
+simple_test $cmd
diff --git a/ctdb/tests/onnode/0011.sh b/ctdb/tests/onnode/0011.sh
new file mode 100755
index 00000000000..46045331f1e
--- /dev/null
+++ b/ctdb/tests/onnode/0011.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+cmd="$ONNODE 99 hostname"
+
+define_test "$cmd" "invalid pnn 99"
+
+required_result 1 <<EOF
+onnode: "node 99" does not exist
+EOF
+
+simple_test $cmd
diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode
index eabe034d227..13b0d19b3ee 100755
--- a/ctdb/tools/onnode
+++ b/ctdb/tools/onnode
@@ -102,8 +102,12 @@ echo_nth ()
{
local n="$1" ; shift
- shift "$n"
- local node="$1"
+ # Note that this is 0-based
+ local node=""
+ if [ "$n" -le $# ] ; then
+ shift "$n"
+ node="$1"
+ fi
if [ -n "$node" -a "$node" != "#DEAD" ] ; then
echo "$node"