Pregunta

The code below works fine in Ruby 1.9.3 but throws a Bad file descriptor exception with Ruby 2.1.1 (even with close_on_exec set to false).

#!/usr/bin/env ruby

if ARGV.empty?
    f = open("/dev/null")
    f.close_on_exec = false if respond_to?(:close_on_exec=)
else
    f = IO.for_fd(ARGV[0].to_i)
    exit
end

exec "./client.rb", f.fileno.to_s

Output:

./client.rb:7:in `for_fd': Bad file descriptor (Errno::EBADF)
from ./client.rb:7:in `<main>'

Has anything else, besides close_on_exec, changed that I'm missing?

¿Fue útil?

Solución

Passing :close_others => false as options in addition to setting close_on_exec = false solves it. E.g.

exec "./client.rb", f.fileno.to_s, :close_others => false
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top