1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

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>
This commit is contained in:
Martin Schwenke 2018-10-12 14:41:42 +11:00 committed by Amitay Isaacs
parent 08469408c3
commit 1bbc4fad43
3 changed files with 32 additions and 2 deletions

13
ctdb/tests/onnode/0010.sh Executable file
View File

@ -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

13
ctdb/tests/onnode/0011.sh Executable file
View File

@ -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

View File

@ -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"