aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2018-02-23 14:54:54 +1100
committerEryu Guan <eguan@redhat.com>2018-02-23 13:11:53 +0800
commit7aaf557970c03a965436a3fa6fdd56267edf5ade (patch)
tree3be240dc6f24e69e1c25d079a5a4650954c42d27
parent6702176b93404db6efc1ed6ea8ac4075df2f949f (diff)
downloadxfstests-dev-7aaf557970c03a965436a3fa6fdd56267edf5ade.tar.gz
common/xfs: Initialise OPTIND for getopts calls
According to the bash man page: OPTIND is initialized to 1 each time the shell or a shell script is invoked. This doesn't appear to be true - in tests scripts with no other getopts calls, I'm seeing the getopts loop in _xfs_check to fail to parse input parameters correctly. Tracing shows the parameters are being passed to _xfs_check correctly, but on occassion getopts simply doesn't see them. Hence when running tests with both external log and real time devices, tests are failing at random because xfs_check is mis-parsing the parameters passed to it and not configuring the external log correctly: _check_xfs_filesystem: filesystem on /dev/sdg is inconsistent (c) *** xfs_check output *** aborting - no external log specified for FS with an external log *** end xfs_check output Fix this by ensuring OPTIND is correctly initialised before using getopts. Do it for all places that call getopts that don't already set OPTIND=1 before starting their parsing loop. Signed-Off-By: Dave Chinner <dchinner@redhat.com> Reviewed-by: Eryu Guan <eguan@redhat.com> Signed-off-by: Eryu Guan <eguan@redhat.com>
-rw-r--r--common/xfs1
-rwxr-xr-xtests/generic/0741
-rwxr-xr-xtests/generic/0751
-rwxr-xr-xtests/generic/1121
4 files changed, 4 insertions, 0 deletions
diff --git a/common/xfs b/common/xfs
index 9ed78dee08..354f584f76 100644
--- a/common/xfs
+++ b/common/xfs
@@ -119,6 +119,7 @@ _xfs_check()
DBOPTS=" "
USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
+ OPTIND=1
while getopts "b:fi:l:stvV" c; do
case $c in
s) OPTS=$OPTS"-s ";;
diff --git a/tests/generic/074 b/tests/generic/074
index 5f205b509e..d39f9a3d43 100755
--- a/tests/generic/074
+++ b/tests/generic/074
@@ -87,6 +87,7 @@ _usage()
_process_args()
{
+ OPTIND=1
while getopts "f:l:n:?" c $@
do
case $c
diff --git a/tests/generic/075 b/tests/generic/075
index 321c721776..e9dd4a5c5d 100755
--- a/tests/generic/075
+++ b/tests/generic/075
@@ -98,6 +98,7 @@ _usage()
_process_args()
{
+ OPTIND=1
while getopts "l:n:N:?" c $@
do
case $c
diff --git a/tests/generic/112 b/tests/generic/112
index 0ab1c8c879..5ab1cb3ad4 100755
--- a/tests/generic/112
+++ b/tests/generic/112
@@ -94,6 +94,7 @@ _usage()
_process_args()
{
+ OPTIND=1
while getopts "l:n:N:?" c $@
do
case $c