[PATCH v2] tools: fix iterating over argv when recovering xattr

Daniel P. Berrangé posted 1 patch 2 years, 4 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20211126154656.1655057-1-berrange@redhat.com
tools/libvirt_recover_xattrs.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH v2] tools: fix iterating over argv when recovering xattr
Posted by Daniel P. Berrangé 2 years, 4 months ago
The libvirt_recover_xattrs.sh tool hangs when run. When not flags
are provided OPTIND is 1, so the loop expands to 'shift 0' which
has not effect. Rewrite to just loop over $@ instead which involves
less cleverness.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tools/libvirt_recover_xattrs.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libvirt_recover_xattrs.sh b/tools/libvirt_recover_xattrs.sh
index be6ee84b5f..35c164a9c7 100755
--- a/tools/libvirt_recover_xattrs.sh
+++ b/tools/libvirt_recover_xattrs.sh
@@ -106,9 +106,9 @@ fix_xattrs() {
 
 shift $((OPTIND - 1))
 if [ $# -gt 0 ]; then
-    while [ $# -gt 0 ]; do
-        fix_xattrs "$1"
-        shift $((OPTIND - 1))
+    for arg in "$@"
+    do
+        fix_xattrs "$arg"
     done
 else
     if [ ${UNSAFE} -eq 1 ]; then
-- 
2.33.1

Re: [PATCH v2] tools: fix iterating over argv when recovering xattr
Posted by Martin Kletzander 2 years, 4 months ago
On Fri, Nov 26, 2021 at 03:46:56PM +0000, Daniel P. Berrangé wrote:
>The libvirt_recover_xattrs.sh tool hangs when run. When not flags

s/not/no/

>are provided OPTIND is 1, so the loop expands to 'shift 0' which
>has not effect. Rewrite to just loop over $@ instead which involves
>less cleverness.
>
>Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

>---
> tools/libvirt_recover_xattrs.sh | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>diff --git a/tools/libvirt_recover_xattrs.sh b/tools/libvirt_recover_xattrs.sh
>index be6ee84b5f..35c164a9c7 100755
>--- a/tools/libvirt_recover_xattrs.sh
>+++ b/tools/libvirt_recover_xattrs.sh
>@@ -106,9 +106,9 @@ fix_xattrs() {
>
> shift $((OPTIND - 1))
> if [ $# -gt 0 ]; then
>-    while [ $# -gt 0 ]; do
>-        fix_xattrs "$1"
>-        shift $((OPTIND - 1))
>+    for arg in "$@"
>+    do
>+        fix_xattrs "$arg"
>     done
> else
>     if [ ${UNSAFE} -eq 1 ]; then
>-- 
>2.33.1
>