From patchwork Tue Feb 16 11:35:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 8324281 Return-Path: X-Original-To: patchwork-xen-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 644629F372 for ; Tue, 16 Feb 2016 11:38:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 944F42027D for ; Tue, 16 Feb 2016 11:38:15 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 831E3202A1 for ; Tue, 16 Feb 2016 11:38:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVdv9-0004dq-SX; Tue, 16 Feb 2016 11:35:55 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVdv8-0004da-Mv for xen-devel@lists.xen.org; Tue, 16 Feb 2016 11:35:54 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 38/0D-29293-99903C65; Tue, 16 Feb 2016 11:35:53 +0000 X-Env-Sender: prvs=847c1d30f=Ian.Campbell@citrix.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1455622552!22400442!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 63963 invoked from network); 16 Feb 2016 11:35:53 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-14.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 16 Feb 2016 11:35:53 -0000 X-IronPort-AV: E=Sophos;i="5.22,455,1449532800"; d="scan'208";a="331897618" From: Ian Campbell To: , , Date: Tue, 16 Feb 2016 11:35:45 +0000 Message-ID: <1455622545-22269-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: andrew.cooper3@citrix.com, Ian Campbell Subject: [Xen-devel] [PATCH] xl: close nullfd after dup2'ing it to stdin X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Taking care not to do so if nullfd happens (somehow) to have the same fd number as stdin/out/err. CID: 1130519 It was previously hypothesised[0] that fixing 1130516 would solve this too, but that appears to not have been the case. Compile tested only. [0] http://lists.xenproject.org/archives/html/xen-devel/2013-11/msg02931.html Signed-off-by: Ian Campbell Cc: andrew.cooper3@citrix.com Acked-by: Wei Liu --- tools/libxl/xl_cmdimpl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index d07ccb2..f38e3dd 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -505,6 +505,16 @@ static int do_daemonize(char *name, const char *pidfile) dup2(logfile, 1); dup2(logfile, 2); + /* Close nullfd unless it happens to == std{in,out,err} */ + switch (nullfd) { + case 0: + case 1: + case 2: + break; + default: + close(nullfd); + } + CHK_SYSCALL(daemon(0, 1)); if (pidfile) {