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>
---
scripts/qemu-guest-agent/fsfreeze-hook | 4 ++--
1 file 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
--
2.43.0
On 17/3/26 10:48, Peter Maydell wrote:
> 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>
> ---
> scripts/qemu-guest-agent/fsfreeze-hook | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
On Tue, Mar 17, 2026 at 11:54 AM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:
> On 17/3/26 10:48, Peter Maydell wrote:
> > 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>
> > ---
> > scripts/qemu-guest-agent/fsfreeze-hook | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>
>
© 2016 - 2026 Red Hat, Inc.