@samitouri / QOSamiQemu / commits / b5abb655fa

scripts/qemu-guest-agent/fsfreeze-hook: Avoid bash-isms

The fsfreeze-hook script starts with #!/bin/sh, but it uses several bash-specific constructs, resulting in misbehaviour on guest systems where /bin/sh is some other POSIX shell. Fix the simple ones reported by shellcheck: In scripts/qemu-guest-agent/fsfreeze-hook line 27: touch "$LOGFILE" &>/dev/null || USE_SYSLOG=1 ^---------^ SC3020 (warning): In POSIX sh, &> is undefined. In scripts/qemu-guest-agent/fsfreeze-hook line 31: local message="$1" ^-----------^ SC3043 (warning): In POSIX sh, 'local' is undefined. In scripts/qemu-guest-agent/fsfreeze-hook line 46: log_message "Executing $file $@" ^-- SC2145 (error): Argument mixes string and array. Use * or separate argument. In scripts/qemu-guest-agent/fsfreeze-hook line 55: if [ $STATUS -ne 0 ]; then ^-----^ SC2086 (info): Double quote to prevent globbing and word splitting. There is also a use of PIPESTATUS that is more complex to fix; that will be dealt with in a separate commit. Cc: qemu-stable@nongnu.org Fixes: 85978dfb6b1c133 ("qemu-ga: Optimize freeze-hook script logic of logging error") Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com> Link: https://lore.kernel.org/qemu-devel/20260317094806.1944053-2-peter.maydell@linaro.org Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>

Peter Maydell committed Mar 17, 2026 at 09:48 UTC b5abb655fab6145ff3728d4bdaea3648468590fc
1 file changed +5 -6
scripts/qemu-guest-agent/fsfreeze-hook
+5 -6
@@ -24,15 +24,14 @@ USE_SYSLOG=0
24 # if log file is not writable, fallback to syslog
25 [ ! -w "$LOGFILE" ] && USE_SYSLOG=1
26 # try to update log file and fallback to syslog if it fails
27 -touch "$LOGFILE" &>/dev/null || USE_SYSLOG=1
27 +touch "$LOGFILE" >/dev/null 2>&1 || USE_SYSLOG=1
28
29 # Ensure the log file is writable, fallback to syslog if not
30 log_message() {
31 - local message="$1"
31 if [ "$USE_SYSLOG" -eq 0 ]; then
33 - printf "%s: %s\n" "$(date)" "$message" >>"$LOGFILE"
32 + printf "%s: %s\n" "$(date)" "$1" >>"$LOGFILE"
33 else
35 - logger -t qemu-ga-freeze-hook "$message"
34 + logger -t qemu-ga-freeze-hook "$1"
35 fi
36 }
37
@@ -43,7 +42,7 @@ for file in "$FSFREEZE_D"/* ; do
42 is_ignored_file "$file" && continue
43 [ -x "$file" ] || continue
44
46 - log_message "Executing $file $@"
45 + log_message "Executing $file $*"
46 if [ "$USE_SYSLOG" -eq 0 ]; then
47 "$file" "$@" >>"$LOGFILE" 2>&1
48 STATUS=$?
@@ -52,7 +51,7 @@ for file in "$FSFREEZE_D"/* ; do
51 STATUS=${PIPESTATUS[0]}
52 fi
53
55 - if [ $STATUS -ne 0 ]; then
54 + if [ "$STATUS" -ne 0 ]; then
55 log_message "Error: $file finished with status=$STATUS"
56 else
57 log_message "$file finished successfully"