From 0c1fcb02b154cf1840914c4b5d96a495690376e0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 10 Mar 2002 17:59:23 +0000 Subject: [PATCH] Win32Process.java: Added comment. * java/lang/Win32Process.java: Added comment. * include/posix.h (_Jv_platform_close_on_exec): New function. Include fcntl.h. * include/win32.h (_Jv_platform_close_on_exec): New function. * java/net/natPlainSocketImpl.cc (create): Set close-on-exec flag. (accept): Likewise. * java/net/natPlainDatagramSocketImpl.cc (create): Set close-on-exec flag. * java/io/natFileDescriptorPosix.cc (open): Set close-on-exec flag. From-SVN: r50536 --- libjava/ChangeLog | 14 ++++++++++++++ libjava/include/posix.h | 12 ++++++++---- libjava/include/win32.h | 5 +++++ libjava/java/io/natFileDescriptorPosix.cc | 4 +++- libjava/java/lang/Win32Process.java | 5 +++++ libjava/java/net/natPlainDatagramSocketImpl.cc | 5 ++++- libjava/java/net/natPlainSocketImpl.cc | 6 ++++++ 7 files changed, 45 insertions(+), 6 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 1a36a3c6ec3..205b8b3aa44 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,17 @@ +2002-03-10 Tom Tromey + + * java/lang/Win32Process.java: Added comment. + * include/posix.h (_Jv_platform_close_on_exec): New function. + Include fcntl.h. + * include/win32.h (_Jv_platform_close_on_exec): New function. + * java/net/natPlainSocketImpl.cc (create): Set close-on-exec + flag. + (accept): Likewise. + * java/net/natPlainDatagramSocketImpl.cc (create): Set + close-on-exec flag. + * java/io/natFileDescriptorPosix.cc (open): Set close-on-exec + flag. + 2002-03-09 Tom Tromey * verify.cc (state::NO_STACK): New constant. diff --git a/libjava/include/posix.h b/libjava/include/posix.h index f96507405de..05c6ddfad4c 100644 --- a/libjava/include/posix.h +++ b/libjava/include/posix.h @@ -28,13 +28,17 @@ details. */ #include #endif +#include + #include extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *); extern jlong _Jv_platform_gettimeofday (); extern void _Jv_platform_initialize (void); - - - - +inline void +_Jv_platform_close_on_exec (jint fd) +{ + // Ignore errors. + fcntl (fd, F_SETFD, FD_CLOEXEC); +} diff --git a/libjava/include/win32.h b/libjava/include/win32.h index c2ecbff1ff2..73eb0c819d6 100644 --- a/libjava/include/win32.h +++ b/libjava/include/win32.h @@ -21,4 +21,9 @@ details. */ extern void _Jv_platform_initialize (void); extern jlong _Jv_platform_gettimeofday (); +void _Jv_platform_close_on_exec (jint) +{ + // Ignore. +} + #endif /* __JV_WIN32_H__ */ diff --git a/libjava/java/io/natFileDescriptorPosix.cc b/libjava/java/io/natFileDescriptorPosix.cc index 5352f99cc63..bfe00093f40 100644 --- a/libjava/java/io/natFileDescriptorPosix.cc +++ b/libjava/java/io/natFileDescriptorPosix.cc @@ -17,7 +17,6 @@ details. */ #include #include #include -#include #ifdef HAVE_SYS_IOCTL_H #define BSD_COMP /* Get FIONREAD on Solaris2. */ @@ -122,6 +121,9 @@ java::io::FileDescriptor::open (jstring path, jint jflags) sprintf (msg, "%s (%s)", buf, strerror (errno)); throw new FileNotFoundException (JvNewStringLatin1 (msg)); } + + _Jv_platform_close_on_exec (fd); + return fd; } diff --git a/libjava/java/lang/Win32Process.java b/libjava/java/lang/Win32Process.java index 00ee6b21565..0af24573eaa 100644 --- a/libjava/java/lang/Win32Process.java +++ b/libjava/java/lang/Win32Process.java @@ -21,6 +21,11 @@ import java.io.IOException; // This is entirely internal to our implementation. +// NOTE: when this is implemented, we'll need to add +// HANDLE_FLAG_INHERIT in FileDescriptor and other places, to make +// sure that file descriptors aren't inherited by the child process. +// See _Jv_platform_close_on_exec. + // This file is copied to `ConcreteProcess.java' before compilation. // Hence the class name apparently does not match the file name. final class ConcreteProcess extends Process diff --git a/libjava/java/net/natPlainDatagramSocketImpl.cc b/libjava/java/net/natPlainDatagramSocketImpl.cc index 628ac620f9a..81e17cc52a7 100644 --- a/libjava/java/net/natPlainDatagramSocketImpl.cc +++ b/libjava/java/net/natPlainDatagramSocketImpl.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2000 Free Software Foundation +/* Copyright (C) 1999, 2000, 2002 Free Software Foundation This file is part of libgcj. @@ -185,6 +185,9 @@ java::net::PlainDatagramSocketImpl::create () char* strerr = strerror (errno); throw new java::net::SocketException (JvNewStringUTF (strerr)); } + + _Jv_platform_close_on_exec (sock); + fnum = sock; fd = new java::io::FileDescriptor (sock); } diff --git a/libjava/java/net/natPlainSocketImpl.cc b/libjava/java/net/natPlainSocketImpl.cc index 99eb80b370e..dd8d2ccdd55 100644 --- a/libjava/java/net/natPlainSocketImpl.cc +++ b/libjava/java/net/natPlainSocketImpl.cc @@ -232,6 +232,9 @@ java::net::PlainSocketImpl::create (jboolean stream) char* strerr = strerror (errno); throw new java::io::IOException (JvNewStringUTF (strerr)); } + + _Jv_platform_close_on_exec (sock); + fnum = sock; fd = new java::io::FileDescriptor (sock); } @@ -374,6 +377,9 @@ java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s) new_socket = _Jv_accept (fnum, (sockaddr*) &u, &addrlen); if (new_socket < 0) goto error; + + _Jv_platform_close_on_exec (new_socket); + jbyteArray raddr; jint rport; if (u.address.sin_family == AF_INET)