From patchwork Tue Jan 8 21:26:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 210542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5D1292C009A for ; Wed, 9 Jan 2013 08:26:44 +1100 (EST) Received: from localhost ([::1]:56964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsgh0-0006Rc-DJ for incoming@patchwork.ozlabs.org; Tue, 08 Jan 2013 16:26:42 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsggn-0006JU-Af for qemu-devel@nongnu.org; Tue, 08 Jan 2013 16:26:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tsggl-000569-Fh for qemu-devel@nongnu.org; Tue, 08 Jan 2013 16:26:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsggl-000561-7q for qemu-devel@nongnu.org; Tue, 08 Jan 2013 16:26:27 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r08LQOiX014177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Jan 2013 16:26:24 -0500 Received: from localhost (ovpn-113-104.phx2.redhat.com [10.3.113.104]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r08LQNkf020875; Tue, 8 Jan 2013 16:26:24 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 8 Jan 2013 19:26:26 -0200 Message-Id: <1357680386-10904-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1357680386-10904-1-git-send-email-lcapitulino@redhat.com> References: <1357680386-10904-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 2/2] qemu-ga: add ga_open_logfile() 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This function sets O_CLOEXEC on the log file fd so that it isn't leaked to executed processes. Signed-off-by: Luiz Capitulino Reviewed-by: Eric Blake --- qga/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/qga/main.c b/qga/main.c index e4245cc..15be74f 100644 --- a/qga/main.c +++ b/qga/main.c @@ -236,6 +236,19 @@ void ga_set_response_delimited(GAState *s) s->delimit_response = true; } +static FILE *ga_open_logfile(const char *logfile) +{ + FILE *f; + + f = fopen(logfile, "a"); + if (!f) { + return NULL; + } + + qemu_set_cloexec(fileno(f)); + return f; +} + #ifndef _WIN32 static bool ga_open_pidfile(const char *pidfile) { @@ -377,7 +390,7 @@ void ga_unset_frozen(GAState *s) * in a frozen state at start up, do it now */ if (s->deferred_options.log_filepath) { - s->log_file = fopen(s->deferred_options.log_filepath, "a"); + s->log_file = ga_open_logfile(s->deferred_options.log_filepath); if (!s->log_file) { s->log_file = stderr; } @@ -838,7 +851,7 @@ int main(int argc, char **argv) become_daemon(pid_filepath); } if (log_filepath) { - FILE *log_file = fopen(log_filepath, "a"); + FILE *log_file = ga_open_logfile(log_filepath); if (!log_file) { g_critical("unable to open specified log file: %s", strerror(errno));