Message ID | 1460147350-7601-4-git-send-email-pbonzini@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Paolo Bonzini <pbonzini@redhat.com> writes: > This decouples logging further from config-target.h > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> > --- > bsd-user/main.c | 1 + > include/qemu/log.h | 17 ++--------------- > linux-user/main.c | 1 + > util/log.c | 12 ++++++++++-- > 4 files changed, 14 insertions(+), 17 deletions(-) > > diff --git a/bsd-user/main.c b/bsd-user/main.c > index 27854c1..058eaca 100644 > --- a/bsd-user/main.c > +++ b/bsd-user/main.c > @@ -849,6 +849,7 @@ int main(int argc, char **argv) > } > > /* init debug */ > + qemu_log_needs_buffers(); > qemu_set_log_filename(log_file); > if (log_mask) { > int mask; > diff --git a/include/qemu/log.h b/include/qemu/log.h > index c52f136..234fa81 100644 > --- a/include/qemu/log.h > +++ b/include/qemu/log.h > @@ -104,21 +104,8 @@ typedef struct QEMULogItem { > > extern const QEMULogItem qemu_log_items[]; > > -/* This is the function that actually does the work of > - * changing the log level; it should only be accessed via > - * the qemu_set_log() wrapper. > - */ > -void do_qemu_set_log(int log_flags, bool use_own_buffers); > - > -static inline void qemu_set_log(int log_flags) > -{ > -#ifdef CONFIG_USER_ONLY > - do_qemu_set_log(log_flags, true); > -#else > - do_qemu_set_log(log_flags, false); > -#endif > -} > - > +void qemu_set_log(int log_flags); > +void qemu_log_needs_buffers(void); > void qemu_set_log_filename(const char *filename); > void qemu_set_dfilter_ranges(const char *ranges); > bool qemu_log_in_addr_range(uint64_t addr); > diff --git a/linux-user/main.c b/linux-user/main.c > index 5f3ec97..2b7fa9c 100644 > --- a/linux-user/main.c > +++ b/linux-user/main.c > @@ -3760,6 +3760,7 @@ static void handle_arg_log(const char *arg) > qemu_print_log_usage(stdout); > exit(EXIT_FAILURE); > } > + qemu_log_needs_buffers(); > qemu_set_log(mask); > } > > diff --git a/util/log.c b/util/log.c > index 1857730..5ad72c1 100644 > --- a/util/log.c > +++ b/util/log.c > @@ -42,8 +42,10 @@ void qemu_log(const char *fmt, ...) > va_end(ap); > } > > +static bool log_uses_own_buffers; > + > /* enable or disable low levels log */ > -void do_qemu_set_log(int log_flags, bool use_own_buffers) > +void qemu_set_log(int log_flags) > { > qemu_loglevel = log_flags; > #ifdef CONFIG_TRACE_LOG > @@ -70,7 +72,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) > qemu_logfile = stderr; > } > /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ > - if (use_own_buffers) { > + if (log_uses_own_buffers) { > static char logfile_buf[4096]; > > setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf)); > @@ -89,6 +91,12 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) > qemu_log_close(); > } > } > + > +void qemu_log_needs_buffers(void) > +{ > + log_uses_own_buffers = true; > +} > + > /* > * Allow the user to include %d in their logfile which will be > * substituted with the current PID. This is useful for debugging many -- Alex Bennée
diff --git a/bsd-user/main.c b/bsd-user/main.c index 27854c1..058eaca 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -849,6 +849,7 @@ int main(int argc, char **argv) } /* init debug */ + qemu_log_needs_buffers(); qemu_set_log_filename(log_file); if (log_mask) { int mask; diff --git a/include/qemu/log.h b/include/qemu/log.h index c52f136..234fa81 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -104,21 +104,8 @@ typedef struct QEMULogItem { extern const QEMULogItem qemu_log_items[]; -/* This is the function that actually does the work of - * changing the log level; it should only be accessed via - * the qemu_set_log() wrapper. - */ -void do_qemu_set_log(int log_flags, bool use_own_buffers); - -static inline void qemu_set_log(int log_flags) -{ -#ifdef CONFIG_USER_ONLY - do_qemu_set_log(log_flags, true); -#else - do_qemu_set_log(log_flags, false); -#endif -} - +void qemu_set_log(int log_flags); +void qemu_log_needs_buffers(void); void qemu_set_log_filename(const char *filename); void qemu_set_dfilter_ranges(const char *ranges); bool qemu_log_in_addr_range(uint64_t addr); diff --git a/linux-user/main.c b/linux-user/main.c index 5f3ec97..2b7fa9c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3760,6 +3760,7 @@ static void handle_arg_log(const char *arg) qemu_print_log_usage(stdout); exit(EXIT_FAILURE); } + qemu_log_needs_buffers(); qemu_set_log(mask); } diff --git a/util/log.c b/util/log.c index 1857730..5ad72c1 100644 --- a/util/log.c +++ b/util/log.c @@ -42,8 +42,10 @@ void qemu_log(const char *fmt, ...) va_end(ap); } +static bool log_uses_own_buffers; + /* enable or disable low levels log */ -void do_qemu_set_log(int log_flags, bool use_own_buffers) +void qemu_set_log(int log_flags) { qemu_loglevel = log_flags; #ifdef CONFIG_TRACE_LOG @@ -70,7 +72,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) qemu_logfile = stderr; } /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ - if (use_own_buffers) { + if (log_uses_own_buffers) { static char logfile_buf[4096]; setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf)); @@ -89,6 +91,12 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) qemu_log_close(); } } + +void qemu_log_needs_buffers(void) +{ + log_uses_own_buffers = true; +} + /* * Allow the user to include %d in their logfile which will be * substituted with the current PID. This is useful for debugging many
This decouples logging further from config-target.h Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- bsd-user/main.c | 1 + include/qemu/log.h | 17 ++--------------- linux-user/main.c | 1 + util/log.c | 12 ++++++++++-- 4 files changed, 14 insertions(+), 17 deletions(-)