[Patch] PR 31228, Fix close-on-exec race.
David Daney
ddaney@avtrex.com
Wed Mar 21 17:34:00 GMT 2007
Tom Tromey wrote:
>>>>>> "David" == David Daney <ddaney@avtrex.com> writes:
>>>>>>
>
> David> Make the accept non-blocking, and do a select/poll on the
> David> ServerSocket. That way the accept would never block and you could use
> David> a mutex.
>
> Yeah. I hadn't thought of the accept case, thanks.
>
> David> This makes me think that ld.so is probably broken also. When we do
> David> dlopen ld.so opens the library file and does several mmaps before
> David> closing the file descriptor. These could leak out as well.
>
> Not to mention other places that libc may create fds.
>
> On some platforms fdwalk(3) can be used to make this close loop more
> efficient. There's also closefrom(3). Linux doesn't seem to have
> either of these, but Solaris does.
>
> Tom
>
How about this version?
I only tested it on x86_64-pc-linux-gnu, so there may be bugs in the
parts of the patch that are targeted at platforms that have fdwalk.
2007-03-21 David Daney <ddaney@avtrex.com)
PR libgcj/31228
* configure.ac: Add checks for getrlimit, fdwalk, readdir,
/proc/self/fd, and sys/resource.h.
* include/posix.h (_Jv_platform_close_on_exec): Remove.
* include/config.h.in: Regenerate.
* configure: Regenerate.
* gnu/java/nio/channels/natFileChannelPosix.cc (open): Remove call to
_Jv_platform_close_on_exec;
* gnu/java/net/natPlainSocketImplPosix.cc (create): Likewise.
(accept): Likewise.
* gnu/java/net/natPlainDatagramSocketImplPosix.cc (create):Likewise.
* java/lang/natPosixProcess.cc: Include dirent.h and sys/resource.h.
(closer_function): New function.
(close_all_files): New function with two alternate implementations.
(nativeSpawn): Call close_all_files. Don't set FD_CLOEXEC on pipes.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: closeall.diff.txt
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20070321/5ebb7337/attachment.txt>
More information about the Java-patches
mailing list