summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2026-03-17 09:48:06 +0000
committerKostiantyn Kostiuk <kkostiuk@redhat.com>2026-03-27 19:55:01 +0200
commit08497afcb2a737794991f17a37f0a0971fca411e (patch)
treee1d0c83d3fa6eeebca0a222163b86b4127e6abbf /scripts
parent65b9f4791c24b09814ae51135e8dad283faed348 (diff)
downloadqemu-08497afcb2a737794991f17a37f0a0971fca411e.tar.gz
qemu-08497afcb2a737794991f17a37f0a0971fca411e.zip
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>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/qemu-guest-agent/fsfreeze-hook4
1 files changed, 2 insertions, 2 deletions
diff --git a/scripts/qemu-guest-agent/fsfreeze-hook b/scripts/qemu-guest-agent/fsfreeze-hook
index 21eb5c5145..76669f5caf 100755
--- a/scripts/qemu-guest-agent/fsfreeze-hook
+++ b/scripts/qemu-guest-agent/fsfreeze-hook
@@ -21,8 +21,8 @@ is_ignored_file() {
}
USE_SYSLOG=0
-# if log file is not writable, fallback to syslog
-[ ! -w "$LOGFILE" ] && USE_SYSLOG=1
+# if log file exists but is not writable, fallback to syslog
+[ -e "$LOGFILE" ] && [ ! -w "$LOGFILE" ] && USE_SYSLOG=1
# try to update log file and fallback to syslog if it fails
touch "$LOGFILE" >/dev/null 2>&1 || USE_SYSLOG=1