[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/24] util/log: do not close and reopen log files when flags are
From: |
Paolo Bonzini |
Subject: |
[PULL 03/24] util/log: do not close and reopen log files when flags are turned off |
Date: |
Wed, 21 Dec 2022 19:01:20 +0100 |
log_append makes sure that if you turn off the logging (which clears
log_flags and makes need_to_open_file false) the old log is not
overwritten. The usecase is that if you remove or move the file
QEMU will not keep writing to the old file. However, this is
not always the desited behavior, in particular having log_append==1
after changing the file name makes little sense.
When qemu_set_log_internal is called from the logfile monitor
command, filename must be non-NULL and therefore changed_name must
be true. Therefore, the only case where the file is closed and
need_to_open_file == false is indeed when log_flags becomes
zero. In this case, just flush the file and do not bother
closing it, thus faking the same append behavior as previously.
The behavioral change is that changing the logfile twice, for
example log1 -> log2 -> log1, will cause log1 to be overwritten.
This can simply be documented, since it is not a particularly
surprising behavior.
Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id: <20221025092119.236224-1-pbonzini@redhat.com>
[groug: nullify global_file before actually closing the file]
Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <20221108140032.1460307-2-groug@kaod.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
util/log.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/util/log.c b/util/log.c
index c2198badf240..fb843453dd49 100644
--- a/util/log.c
+++ b/util/log.c
@@ -45,7 +45,6 @@ static __thread FILE *thread_file;
static __thread Notifier qemu_log_thread_cleanup_notifier;
int qemu_loglevel;
-static bool log_append;
static bool log_per_thread;
static GArray *debug_regions;
@@ -277,19 +276,20 @@ static bool qemu_set_log_internal(const char *filename,
bool changed_name,
daemonized = is_daemonized();
need_to_open_file = log_flags && !per_thread && (!daemonized || filename);
- if (logfile && (!need_to_open_file || changed_name)) {
- qatomic_rcu_set(&global_file, NULL);
- if (logfile != stderr) {
+ if (logfile) {
+ fflush(logfile);
+ if (changed_name && logfile != stderr) {
RCUCloseFILE *r = g_new0(RCUCloseFILE, 1);
r->fd = logfile;
+ qatomic_rcu_set(&global_file, NULL);
call_rcu(r, rcu_close_file, rcu);
+ logfile = NULL;
}
- logfile = NULL;
}
if (!logfile && need_to_open_file) {
if (filename) {
- logfile = fopen(filename, log_append ? "a" : "w");
+ logfile = fopen(filename, "w");
if (!logfile) {
error_setg_errno(errp, errno, "Error opening logfile %s",
filename);
@@ -308,8 +308,6 @@ static bool qemu_set_log_internal(const char *filename,
bool changed_name,
logfile = stderr;
}
- log_append = 1;
-
qatomic_rcu_set(&global_file, logfile);
}
return true;
--
2.38.1
- [PULL 00/24] QEMU patches for 2022-12-21, Paolo Bonzini, 2022/12/21
- [PULL 03/24] util/log: do not close and reopen log files when flags are turned off,
Paolo Bonzini <=
- [PULL 01/24] typedefs: Forward-declare AccelState, Paolo Bonzini, 2022/12/21
- [PULL 04/24] util/log: Always send errors to logfile when daemonized, Paolo Bonzini, 2022/12/21
- [PULL 05/24] ide: Add 8-bit data mode, Paolo Bonzini, 2022/12/21
- [PULL 06/24] ide: Add "ide-cf" driver, a CompactFlash card, Paolo Bonzini, 2022/12/21
- [PULL 08/24] configure: remove dead function, Paolo Bonzini, 2022/12/21
- [PULL 10/24] configure: preserve qemu-ga variables, Paolo Bonzini, 2022/12/21
- [PULL 02/24] hw: Reduce "qemu/accel.h" inclusion, Paolo Bonzini, 2022/12/21
- [PULL 07/24] configure: remove useless write_c_skeleton, Paolo Bonzini, 2022/12/21
- [PULL 11/24] configure: remove backwards-compatibility and obsolete options, Paolo Bonzini, 2022/12/21
- [PULL 09/24] configure: cleanup $cpu tests, Paolo Bonzini, 2022/12/21