From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N8yC4-0008KI-C8 for qemu-devel@nongnu.org; Fri, 13 Nov 2009 10:36:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N8yBz-0008Jk-Ma for qemu-devel@nongnu.org; Fri, 13 Nov 2009 10:36:12 -0500 Received: from [199.232.76.173] (port=39100 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8yBz-0008Jf-FC for qemu-devel@nongnu.org; Fri, 13 Nov 2009 10:36:07 -0500 Received: from mail-pw0-f43.google.com ([209.85.160.43]:48708) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N8yBz-0004rg-4H for qemu-devel@nongnu.org; Fri, 13 Nov 2009 10:36:07 -0500 Received: by pwi12 with SMTP id 12so2158493pwi.2 for ; Fri, 13 Nov 2009 07:36:05 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1258125436-23759-1-git-send-email-kwolf@redhat.com> References: <1258125436-23759-1-git-send-email-kwolf@redhat.com> Date: Fri, 13 Nov 2009 23:36:05 +0800 Message-ID: Subject: Re: [Qemu-devel] [PATCH] Don't leak file descriptors From: Scott Tsai Content-Type: text/plain; charset=UTF-8 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org On Fri, Nov 13, 2009 at 11:17 PM, 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. Since qemu is a multi threaded program, how about opening those file descriptors with the equivalent of O_CLOEXEC set to avoid the race condition when a fork comes between the 'open/socket/accept' operation and the 'fcntl'? We could create helper functions like 'qemu_socket_cloexec'. The implementation of qemu_socket_cloexec would use the new system calls and flags listed in: http://udrepper.livejournal.com/20407.html if available and fall back to separate 'open' and 'fcnt' operations when not building with a new enough glibc.