Skip to content

Commit

Permalink
Merge pull request rtomayko#66 from takahashim/fix-errors-187
Browse files Browse the repository at this point in the history
Fix errors in 1.8.7
  • Loading branch information
rtomayko committed Feb 17, 2015
2 parents a986ac4 + 6c95fe3 commit 009388f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lib/posix/spawn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ def fspawn(*args)
if fd?(val)
val = fd_to_io(val)
key.reopen(val)
key.close_on_exec = false
val.close_on_exec = false
if key.respond_to?(:close_on_exec=)
key.close_on_exec = false
val.close_on_exec = false
end
elsif val == :close
if key.respond_to?(:close_on_exec=)
key.close_on_exec = true
Expand All @@ -240,7 +242,12 @@ def fspawn(*args)
Process::setpgid(0, pgroup) if pgroup

# do the deed
::Kernel::exec(*argv, :close_others=>false)
if RUBY_VERSION =~ /\A1\.8/
::Kernel::exec(*argv)
else
argv_and_options = argv + [{:close_others=>false}]
::Kernel::exec(*argv_and_options)
end
ensure
exit!(127)
end
Expand Down Expand Up @@ -271,7 +278,8 @@ def system(*args)
# Returns the String output of the command.
def `(cmd)
r, w = IO.pipe
pid = spawn(*system_command_prefixes, cmd, :out => w, r => :close)
command_and_args = system_command_prefixes + [cmd, {:out => w, r => :close}]
pid = spawn(*command_and_args)

if pid > 0
w.close
Expand Down Expand Up @@ -523,7 +531,8 @@ def system_command_prefixes
def adjust_process_spawn_argv(args)
if args.size == 1 && args[0] =~ /[ |>]/
# single string with these characters means run it through the shell
[*system_command_prefixes, args[0]]
command_and_args = system_command_prefixes + [args[0]]
[*command_and_args]
elsif !args[0].respond_to?(:to_ary)
# [argv0, argv1, ...]
[[args[0], args[0]], *args[1..-1]]
Expand Down
2 changes: 1 addition & 1 deletion lib/posix/spawn/child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def self.build(*args)
else
{}
end
new(*args, { :noexec => true }.merge(options))
new(*(args + [{ :noexec => true }.merge(options)]))
end

# All data written to the child process's stdout stream as a String.
Expand Down

0 comments on commit 009388f

Please sign in to comment.