ctdb-tools: Avoid use of non-portable getopt in onnode
authorMartin Schwenke <martin@meltin.net>
Sun, 1 Jul 2018 08:43:06 +0000 (18:43 +1000)
committerMartin Schwenke <martins@samba.org>
Sat, 28 Jul 2018 01:50:10 +0000 (03:50 +0200)
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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tools/onnode

index 50fc6a732d5854b72070fc7f0d9bfeacfa1f0d37..bef04b0fce029fe068e629ff90343e59babc7dfd 100755 (executable)
@@ -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 ()