Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: tromey@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: close-on-exec internal file descriptors
Date: Sat, 06 Dec 2008 15:42:00 -0000	[thread overview]
Message-ID: <200812061540.mB6FemZD011819@brahms.sibelius.xs4all.nl> (raw)
In-Reply-To: <m3skp2w32i.fsf@fleche.redhat.com> (message from Tom Tromey on 	Fri, 05 Dec 2008 17:38:13 -0700)

> From: Tom Tromey <tromey@redhat.com>
> Date: Fri, 05 Dec 2008 17:38:13 -0700
> 
> A few weeks ago, someone on irc pointed out that gdb leaks file
> descriptors to its child processes.  One simple way to see this is to
> start gdb with an exec and then shell out:
> 
>     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.
> 
> 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.
> 
> I chose to take advantage of the new glibc flags like O_CLOEXEC when
> they are available.  This is friendlier in the Python case -- here,
> gdb might have multiple threads, and the glibc flags enable us to
> avoid a window where a file descriptor is not marked close-on-exec.
> If the new flags or functions are not available, we fall back to
> fcntl.

Sorry, but I don't see the point in having #ifdef O_CLOEXEC code when
there is a perfectly portable way to do this using fcntl.  It leads to
more bits of code that can possibly go untested.

I also think it would actually be better to explicitly close file
descriptors before doing an exec instead of relying on people to use
the proper _cloexec call throughout gdb.


  parent reply	other threads:[~2008-12-06 15:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-06  0:39 Tom Tromey
2008-12-06  8:14 ` Eli Zaretskii
2008-12-06 15:58   ` Tom Tromey
2008-12-06 16:52     ` Daniel Jacobowitz
2008-12-06 17:05       ` Eli Zaretskii
2008-12-06 16:54     ` Eli Zaretskii
2008-12-06 15:26 ` Daniel Jacobowitz
2008-12-06 15:59   ` Tom Tromey
2008-12-06 15:42 ` Mark Kettenis [this message]
2008-12-06 22:06   ` Tom Tromey
2008-12-07 19:26     ` Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200812061540.mB6FemZD011819@brahms.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox