From patchwork Wed Feb 24 13:27:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8406361 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 7C2BDC0554 for ; Wed, 24 Feb 2016 13:30:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D309020212 for ; Wed, 24 Feb 2016 13:30: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 1A30E202F0 for ; Wed, 24 Feb 2016 13:30:12 +0000 (UTC) Received: from localhost ([::1]:35836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYZW7-0000Gl-Dn for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Feb 2016 08:30:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYZU8-0005Dy-67 for qemu-devel@nongnu.org; Wed, 24 Feb 2016 08:28:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYZU7-0005lV-6D for qemu-devel@nongnu.org; Wed, 24 Feb 2016 08:28:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43657) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYZU7-0005lK-1R for qemu-devel@nongnu.org; Wed, 24 Feb 2016 08:28:07 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 8104363141; Wed, 24 Feb 2016 13:28:06 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-42.ams2.redhat.com [10.36.112.42]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1ODRha4009553; Wed, 24 Feb 2016 08:28:05 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 24 Feb 2016 14:27:36 +0100 Message-Id: <1456320461-26756-15-git-send-email-pbonzini@redhat.com> In-Reply-To: <1456320461-26756-1-git-send-email-pbonzini@redhat.com> References: <1456320461-26756-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 24 Feb 2016 13:28:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Cc: Dimitris Aragiorgis Subject: [Qemu-devel] [PULL 14/19] log: Redirect stderr to logfile if deamonized 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 From: Dimitris Aragiorgis In case of daemonize, use the logfile passed with the -D option in order to redirect stderr to it instead of /dev/null. Also remove some unused code in log.h. Signed-off-by: Dimitris Aragiorgis Message-Id: <1455795518-19205-1-git-send-email-dimara@arrikto.com> Signed-off-by: Paolo Bonzini --- include/qemu/log.h | 6 ------ os-posix.c | 6 +++++- util/log.c | 11 +++++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index 30817f7..dda65fd 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -94,12 +94,6 @@ static inline void qemu_log_close(void) } } -/* Set up a new log file */ -static inline void qemu_log_set_file(FILE *f) -{ - qemu_logfile = f; -} - /* define log items */ typedef struct QEMULogItem { int mask; diff --git a/os-posix.c b/os-posix.c index cce62ed..92fa3ba 100644 --- a/os-posix.c +++ b/os-posix.c @@ -37,6 +37,7 @@ #include "qemu-options.h" #include "qemu/rcu.h" #include "qemu/error-report.h" +#include "qemu/log.h" #ifdef CONFIG_LINUX #include @@ -275,7 +276,10 @@ void os_setup_post(void) dup2(fd, 0); dup2(fd, 1); - dup2(fd, 2); + /* In case -D is given do not redirect stderr to /dev/null */ + if (!qemu_logfile) { + dup2(fd, 2); + } close(fd); diff --git a/util/log.c b/util/log.c index 2709e98..a7ddc7e 100644 --- a/util/log.c +++ b/util/log.c @@ -56,13 +56,20 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) #ifdef CONFIG_TRACE_LOG qemu_loglevel |= LOG_TRACE; #endif - if (qemu_loglevel && !qemu_logfile) { + if ((qemu_loglevel || is_daemonized()) && !qemu_logfile) { if (logfilename) { qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); if (!qemu_logfile) { perror(logfilename); _exit(1); } + /* 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 */ qemu_logfile = stderr; @@ -82,7 +89,7 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers) log_append = 1; } } - if (!qemu_loglevel && qemu_logfile) { + if (!qemu_loglevel && !is_daemonized() && qemu_logfile) { qemu_log_close(); } }