From patchwork Wed Dec 2 10:34:08 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 39981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A137FB7BF0 for ; Wed, 2 Dec 2009 21:36:11 +1100 (EST) Received: from localhost ([127.0.0.1]:44977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFmZ4-0006Xk-SQ for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2009 05:36:06 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFmYM-0006XW-8A for qemu-devel@nongnu.org; Wed, 02 Dec 2009 05:35:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFmYH-0006Wq-5q for qemu-devel@nongnu.org; Wed, 02 Dec 2009 05:35:21 -0500 Received: from [199.232.76.173] (port=42471 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFmYH-0006Wn-1S for qemu-devel@nongnu.org; Wed, 02 Dec 2009 05:35:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1025) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFmYG-0004hr-MK for qemu-devel@nongnu.org; Wed, 02 Dec 2009 05:35:17 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB2AZEJF005029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Dec 2009 05:35:14 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB2AZC3Z001714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 2 Dec 2009 05:35:13 -0500 Message-ID: <4B1642A0.5030701@redhat.com> Date: Wed, 02 Dec 2009 11:34:08 +0100 From: Kevin Wolf User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4pre) Gecko/20091014 Fedora/3.0-2.8.b4.fc11 Thunderbird/3.0b4 MIME-Version: 1.0 To: Alexander Graf Subject: Re: [Qemu-devel] [PATCH v2] Don't leak file descriptors References: <1258386420-23294-1-git-send-email-kwolf@redhat.com> <4B153C60.2060605@suse.de> In-Reply-To: <4B153C60.2060605@suse.de> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Am 01.12.2009 16:55, schrieb Alexander Graf: > Kevin Wolf wrote: >> We're leaking file descriptors to child processes. Set FD_CLOEXEC on file >> descriptors that don't need to be passed to children to stop this misbehaviour. >> >> Signed-off-by: Kevin Wolf > > On Anthony's staging tree: > > cc1: warnings being treated as errors > osdep.c: In function ‘qemu_accept’: > osdep.c:304: error: implicit declaration of function ‘accept4’ Does this one on top work for you? Kevin diff --git a/configure b/configure index dca5a43..0a1e347 100755 --- a/configure +++ b/configure @@ -1550,6 +1550,23 @@ if compile_prog "" "" ; then pipe2=yes fi +# check if accept4 is there +accept4=no +cat > $TMPC << EOF +#define _GNU_SOURCE +#include +#include + +int main(void) +{ + accept4(0, NULL, NULL, SOCK_CLOEXEC); + return 0; +} +EOF +if compile_prog "" "" ; then + accept4=yes +fi + # check if tee/splice is there. vmsplice was added same time. splice=no cat > $TMPC << EOF @@ -2013,6 +2030,9 @@ fi if test "$pipe2" = "yes" ; then echo "CONFIG_PIPE2=y" >> $config_host_mak fi +if test "$accept4" = "yes" ; then + echo "CONFIG_ACCEPT4=y" >> $config_host_mak +fi if test "$splice" = "yes" ; then echo "CONFIG_SPLICE=y" >> $config_host_mak fi diff --git a/osdep.c b/osdep.c index 039065e..7509c5b 100644 --- a/osdep.c +++ b/osdep.c @@ -260,7 +260,7 @@ int qemu_pipe(int pipefd[2]) { int ret; -#ifdef O_CLOEXEC +#ifdef CONFIG_PIPE2 ret = pipe2(pipefd, O_CLOEXEC); #else ret = pipe(pipefd); @@ -300,7 +300,7 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen) { int ret; -#ifdef SOCK_CLOEXEC +#ifdef CONFIG_ACCEPT4 ret = accept4(s, addr, addrlen, SOCK_CLOEXEC); #else ret = accept(s, addr, addrlen);