guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Preventing file descriptor leak to execl'd processes


From: Andy Wingo
Subject: Re: Preventing file descriptor leak to execl'd processes
Date: Fri, 12 Mar 2021 22:22:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]