$OpenBSD: patch-j2se_src_solaris_native_java_lang_UNIXProcess_md_c,v 1.1 2012/03/22 18:53:16 kurt Exp $
--- j2se/src/solaris/native/java/lang/UNIXProcess_md.c.orig	Thu Mar 22 12:29:53 2012
+++ j2se/src/solaris/native/java/lang/UNIXProcess_md.c	Thu Mar 22 12:38:41 2012
@@ -257,19 +257,10 @@ Java_java_lang_UNIXProcess_waitForProcessExit(JNIEnv* 
 }
 
 #if defined(__OpenBSD__)
-/*
- * Directly call _thread_sys_closefrom() so the child process
- * doesn't reset the parrent's file descriptors to be blocking.
- * This function is only called from the child process which
- * is single threaded and about to call execvp() so it is
- * safe to bypass the threaded closefrom().
- */
-int _thread_sys_closefrom(int);
-
 static int
 closeDescriptors(void)
 {
-	return _thread_sys_closefrom(FAIL_FILENO + 1);
+	return closefrom(FAIL_FILENO + 1);
 }
 
 #elif defined(_ALLBSD_SOURCE)
@@ -534,9 +525,18 @@ execvp_usingParentPath(const char *file, const char *c
     return -1;
 }
 
-/* execvpe should have been included in the Unix standards. */
+/**
+  * 'execvpe' should have been included in the Unix standards,
+  * and is a GNU extension in glibc 2.10.
+  *
+  * JDK_execvpe is identical to execvp, except that the child environment is
+  * specified via the 3rd argument instead of being inherited from environ.
+  *
+  * This implementation of JDK_execvpe does not work if memory is shared
+  * with the parent, when using vfork(2), or clone(2) with CLONE_VM.
+  */
 static int
-execvpe(const char *file, const char *const argv[], const char *const envp[])
+JDK_execvpe(const char *file, const char *const argv[], const char *const envp[])
 {
     /* This is one of the rare times it's more portable to declare an
      * external symbol explicitly, rather than via a system header.
@@ -654,28 +654,6 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
     if (resultPid == 0) {
 	/* Child process */
 
-#ifdef __OpenBSD__
-// XXXBSD: Work-around userland pthread implementation issue.
-// Closing file descriptors will reset them to be blocking.
-// This is problematic for the parent when it attemts to use
-// the blocking fd and deadlocks. Setting them to non-blocking
-// in the child prevents the close/dup2 from resetting them.
-    {
-	int flags;
-	flags = fcntl(STDIN_FILENO, F_GETFL, NULL);
-	if (flags != -1)
-	    fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
-
-	flags = fcntl(STDOUT_FILENO, F_GETFL, NULL);
-	if (flags != -1)
-	    fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
-
-	flags = fcntl(STDERR_FILENO, F_GETFL, NULL);
-	if (flags != -1)
-	    fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
-    }
-#endif
-
 	/* Close the parent sides of the pipe.
 	   Give the child sides of the pipes the right fileno's.
 	   Closing pipe fds here is redundant, since closeDescriptors()
@@ -710,7 +688,7 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
 	if (fcntl(FAIL_FILENO, F_SETFD, FD_CLOEXEC) == -1)
 	    goto WhyCantJohnnyExec;
 
-	execvpe(argv[0], argv, envv);
+	JDK_execvpe(argv[0], argv, envv);
 
     WhyCantJohnnyExec:
 	/* We used to go to an awful lot of trouble to predict whether the
