Question about libjava/childproc.c
Thomas Stüfe
thomas.stuefe at gmail.com
Wed Sep 5 16:15:01 UTC 2018
Hi Alan,
On Wed, Sep 5, 2018 at 6:06 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 05/09/2018 16:45, Thomas Stüfe wrote:
>>
>> :
>>
>> My question would be, could we not - instead of straight away closing
>> the file descriptor - set them all to FD_CLOEXEC instead?
>>
> This comes up periodically but even if we do that then we still need this
> code to catch the places where FD_CLOEXEC isn't set.
Oh, I did not want to get rid of this coding, just change it like this:
@@ -109,7 +100,7 @@
int fd;
if (isAsciiDigit(dirp->d_name[0]) &&
(fd = strtol(dirp->d_name, NULL, 10)) >= from_fd + 2)
- close(fd);
+ fcntl(fc, F_SETFD, FD_CLOEXEC);
}
closedir(dp);
So, keep looping thru the open file descriptors, but instead of
closing them - which would interfere with the file descriptor
opendir() is using - just set them to FD_CLOEXEC.
That would not interfere with opendir() and we could remove the weird
workaround above, which tries to outguess the opendir() implementation
and proactivly closes file descriptors.
I did not test this though so I may be on the wrong track.
>
> Note that there a thread net-dev trying to do this for sockets. The scenario
> there seems to be someone calling fork/exec directory and not using
> ProcessBuilder. The patch under discussion is not complete but it helps.
>
> -Alan
More information about the core-libs-dev
mailing list