Skip to content

Commit

Permalink
Rewrite unix fork reopen to be compatible with ruby 2.6
Browse files Browse the repository at this point in the history
On ruby 2.6 the original code would fail specs:

lib/childprocess/unix/fork_exec_process.rb:32:in `reopen': exclusive
access mode is not supported (ArgumentError)

The documentation for reopen shows that it has two ways to call it:

  reopen(other_IO) -> ios
  reopen(path, mode [,opt]) -> ios

With ruby 2.4 and 2.5 calling reopen with a path and no mode seems to
work fine, but with ruby 2.6 this triggers the spec failure.

This commit splits the calls based on stdout/stderr availability so
that both types of reopen calls can get the required parameters. This
fixes the 2.6 specs while being backward compatible with ruby 2.4 and
2.5.
  • Loading branch information
graaff committed Apr 29, 2019
1 parent fb4d23f commit 21973e1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/childprocess/unix/fork_exec_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ def launch_process
exec_r.close
set_env

STDOUT.reopen(stdout || "/dev/null")
STDERR.reopen(stderr || "/dev/null")
if stdout
STDOUT.reopen(stdout)
else
STDOUT.reopen("/dev/null", "a+")
end
if stderr
STDERR.reopen(stderr)
else
STDERR.reopen("/dev/null", "a+")
end

if duplex?
STDIN.reopen(reader)
Expand Down

0 comments on commit 21973e1

Please sign in to comment.