Skip to content

Commit

Permalink
Always use 0,1,2 for stdio fileno when non-native.
Browse files Browse the repository at this point in the history
This code was originally removed in 7e024a7
to fix #2690, but childprocess was no longer able to launch
a subprocess (#4122). Until Windows has native, we need this code
in place...and may always need it for non-native setups, to keep
stdio fileno sane.

Fixes #4122.
  • Loading branch information
headius committed Sep 1, 2016
1 parent d5f6fca commit 1a977d5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -187,6 +187,14 @@ public static RubyIO prepStdio(Ruby runtime, InputStream f, Channel c, int fmode

fptr = io.getOpenFileChecked();

// If we can't use native IO, always force stdio to expected fileno.
if (!runtime.getPosix().isNative() || Platform.IS_WINDOWS) {
// Use standard stdio filenos if we're using System.in et al.
if (f == System.in) {
fptr.fd().realFileno = 0;
}
}

prepStdioEcflags(fptr, fmode);
fptr.stdio_file = f;

Expand All @@ -201,6 +209,16 @@ public static RubyIO prepStdio(Ruby runtime, OutputStream f, Channel c, int fmod

fptr = io.getOpenFileChecked();

// If we can't use native IO, always force stdio to expected fileno.
if (!runtime.getPosix().isNative() || Platform.IS_WINDOWS) {
// Use standard stdio filenos if we're using System.in et al.
if (f == System.out) {
fptr.fd().realFileno = 1;
} else if (f == System.err) {
fptr.fd().realFileno = 2;
}
}

prepStdioEcflags(fptr, fmode);
fptr.stdio_file = f;

Expand Down

0 comments on commit 1a977d5

Please sign in to comment.