OSDN Git Service

* java/lang/Win32Process.java: Added comment.
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Mar 2002 17:59:23 +0000 (17:59 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Mar 2002 17:59:23 +0000 (17:59 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@50536 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/include/posix.h
libjava/include/win32.h
libjava/java/io/natFileDescriptorPosix.cc
libjava/java/lang/Win32Process.java
libjava/java/net/natPlainDatagramSocketImpl.cc
libjava/java/net/natPlainSocketImpl.cc

index 1a36a3c..205b8b3 100644 (file)
@@ -1,3 +1,17 @@
+2002-03-10  Tom Tromey  <tromey@redhat.com>
+
+       * 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  <tromey@redhat.com>
 
        * verify.cc (state::NO_STACK): New constant.
index f965074..05c6ddf 100644 (file)
@@ -28,13 +28,17 @@ details.  */
 #include <unistd.h>
 #endif
 
+#include <fcntl.h>
+
 #include <gcj/cni.h>
 
 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);
+}
index c2ecbff..73eb0c8 100644 (file)
@@ -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__ */
index 5352f99..bfe0009 100644 (file)
@@ -17,7 +17,6 @@ details.  */
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/param.h>
-#include <fcntl.h>
 
 #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;
 }
 
index 00ee6b2..0af2457 100644 (file)
@@ -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
index 628ac62..81e17cc 100644 (file)
@@ -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);
 }
index 99eb80b..dd8d2cc 100644 (file)
@@ -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)