@samitouri / QOSamiQemu / commits / 08497afcb2

scripts/qemu-guest-agent/fsfreeze-hook: Fix syslog-fallback logic

In the fsfreeze script we attempt to implement "log to a file if we can, and fall back to syslog if we cannot". We do this with: [ ! -w "$LOGFILE" ] && USE_SYSLOG=1 touch "$LOGFILE" >/dev/null 2>&1 || USE_SYSLOG=1 This has a weird behaviour if it is run in a setup where we have permissions that would allow us to write to $LOGFILE but it does not currently exist. On the first execution, the '-w' fails and so we set USE_SYSLOG=1. But since we also do the "touch $LOGFILE" step we create an empty logfile. Then on the second time the script is executed, we see a writeable logfile and will use it. The effect is "log to syslog once, then to the logfile thereafter", which is not likely to be what anybody wants. Update the condition of the first check to only pick syslog if the logfile exists but is not writable. This means that: * if the logfile doesn't exist but we are able to create it, we will create it and use it * if the logfile already exists and we can write to it, we will use it * if the logfile already exists but we can't write to it, we will fall back to syslog * if the logfile doesn't exist and we can't create it, we will fall back to syslog 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> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260317094806.1944053-4-peter.maydell@linaro.org Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>

Peter Maydell committed Mar 17, 2026 at 09:48 UTC 08497afcb2a737794991f17a37f0a0971fca411e
1 file changed +2 -2
scripts/qemu-guest-agent/fsfreeze-hook
+2 -2
@@ -21,8 +21,8 @@ is_ignored_file() {
21 }
22
23 USE_SYSLOG=0
24 -# if log file is not writable, fallback to syslog
25 -[ ! -w "$LOGFILE" ] && USE_SYSLOG=1
24 +# if log file exists but is not writable, fallback to syslog
25 +[ -e "$LOGFILE" ] && [ ! -w "$LOGFILE" ] && USE_SYSLOG=1
26 # try to update log file and fallback to syslog if it fails
27 touch "$LOGFILE" >/dev/null 2>&1 || USE_SYSLOG=1
28