-
Enhancement
-
Resolution: Fixed
-
P3
-
6u21
-
b02
-
generic
-
generic
-
Verified
A number of CRs have made improvements to the Process.exec code in JDK7, primarily for Linux systems and these changes are beneficial on a number of platforms supported by JDK 6. There is no single CR to cover this, but refer to 6850720 and 6853336 to see how the current code came about. See 7020237 for a follow-up bug fix for Solaris 8/9.
Affected file:
src/solaris/native/java/lang/UNIXProcess_md.c
The JDK6 code is not exactly the same as JDK7 "due to the fact that the JDK7 version of the Java_java_lang_UNIXProcess_forkAndExec native function now has the ability to pass file descriptors into this routine. The JDK6 version does not support this behavior."
Diffs of JDK7 fix backported to JDK6
646a665
> int fds[3];
685,686c704,707
< if ((moveDescriptor(p->in[0], STDIN_FILENO) == -1) ||
< (moveDescriptor(p->out[1], STDOUT_FILENO) == -1))
---
> if ((moveDescriptor(p->in[0] != -1 ? p->in[0] : p->fds[0],
> STDIN_FILENO) == -1) ||
> (moveDescriptor(p->out[1]!= -1 ? p->out[1] : p->fds[1],
> STDOUT_FILENO) == -1))
694c715,716
< if (moveDescriptor(p->err[1], STDERR_FILENO) == -1)
---
> if (moveDescriptor(p->err[1] != -1 ? p->err[1] : p->fds[2],
> STDERR_FILENO) == -1)
795,798c817,818
< jboolean redirectErrorStream,
< jobject stdin_fd,
< jobject stdout_fd,
< jobject stderr_fd)
---
> jintArray std_fds,
> jboolean redirectErrorStream)
802a823
> jint *fds = NULL;
840,842c861,867
< if ((pipe(in) < 0) ||
< (pipe(out) < 0) ||
< (pipe(err) < 0) ||
---
> assert(std_fds != NULL);
> fds = (*env)->GetIntArrayElements(env, std_fds, NULL);
> if (fds == NULL) goto Catch;
>
> if ((fds[0] == -1 && pipe(in) < 0) ||
> (fds[1] == -1 && pipe(out) < 0) ||
> (fds[2] == -1 && pipe(err) < 0) ||
846a872,874
> c->fds[0] = fds[0];
> c->fds[1] = fds[1];
> c->fds[2] = fds[2];
876,878c904,906
< (*env)->SetIntField(env, stdin_fd, IO_fd_fdID, in [1]);
< (*env)->SetIntField(env, stdout_fd, IO_fd_fdID, out[0]);
< (*env)->SetIntField(env, stderr_fd, IO_fd_fdID, err[0]);
---
> fds[0] = (in [1] != -1) ? in [1] : -1;
> fds[1] = (out[0] != -1) ? out[0] : -1;
> fds[2] = (err[0] != -1) ? err[0] : -1;
902a931,933
> if (fds != NULL)
> (*env)->ReleaseIntArrayElements(env, std_fds, fds, 0);
>
Affected file:
src/solaris/native/java/lang/UNIXProcess_md.c
The JDK6 code is not exactly the same as JDK7 "due to the fact that the JDK7 version of the Java_java_lang_UNIXProcess_forkAndExec native function now has the ability to pass file descriptors into this routine. The JDK6 version does not support this behavior."
Diffs of JDK7 fix backported to JDK6
646a665
> int fds[3];
685,686c704,707
< if ((moveDescriptor(p->in[0], STDIN_FILENO) == -1) ||
< (moveDescriptor(p->out[1], STDOUT_FILENO) == -1))
---
> if ((moveDescriptor(p->in[0] != -1 ? p->in[0] : p->fds[0],
> STDIN_FILENO) == -1) ||
> (moveDescriptor(p->out[1]!= -1 ? p->out[1] : p->fds[1],
> STDOUT_FILENO) == -1))
694c715,716
< if (moveDescriptor(p->err[1], STDERR_FILENO) == -1)
---
> if (moveDescriptor(p->err[1] != -1 ? p->err[1] : p->fds[2],
> STDERR_FILENO) == -1)
795,798c817,818
< jboolean redirectErrorStream,
< jobject stdin_fd,
< jobject stdout_fd,
< jobject stderr_fd)
---
> jintArray std_fds,
> jboolean redirectErrorStream)
802a823
> jint *fds = NULL;
840,842c861,867
< if ((pipe(in) < 0) ||
< (pipe(out) < 0) ||
< (pipe(err) < 0) ||
---
> assert(std_fds != NULL);
> fds = (*env)->GetIntArrayElements(env, std_fds, NULL);
> if (fds == NULL) goto Catch;
>
> if ((fds[0] == -1 && pipe(in) < 0) ||
> (fds[1] == -1 && pipe(out) < 0) ||
> (fds[2] == -1 && pipe(err) < 0) ||
846a872,874
> c->fds[0] = fds[0];
> c->fds[1] = fds[1];
> c->fds[2] = fds[2];
876,878c904,906
< (*env)->SetIntField(env, stdin_fd, IO_fd_fdID, in [1]);
< (*env)->SetIntField(env, stdout_fd, IO_fd_fdID, out[0]);
< (*env)->SetIntField(env, stderr_fd, IO_fd_fdID, err[0]);
---
> fds[0] = (in [1] != -1) ? in [1] : -1;
> fds[1] = (out[0] != -1) ? out[0] : -1;
> fds[2] = (err[0] != -1) ? err[0] : -1;
902a931,933
> if (fds != NULL)
> (*env)->ReleaseIntArrayElements(env, std_fds, fds, 0);
>
- relates to
-
JDK-6853336 (process) disable or remove clone-exec feature (6850720)
- Resolved
-
JDK-6850720 (process) Use clone(CLONE_VM), not fork, on Linux to avoid swap exhaustion
- Resolved
-
JDK-7020237 (process) Runtime.exec uses fork instead of fork1 on Solaris 8/9 (6uX only)
- Closed
-
JDK-6988830 Integrate changes into the j2se workspace to support building of the SE-Embedded product
- Closed