From: Martin Schwenke Date: Sun, 1 Jul 2018 08:43:06 +0000 (+1000) Subject: ctdb-tools: Avoid use of non-portable getopt in onnode X-Git-Tag: ldb-1.5.0~129 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=4a39bc4aaad541f1e89c0eb3e98d4104bcc25025;p=thirdparty%2Fsamba.git ctdb-tools: Avoid use of non-portable getopt in onnode getopt is being used with non-portable options. Use simpler, POSIX-compliant getopts instead. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 50fc6a732d5..bef04b0fce0 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -72,39 +72,30 @@ fi parse_options () { - # $POSIXLY_CORRECT means that the command passed to onnode can - # take options and getopt won't reorder things to make them - # options ot onnode. - local temp - # Not on the previous line - local returns 0! - temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqvPi" -l help -- "$@") - - # No! Checking the exit code afterwards is actually clearer... - # shellcheck disable=SC2181 - [ $? -eq 0 ] || usage - - eval set -- "$temp" - - while true ; do - case "$1" in - -c) current=true ; shift ;; - -f) ctdb_nodes_file="$2" ; shift 2 ;; - -n) names_ok=true ; shift ;; - -o) prefix="$2" ; shift 2 ;; - -p) parallel=true ; shift ;; - -q) quiet=true ; shift ;; - -v) verbose=true ; shift ;; - -P) push=true ; shift ;; - -i) stdin=true ; shift ;; - --) shift ; break ;; - -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable. - esac - done + local opt + + while getopts "cf:hno:pqvPi?" opt ; do + case "$opt" in + c) current=true ;; + f) ctdb_nodes_file="$OPTARG" ;; + n) names_ok=true ;; + o) prefix="$OPTARG" ;; + p) parallel=true ;; + q) quiet=true ;; + v) verbose=true ;; + P) push=true ;; + i) stdin=true ;; + \?|h) usage ;; + esac + done + shift $((OPTIND - 1)) - [ $# -lt 2 ] && usage + if [ $# -lt 2 ] ; then + usage + fi - nodespec="$1" ; shift - command="$*" + nodespec="$1" ; shift + command="$*" } echo_nth ()