From: "Denis V. Lunev" <den@openvz.org>
Cc: "Denis V. Lunev" <den@openvz.org>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH 3/9] log: improve code in do_qemu_set_log
Date: Mon, 14 Mar 2016 14:21:35 +0300 [thread overview]
Message-ID: <1457954501-26528-4-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1457954501-26528-1-git-send-email-den@openvz.org>
The following commit
commit 96c33a4523ee1abe382ce4ff3e82b90ba78aa186
Author: Dimitris Aragiorgis <dimara@arrikto.com>
Date: Thu Feb 18 13:38:38 2016 +0200
log: Redirect stderr to logfile if deamonized
was created with unnecessary side effect - connect from libvirt starts
to hang. This, in turn, was fixed by
commit c586eac33670c198c6c9ceb1419aa99dafcce907
Author: Paolo Bonzini <pbonzini@redhat.com>
Date: Mon Feb 29 12:18:40 2016 +0100
log: do not log if QEMU is daemonized but without -D
but the fix seems a bit awkward to me.
This patch fixes the problem with a bit more readable approach and makes the
code closer to the original state.
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
---
include/qemu/log.h | 4 ++++
os-posix.c | 2 +-
util/log.c | 10 ++--------
3 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/include/qemu/log.h b/include/qemu/log.h
index 40c24fd..be20811 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -88,6 +88,10 @@ static inline void qemu_log_close(void)
}
qemu_logfile = NULL;
}
+
+ if (is_daemonized()) {
+ dup2(STDOUT_FILENO, STDERR_FILENO); /* dup /dev/null to stderr */
+ }
}
/* define log items */
diff --git a/os-posix.c b/os-posix.c
index 92fa3ba..d4b2a91 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -277,7 +277,7 @@ void os_setup_post(void)
dup2(fd, 0);
dup2(fd, 1);
/* In case -D is given do not redirect stderr to /dev/null */
- if (!qemu_logfile) {
+ if (!qemu_logfile || qemu_logfile == stderr) {
dup2(fd, 2);
}
diff --git a/util/log.c b/util/log.c
index 8b921de..a06aa14 100644
--- a/util/log.c
+++ b/util/log.c
@@ -56,8 +56,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
#ifdef CONFIG_TRACE_LOG
qemu_loglevel |= LOG_TRACE;
#endif
- if (!qemu_logfile &&
- (is_daemonized() ? logfilename != NULL : qemu_loglevel)) {
+ if (qemu_loglevel && !qemu_logfile) {
if (logfilename) {
qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
if (!qemu_logfile) {
@@ -67,13 +66,9 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
/* In case we are a daemon redirect stderr to logfile */
if (is_daemonized()) {
dup2(fileno(qemu_logfile), STDERR_FILENO);
- fclose(qemu_logfile);
- /* This will skip closing logfile in qemu_log_close() */
- qemu_logfile = stderr;
}
} else {
/* Default to stderr if no log file specified */
- assert(!is_daemonized());
qemu_logfile = stderr;
}
/* must avoid mmap() usage of glibc by setting a buffer "by hand" */
@@ -91,8 +86,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
log_append = 1;
}
}
- if (qemu_logfile &&
- (is_daemonized() ? logfilename == NULL : !qemu_loglevel)) {
+ if (!qemu_loglevel && qemu_logfile) {
qemu_log_close();
}
}
--
2.5.0
next prev parent reply other threads:[~2016-03-14 11:21 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-14 11:21 [Qemu-devel] [PATCH v2 0/9] log: assorted improvements Denis V. Lunev
2016-03-14 11:21 ` [Qemu-devel] [PATCH 1/9] trace: do not always call exit() in trace_enable_events Denis V. Lunev
2016-03-14 14:25 ` Paolo Bonzini
2016-03-14 11:21 ` [Qemu-devel] [PATCH 2/9] qemu-log: fix cpu_reset log target Denis V. Lunev
2016-03-14 14:24 ` Paolo Bonzini
2016-03-14 11:21 ` Denis V. Lunev [this message]
2016-03-14 14:28 ` [Qemu-devel] [PATCH 3/9] log: improve code in do_qemu_set_log Paolo Bonzini
2016-03-16 11:20 ` Denis V. Lunev
2016-03-16 11:25 ` Paolo Bonzini
2016-03-14 11:21 ` [Qemu-devel] [PATCH 4/9] log: move qemu_log_close/qemu_log_flush from header to log.c Denis V. Lunev
2016-03-14 14:29 ` Paolo Bonzini
2016-03-14 11:21 ` [Qemu-devel] [PATCH 5/9] log: improve performance of qemu_log and qemu_log_mask if disabled Denis V. Lunev
2016-03-14 14:30 ` Paolo Bonzini
2016-03-14 15:07 ` Denis V. Lunev
2016-03-14 11:21 ` [Qemu-devel] [PATCH 6/9] log: log QMP commands and replies Denis V. Lunev
2016-03-14 14:33 ` Paolo Bonzini
2016-03-14 14:38 ` Daniel P. Berrange
2016-03-14 15:00 ` Denis V. Lunev
2016-03-14 15:05 ` Denis V. Lunev
2016-03-14 15:26 ` Daniel P. Berrange
2016-03-14 16:10 ` Denis V. Lunev
2016-03-14 16:37 ` Paolo Bonzini
2016-03-14 16:11 ` Daniel P. Berrange
2016-03-14 16:16 ` Denis V. Lunev
2016-03-14 16:40 ` Paolo Bonzini
2016-03-16 13:09 ` Denis V. Lunev
2016-03-16 13:11 ` Paolo Bonzini
2016-03-17 15:31 ` Daniel P. Berrange
2016-03-14 11:21 ` [Qemu-devel] [PATCH 7/9] log: report HMP command and event Denis V. Lunev
2016-03-14 14:36 ` Paolo Bonzini
2016-03-14 15:08 ` Denis V. Lunev
2016-03-14 16:35 ` Paolo Bonzini
2016-03-14 11:21 ` [Qemu-devel] [PATCH 8/9] log: report QAPI event Denis V. Lunev
2016-03-14 14:33 ` Paolo Bonzini
2016-03-14 11:21 ` [Qemu-devel] [PATCH 9/9] log: adds a timestamp to each log entry Denis V. Lunev
2016-03-14 14:39 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457954501-26528-4-git-send-email-den@openvz.org \
--to=den@openvz.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).