unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Marius Bakke <marius@gnu.org>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: Preventing file descriptor leak to execl'd processes
Date: Fri, 12 Mar 2021 22:22:59 +0100	[thread overview]
Message-ID: <87wnucxe18.fsf@pobox.com> (raw)
In-Reply-To: <87czwc5ijd.fsf@gnu.org> (Marius Bakke's message of "Sat, 06 Mar 2021 17:55:02 +0100")

On Sat 06 Mar 2021 17:55, Marius Bakke <marius@gnu.org> writes:

> $ ls -l /proc/self/fd
> lrwx------ 1 marius marius 64 Mar  6 17:41 0 -> /dev/pts/18
> lrwx------ 1 marius marius 64 Mar  6 17:41 1 -> /dev/pts/18
> lrwx------ 1 marius marius 64 Mar  6 17:41 2 -> /dev/pts/18
> lr-x------ 1 marius marius 64 Mar  6 17:41 3 -> /proc/9940/fd
>
> $ /tmp/test-shell -c 'ls -l /proc/self/fd'
> lrwx------ 1 marius marius 64 Mar  6 17:41 0 -> /dev/pts/18
> lrwx------ 1 marius marius 64 Mar  6 17:41 1 -> /dev/pts/18
> lrwx------ 1 marius marius 64 Mar  6 17:41 2 -> /dev/pts/18
> lr-x------ 1 marius marius 64 Mar  6 17:41 3 -> /proc/9951/fd
> lr-x------ 1 marius marius 64 Mar  6 17:41 7 -> /tmp/test-shell
>
> I've managed to work around it by setting FD_CLOEXEC on it:
>
>   (port-for-each (lambda (port)
>                    (let ((name (port-filename port))
>                          (self (car (program-arguments))))
>                      (when (and name (string=? name self))
>                        (fcntl port F_SETFD (logior FD_CLOEXEC
>                                                    (fcntl port F_GETFD)))))))
>
> But it seems heavy-handed.  Is there an easier way to access the "script
> port"?  Perhaps Guile itself should make it FD_CLOEXEC by default?

I think Guile itself should make the load port FD_CLOEXEC / O_CLOEXEC.
More broadly there are a number of file descriptors in Guile that should
be cloexec but aren't yet.  Want to make a patch for the load port ? :)

Andy



      parent reply	other threads:[~2021-03-12 21:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-06 16:55 Preventing file descriptor leak to execl'd processes Marius Bakke
2021-03-06 18:04 ` Maxime Devos
2021-03-12 21:22 ` Andy Wingo [this message]

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=87wnucxe18.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=marius@gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).