From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9899 invoked by alias); 6 Dec 2008 08:14:03 -0000 Received: (qmail 9812 invoked by uid 22791); 6 Dec 2008 08:14:02 -0000 X-Spam-Check-By: sourceware.org Received: from mtaout5.012.net.il (HELO mtaout5.012.net.il) (84.95.2.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 06 Dec 2008 08:13:23 +0000 Received: from conversion-daemon.i_mtaout5.012.net.il by i_mtaout5.012.net.il (HyperSendmail v2004.12) id <0KBG00F004132300@i_mtaout5.012.net.il> for gdb-patches@sourceware.org; Sat, 06 Dec 2008 10:15:27 +0200 (IST) Received: from HOME-C4E4A596F7 ([77.126.111.178]) by i_mtaout5.012.net.il (HyperSendmail v2004.12) with ESMTPA id <0KBG007O649O5ZW1@i_mtaout5.012.net.il>; Sat, 06 Dec 2008 10:15:25 +0200 (IST) Date: Sat, 06 Dec 2008 08:14:00 -0000 From: Eli Zaretskii Subject: Re: RFA: close-on-exec internal file descriptors In-reply-to: X-012-Sender: halo1@inter.net.il To: tromey@redhat.com Cc: gdb-patches@sourceware.org Reply-to: Eli Zaretskii Message-id: References: X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-12/txt/msg00108.txt.bz2 > From: Tom Tromey > Date: Fri, 05 Dec 2008 17:38:13 -0700 > > This patch fixes this problem by introducing new wrapper functions > which create close-on-exec file descriptors. Then, these functions > are used everywhere in gdb. After this patch, these wrapper functions > should be used in all new code as well. Thanks. > opsy. gdb /tmp/r > [...] > (gdb) shell ls -l /proc/$$/fd > total 0 > lrwx------ 1 tromey tromey 64 2008-12-05 17:10 0 -> /dev/pts/1 > lrwx------ 1 tromey tromey 64 2008-12-05 17:10 1 -> /dev/pts/1 > lrwx------ 1 tromey tromey 64 2008-12-05 17:10 2 -> /dev/pts/1 > lr-x------ 1 tromey tromey 64 2008-12-05 17:10 3 -> pipe:[1100229] > l-wx------ 1 tromey tromey 64 2008-12-05 17:10 4 -> pipe:[1100229] > lr-x------ 1 tromey tromey 64 2008-12-05 17:10 5 -> /proc/8096/fd > > I believe those 'pipe' entries are from the call to pipe in > linux-nat.c:linux_nat_set_async. Are you saying that the problem is specific to Linux native targets? If so, why the solution invades general source files such as remote.c, ser-tcp.c, ui-file.c, source.c and even remote-mips.c? > I chose to take advantage of the new glibc flags like O_CLOEXEC when > they are available. Relying on glibc is OK for GNU/Linux, but you seem to be modifying files that have no relation to the Linux native builds. Does that mean the non-glibc builds that don't have the support you are relying on will still leak descriptors? > +FILE * > +fopen_cloexec (const char *path, const char *mode) > +{ > +#ifdef O_CLOEXEC > + /* We assume that O_CLOEXEC also implies the availability of the "e" > + flag to fopen. */ > + char new_mode[20]; > + strcpy (new_mode, mode); > + strcat (new_mode, "e"); > + return fopen (path, new_mode); Can we do something more safe than this arbitrary [20] limitation?