This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: close-on-exec files


>>>>> "Adam" == Adam Megacz <patches@lists.megacz.com> writes:

Adam> Well, it definately won't work since Win32 doesn't have an
Adam> 'fcntl' function.

Ok.  I've made a new _Jv_platform function which sets a file
descriptor to be close-on-exec.  For POSIX it calls fcntl, for Win32
it does nothing.

Adam> Could you throw a FIXME into Win32Process.java noting that when
Adam> the class is implemented, we need to add HANDLE_FLAG_INHERIT in
Adam> natFileDescriptor.cc, and just make sure that your fcntl()'s are
Adam> #ifndef_WIN32'd out?

Ok, done.

I'm checking in the appended to the trunk and the branch.

Tom

Index: ChangeLog
from  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.

Index: include/posix.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/posix.h,v
retrieving revision 1.4
diff -u -r1.4 posix.h
--- include/posix.h 2002/03/08 01:03:56 1.4
+++ include/posix.h 2002/03/10 17:57:25
@@ -28,13 +28,17 @@
 #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: include/win32.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/win32.h,v
retrieving revision 1.4
diff -u -r1.4 win32.h
--- include/win32.h 2002/03/08 01:03:56 1.4
+++ include/win32.h 2002/03/10 17:57:25
@@ -21,4 +21,9 @@
 extern void _Jv_platform_initialize (void);
 extern jlong _Jv_platform_gettimeofday ();
 
+void _Jv_platform_close_on_exec (jint)
+{
+  // Ignore.
+}
+
 #endif /* __JV_WIN32_H__ */
Index: java/lang/Win32Process.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Win32Process.java,v
retrieving revision 1.3
diff -u -r1.3 Win32Process.java
--- java/lang/Win32Process.java 2002/03/09 08:47:40 1.3
+++ java/lang/Win32Process.java 2002/03/10 17:57:25
@@ -21,6 +21,11 @@
 
 // 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: java/io/natFileDescriptorPosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFileDescriptorPosix.cc,v
retrieving revision 1.18
diff -u -r1.18 natFileDescriptorPosix.cc
--- java/io/natFileDescriptorPosix.cc 2002/03/06 23:23:34 1.18
+++ java/io/natFileDescriptorPosix.cc 2002/03/10 17:57:25
@@ -17,7 +17,6 @@
 #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 @@
       sprintf (msg, "%s (%s)", buf, strerror (errno));
       throw new FileNotFoundException (JvNewStringLatin1 (msg));
     }
+
+  _Jv_platform_close_on_exec (fd);
+
   return fd;
 }
 
Index: java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.33
diff -u -r1.33 natPlainDatagramSocketImpl.cc
--- java/net/natPlainDatagramSocketImpl.cc 2002/02/25 05:21:45 1.33
+++ java/net/natPlainDatagramSocketImpl.cc 2002/03/10 17:57:26
@@ -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 @@
       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: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.33
diff -u -r1.33 natPlainSocketImpl.cc
--- java/net/natPlainSocketImpl.cc 2002/03/09 07:56:55 1.33
+++ java/net/natPlainSocketImpl.cc 2002/03/10 17:57:26
@@ -232,6 +232,9 @@
       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 @@
   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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]