From patchwork Thu May 10 19:50:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 158378 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 70A8CB6FA3 for ; Fri, 11 May 2012 05:50:52 +1000 (EST) Received: from localhost ([::1]:44872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZNy-0006iY-Bh for incoming@patchwork.ozlabs.org; Thu, 10 May 2012 15:50:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZNn-0006dk-2g for qemu-devel@nongnu.org; Thu, 10 May 2012 15:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSZNl-0000AO-7l for qemu-devel@nongnu.org; Thu, 10 May 2012 15:50:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31175) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZNk-0000A2-VC for qemu-devel@nongnu.org; Thu, 10 May 2012 15:50:37 -0400 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 (8.14.4/8.14.4) with ESMTP id q4AJoWD1017345 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 May 2012 15:50:32 -0400 Received: from localhost (ovpn-116-83.ams2.redhat.com [10.36.116.83]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4AJoUEj018814; Thu, 10 May 2012 15:50:31 -0400 From: Luiz Capitulino To: mdroth@linux.vnet.ibm.com Date: Thu, 10 May 2012 16:50:41 -0300 Message-Id: <1336679442-19198-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1336679442-19198-1-git-send-email-lcapitulino@redhat.com> References: <1336679442-19198-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 1/2] qemu-ga: make reopen_fd_to_null() public 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 The next commit wants to use it. Signed-off-by: Luiz Capitulino Reviewed-by: Eric Blake --- qemu-ga.c | 17 +++++++++++++++++ qga/commands-posix.c | 19 ------------------- qga/guest-agent-core.h | 4 ++++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/qemu-ga.c b/qemu-ga.c index 216be39..7896565 100644 --- a/qemu-ga.c +++ b/qemu-ga.c @@ -140,6 +140,23 @@ static gboolean register_signal_handlers(void) return true; } + +/* TODO: use this in place of all post-fork() fclose(std*) callers */ +void reopen_fd_to_null(int fd) +{ + int nullfd; + + nullfd = open("/dev/null", O_RDWR); + if (nullfd < 0) { + return; + } + + dup2(nullfd, fd); + + if (nullfd != fd) { + close(nullfd); + } +} #endif static void usage(const char *cmd) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index d58730a..2ce9b82 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -34,25 +34,6 @@ #endif #endif -#if defined(__linux__) -/* TODO: use this in place of all post-fork() fclose(std*) callers */ -static void reopen_fd_to_null(int fd) -{ - int nullfd; - - nullfd = open("/dev/null", O_RDWR); - if (nullfd < 0) { - return; - } - - dup2(nullfd, fd); - - if (nullfd != fd) { - close(nullfd); - } -} -#endif /* defined(__linux__) */ - void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) { int ret; diff --git a/qga/guest-agent-core.h b/qga/guest-agent-core.h index bbb8b9b..6dba104 100644 --- a/qga/guest-agent-core.h +++ b/qga/guest-agent-core.h @@ -35,3 +35,7 @@ void ga_set_response_delimited(GAState *s); bool ga_is_frozen(GAState *s); void ga_set_frozen(GAState *s); void ga_unset_frozen(GAState *s); + +#ifndef _WIN32 +void reopen_fd_to_null(int fd); +#endif