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>
---
scripts/qemu-guest-agent/fsfreeze-hook | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/scripts/qemu-guest-agent/fsfreeze-hook b/scripts/qemu-guest-agent/fsfreeze-hook
index 5b915af017..6e2d7588af 100755
--- a/scripts/qemu-guest-agent/fsfreeze-hook
+++ b/scripts/qemu-guest-agent/fsfreeze-hook
@@ -24,15 +24,14 @@ USE_SYSLOG=0
# if log file is not writable, fallback to syslog
[ ! -w "$LOGFILE" ] && USE_SYSLOG=1
# try to update log file and fallback to syslog if it fails
-touch "$LOGFILE" &>/dev/null || USE_SYSLOG=1
+touch "$LOGFILE" >/dev/null 2>&1 || USE_SYSLOG=1
# Ensure the log file is writable, fallback to syslog if not
log_message() {
- local message="$1"
if [ "$USE_SYSLOG" -eq 0 ]; then
- printf "%s: %s\n" "$(date)" "$message" >>"$LOGFILE"
+ printf "%s: %s\n" "$(date)" "$1" >>"$LOGFILE"
else
- logger -t qemu-ga-freeze-hook "$message"
+ logger -t qemu-ga-freeze-hook "$1"
fi
}
@@ -43,7 +42,7 @@ for file in "$FSFREEZE_D"/* ; do
is_ignored_file "$file" && continue
[ -x "$file" ] || continue
- log_message "Executing $file $@"
+ log_message "Executing $file $*"
if [ "$USE_SYSLOG" -eq 0 ]; then
"$file" "$@" >>"$LOGFILE" 2>&1
STATUS=$?
@@ -52,7 +51,7 @@ for file in "$FSFREEZE_D"/* ; do
STATUS=${PIPESTATUS[0]}
fi
- if [ $STATUS -ne 0 ]; then
+ if [ "$STATUS" -ne 0 ]; then
log_message "Error: $file finished with status=$STATUS"
else
log_message "$file finished successfully"
--
2.43.0
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
On Tue, Mar 17, 2026 at 11:48 AM Peter Maydell <peter.maydell@linaro.org>
wrote:
> 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>
> ---
> scripts/qemu-guest-agent/fsfreeze-hook | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/qemu-guest-agent/fsfreeze-hook
> b/scripts/qemu-guest-agent/fsfreeze-hook
> index 5b915af017..6e2d7588af 100755
> --- a/scripts/qemu-guest-agent/fsfreeze-hook
> +++ b/scripts/qemu-guest-agent/fsfreeze-hook
> @@ -24,15 +24,14 @@ USE_SYSLOG=0
> # if log file is not writable, fallback to syslog
> [ ! -w "$LOGFILE" ] && USE_SYSLOG=1
> # try to update log file and fallback to syslog if it fails
> -touch "$LOGFILE" &>/dev/null || USE_SYSLOG=1
> +touch "$LOGFILE" >/dev/null 2>&1 || USE_SYSLOG=1
>
> # Ensure the log file is writable, fallback to syslog if not
> log_message() {
> - local message="$1"
> if [ "$USE_SYSLOG" -eq 0 ]; then
> - printf "%s: %s\n" "$(date)" "$message" >>"$LOGFILE"
> + printf "%s: %s\n" "$(date)" "$1" >>"$LOGFILE"
> else
> - logger -t qemu-ga-freeze-hook "$message"
> + logger -t qemu-ga-freeze-hook "$1"
> fi
> }
>
> @@ -43,7 +42,7 @@ for file in "$FSFREEZE_D"/* ; do
> is_ignored_file "$file" && continue
> [ -x "$file" ] || continue
>
> - log_message "Executing $file $@"
> + log_message "Executing $file $*"
> if [ "$USE_SYSLOG" -eq 0 ]; then
> "$file" "$@" >>"$LOGFILE" 2>&1
> STATUS=$?
> @@ -52,7 +51,7 @@ for file in "$FSFREEZE_D"/* ; do
> STATUS=${PIPESTATUS[0]}
> fi
>
> - if [ $STATUS -ne 0 ]; then
> + if [ "$STATUS" -ne 0 ]; then
> log_message "Error: $file finished with status=$STATUS"
> else
> log_message "$file finished successfully"
> --
> 2.43.0
>
>
© 2016 - 2026 Red Hat, Inc.