From patchwork Mon Mar 14 11:21:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 8578471 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A40C2C0554 for ; Mon, 14 Mar 2016 11:22:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 046192041C for ; Mon, 14 Mar 2016 11:22:12 +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 0AE3D2041E for ; Mon, 14 Mar 2016 11:22:11 +0000 (UTC) Received: from localhost ([::1]:40173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afQZd-0000td-0a for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 Mar 2016 07:22:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afQZQ-0000tJ-U4 for qemu-devel@nongnu.org; Mon, 14 Mar 2016 07:21:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afQZN-0003CO-O4 for qemu-devel@nongnu.org; Mon, 14 Mar 2016 07:21:56 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:5995 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afQZN-00039Y-Bm for qemu-devel@nongnu.org; Mon, 14 Mar 2016 07:21:53 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u2EBLf94003660; Mon, 14 Mar 2016 14:21:49 +0300 (MSK) From: "Denis V. Lunev" To: Date: Mon, 14 Mar 2016 14:21:35 +0300 Message-Id: <1457954501-26528-4-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457954501-26528-1-git-send-email-den@openvz.org> References: <1457954501-26528-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: "Denis V. Lunev" , qemu-devel@nongnu.org, Stefan Hajnoczi , Paolo Bonzini Subject: [Qemu-devel] [PATCH 3/9] log: improve code in do_qemu_set_log 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 The following commit commit 96c33a4523ee1abe382ce4ff3e82b90ba78aa186 Author: Dimitris Aragiorgis 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 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 CC: Stefan Hajnoczi CC: Paolo Bonzini --- 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(); } }