Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mutiple fixes for pipes and subprocess IO.
* Port 2015 redirect logic for popen. * Improve cloexec for subprocess IO. * Make cloexec work for any streams we can get realFileno for. ** This allows it to work for JVM-provided pipes if they can be unwrapped. See #4858
- Loading branch information
Showing
6 changed files
with
292 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,68 @@ | ||
package org.jruby.api; | ||
|
||
import org.jruby.Ruby; | ||
import org.jruby.RubyIO; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.util.io.OpenFile; | ||
import org.jruby.util.io.PosixShim; | ||
|
||
public class API { | ||
public static IRubyObject rb_sys_fail_path(Ruby runtime, String path) { | ||
throw runtime.newSystemCallError("bad path for cloexec: " + path); | ||
} | ||
|
||
public static int rb_pipe(Ruby runtime, int[] pipes) { | ||
int ret; | ||
ret = rb_cloexec_pipe(runtime, pipes); | ||
// if (ret == -1) { | ||
// if (rb_gc_for_fd(errno)) { | ||
// ret = rb_cloexec_pipe(pipes); | ||
// } | ||
// } | ||
// if (ret == 0) { | ||
// rb_update_max_fd(pipes[0]); | ||
// rb_update_max_fd(pipes[1]); | ||
// } | ||
return ret; | ||
} | ||
|
||
public static int rb_cloexec_pipe(Ruby runtime, int[] pipes) { | ||
int ret; | ||
|
||
//#if defined(HAVE_PIPE2) | ||
// static int try_pipe2 = 1; | ||
// if (try_pipe2) { | ||
// ret = runtime.posix.pippipe2(fildes, O_CLOEXEC); | ||
// if (ret != -1) | ||
// return ret; | ||
// /* pipe2 is available since Linux 2.6.27, glibc 2.9. */ | ||
// if (errno == ENOSYS) { | ||
// try_pipe2 = 0; | ||
// ret = pipe(fildes); | ||
// } | ||
// } | ||
// else { | ||
// ret = pipe(fildes); | ||
// } | ||
//#else | ||
ret = runtime.getPosix().pipe(pipes); | ||
//#endif | ||
if (ret == -1) return -1; | ||
//#ifdef __CYGWIN__ | ||
// if (ret == 0 && fildes[1] == -1) { | ||
// close(fildes[0]); | ||
// fildes[0] = -1; | ||
// errno = ENFILE; | ||
// return -1; | ||
// } | ||
//#endif | ||
rb_maygvl_fd_fix_cloexec(runtime, pipes[0]); | ||
rb_maygvl_fd_fix_cloexec(runtime, pipes[1]); | ||
return ret; | ||
} | ||
|
||
public static void rb_maygvl_fd_fix_cloexec(Ruby runtime, int fd) { | ||
PosixShim shim = new PosixShim(runtime); | ||
OpenFile.fdFixCloexec(shim, fd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.