From patchwork Tue Mar 1 14:03:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitris Aragiorgis X-Patchwork-Id: 8465431 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E90C59F38C for ; Tue, 1 Mar 2016 14:03:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4ACE920122 for ; Tue, 1 Mar 2016 14:03:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4851720265 for ; Tue, 1 Mar 2016 14:03:51 +0000 (UTC) Received: from localhost ([::1]:49797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aakty-0001YO-Nu for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 09:03:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaktN-0000vX-Di for qemu-devel@nongnu.org; Tue, 01 Mar 2016 09:03:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaktJ-00032g-E0 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 09:03:13 -0500 Received: from mx0.arrikto.com ([212.71.252.59]:40008) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaktJ-00032T-8m for qemu-devel@nongnu.org; Tue, 01 Mar 2016 09:03:09 -0500 Received: from troi.arr-srv (mail.arr-srv [192.168.98.4]) by mx0.arrikto.com (Postfix) with ESMTP id C9FB6A073; Tue, 1 Mar 2016 16:03:06 +0200 (EET) Received: from arr (dimara-l.arr-vpn [192.168.89.132]) by troi.arr-srv (Postfix) with ESMTPSA id 73E7E2BC; Tue, 1 Mar 2016 16:03:06 +0200 (EET) Date: Tue, 1 Mar 2016 16:03:05 +0200 From: Dimitris Aragiorgis To: Paolo Bonzini Message-ID: <20160301140305.GA10785@arr> References: <1456833053-8896-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1456833053-8896-1-git-send-email-pbonzini@redhat.com> X-URL: http://www.cslab.ece.ntua.gr/~dimara/ X-PGP-Key: http://www.cslab.ece.ntua.gr/~dimara/keys/pubring.gpg User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.71.252.59 Cc: jtomko@redhat.com, qemu-devel@nongnu.org, kraxel@redhat.com Subject: Re: [Qemu-devel] [PATCH] log: do not log if QEMU is daemonized but without -D X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi all, * Paolo Bonzini [2016-03-01 12:50:53 +0100]: > Commit 96c33a4 ("log: Redirect stderr to logfile if deamonized", > 2016-02-22) wanted to move stderr of a daemonized QEMU to the file > specified with -D. > > However, if -D was not passed, the patch had the side effect of not > redirecting stderr to /dev/null. This happened because qemu_logfile > was set to stderr rather than the expected value of NULL. The fix > is simply in the "if" condition of do_qemu_set_log; the "if" for > closing the file is also changed to match. > Sorry, that was my bad. I tested the proposed fix as well and it works. I would suggest to add some sort of comments since the whole do_qemu_set_log() is hard to parse in one pass. For example: Thanks for this quick fix and sorry again for any trouble caused in the first place. dimara > Reported-by: Jan Tomko > Signed-off-by: Paolo Bonzini > --- > util/log.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/util/log.c b/util/log.c > index a7ddc7e..8b921de 100644 > --- a/util/log.c > +++ b/util/log.c > @@ -56,7 +56,8 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) > #ifdef CONFIG_TRACE_LOG > qemu_loglevel |= LOG_TRACE; > #endif > - if ((qemu_loglevel || is_daemonized()) && !qemu_logfile) { > + if (!qemu_logfile && > + (is_daemonized() ? logfilename != NULL : qemu_loglevel)) { > if (logfilename) { > qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); > if (!qemu_logfile) { > @@ -72,6 +73,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) > } > } 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" */ > @@ -89,7 +91,8 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) > log_append = 1; > } > } > - if (!qemu_loglevel && !is_daemonized() && qemu_logfile) { > + if (qemu_logfile && > + (is_daemonized() ? logfilename == NULL : !qemu_loglevel)) { > qemu_log_close(); > } > } > -- > 2.5.0 > diff --git a/util/log.c b/util/log.c index 8b921de..1d73be0 100644 --- a/util/log.c +++ b/util/log.c @@ -56,6 +56,10 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) #ifdef CONFIG_TRACE_LOG qemu_loglevel |= LOG_TRACE; #endif + /* Setup the logfile when: + * - The loglevel is set via -d option or CONFIG_TRACE_LOG, or + * - Both -daemonize and -D options are given + */ if (!qemu_logfile && (is_daemonized() ? logfilename != NULL : qemu_loglevel)) { if (logfilename) { @@ -91,6 +95,10 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) log_append = 1; } } + /* Close the already setup logfile when loglevel gets reset (e.g. + * via the log HMP command), unless both -daemonize and -D options + * are given. + */ if (qemu_logfile && (is_daemonized() ? logfilename == NULL : !qemu_loglevel)) { qemu_log_close();