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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 26, 2021 at 01:38:17PM +0000, Daniel P. Berrangé wrote:
The libvirt_recover_xattrs.sh tool hangs when run. It appears that
calling 'shift' is not modifying the '$#' value, so the loop never
terminates. Rewrite to just loop over $@ instead which involves less
cleverness.


shift actually does modify the value of the '#' variable, but if OPTIND
is 1, then the shift is called as `shift 0` which, of course, does not
shift any values (shifts them by 0).

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

diff --git a/tools/libvirt_recover_xattrs.sh b/tools/libvirt_recover_xattrs.sh
index be6ee84b5f..ae9a18bad8 100755
--- a/tools/libvirt_recover_xattrs.sh
+++ b/tools/libvirt_recover_xattrs.sh
@@ -104,11 +104,10 @@ fix_xattrs() {
}


-shift $((OPTIND - 1))

I think this needs to stay here in case there are some parameters that
were not shifted as it looks like that's the reason for using OPTIND
here.

if [ $# -gt 0 ]; then
-    while [ $# -gt 0 ]; do
-        fix_xattrs "$1"
-        shift $((OPTIND - 1))

I think the idea was that this shift should've just happen without
parameters to default to `shift 1`.  But `for` works too.

+    for arg in "$@"
+    do
+        fix_xattrs "$arg"
    done
else
    if [ ${UNSAFE} -eq 1 ]; then
--
2.33.1

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux