i965: Replace dup with fcntl(..., F_DUPFD_CLOEXEC, 3)
This fixes Mesa leaking open file descriptors to child processes. This is not a theoretical problem, as a terminal emulator I use actually leaks them. Here I launched it several times:
$ ls -l /proc/self/fd
total 0
lrwx------ 1 wgh wgh 64 Jun 4 16:06 0 -> /dev/pts/10
lrwx------ 1 wgh wgh 64 Jun 4 16:06 1 -> /dev/pts/10
lrwx------ 1 wgh wgh 64 Jun 4 16:06 10 -> /dev/dri/card0
lrwx------ 1 wgh wgh 64 Jun 4 16:06 2 -> /dev/pts/10
lr-x------ 1 wgh wgh 64 Jun 4 16:06 3 -> /proc/1129780/fd
lrwx------ 1 wgh wgh 64 Jun 4 16:06 8 -> /dev/dri/card0
lrwx------ 1 wgh wgh 64 Jun 4 16:06 9 -> /dev/dri/card0
This commit fixes it for me.
Mesa code has quite a few dup() calls in other places, but I decided to refrain from modifying code that I can't test, especially given that some of the code appears to have Windows support.
This has been fixed before in other places, see commits 42ed8a6c, ac6064f9, aaac913e.