[Mesa-dev] [PATCH] egl/drm, gallium: replace all calls to dup(2) with fcntl(F_DUPFD_CLOEXEC)

Matt Whitlock freedesktop at mattwhitlock.name
Sun Oct 2 03:48:10 UTC 2016


On Friday, 30 September 2016, at 2:35 pm, Emil Velikov wrote:
> On 30 September 2016 at 06:47, Matt Whitlock <freedesktop at mattwhitlock.name> wrote:
> > Without this fix, duplicated file descriptors leak into child processes.
> > See commit aaac913e901229d11a1894f6aaf646de6b1a542c for one instance
> > where the same fix was employed.
> 
> Being the author of some of these - thanks for correction.
> Out of curiosity - did you notice some of these by inspection or you
> were hit my the leak ?

Some of these occurrences of dup(2) I found by inspection (grep), but what prompted me to look for them was that I was hit by the leak. Actually, I have been noticing the leak for quite a long time — years — and finally decided to do something about it.

It's trivial to notice the leak just by launching Konsole (KDE's terminal emulator) and issuing the command:

	$ ls -Fl /proc/$$/fd

You'll get a directory listing looking like:

total 0
lrwx------ 1 mattw users 64 Oct  1 23:42 0 -> /dev/pts/6
lrwx------ 1 mattw users 64 Oct  1 23:42 1 -> /dev/pts/6
lrwx------ 1 mattw users 64 Oct  1 23:42 10 -> /dev/dri/card0
lrwx------ 1 mattw users 64 Oct  1 23:42 11 -> /dev/dri/card0
lrwx------ 1 mattw users 64 Oct  1 23:42 2 -> /dev/pts/6
lrwx------ 1 mattw users 64 Oct  1 23:42 255 -> /dev/pts/6

Notice the file descriptors pointing at /dev/dri/card0. There is no reason Bash should have this file open. Indeed, it occurs because Konsole has the device open and forks to exec the user's shell, and the duplicated DRI file descriptors come along for the ride. This no longer happens after my patch.

> As the above list, and lengthy one-line summary, indicates this
> could/should be split up a bit, even though it's quite trivial fix.
> Please do either - one per subsystem (file effectively) or egl,
> gallium/auxiliary, st/dri, st/xa & gallium/winsys ?

I have split it into five patches, which I'll send in reply to this message.


More information about the mesa-dev mailing list