Backport #7358
closedWrong fd redirection on fork
Description
It seems fd redirecton only works with spawn, not with fork+exec (at least for fd 3).
% ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
#!/usr/bin/env ruby
tmp = File.new('/tmp/foo', File::CREAT | File::WRONLY)
cmd = ['echo', 'yes']
pid = Process.spawn(*cmd, 3 => tmp)
Process.wait(pid)
pid = fork do
Process.exec(*cmd, :close_others => true, 3 => tmp)
end
Process.wait(pid)
Updated by drbrain (Eric Hodel) over 11 years ago
- Status changed from Open to Rejected
=begin
If you want data to show up in ((%/tmp/foo%)), redirect stdout in the child process. Setting file descriptor 3 does nothing since ((%echo%)) makes no use of it.
#!/usr/bin/env ruby
tmp = File.new('/tmp/foo', File::CREAT | File::WRONLY)
cmd = ['echo', 'yes']
pid = Process.spawn(*cmd, out: tmp)
Process.wait(pid)
pid = fork do
Process.exec(*cmd, close_others: true, out: tmp)
end
Process.wait(pid)
=end
Updated by felipec (Felipe Contreras) over 10 years ago
That's not what I want, and yes, setting that does nothing, or should do nothing, but that's not what the command above did, it failed.
Fortunately it seems to be fixed now.
Updated by felipec (Felipe Contreras) over 10 years ago
felipec (Felipe Contreras) wrote:
That's not what I want, and yes, setting that does nothing, or should do nothing, but that's not what the command above did, it failed.
Fortunately it seems to be fixed now.
Actually, I went down to bisect where the problem was fixed, and I found it:
https://github.com/ruby/ruby/commit/2fb032b74be9f306fbd2f95d85f8352f4a6027d6
So it turns out it's fixed in Ruby v2.0, but not v1.9, so this is not "rejected", it should be "already fixed in v2.0", and maybe you would want to backport the fix.
FTR. This is the error I get before the patch:
yes
[ASYNC BUG] consume_communication_pipe: read
EBADF
ruby 2.0.0dev (2012-06-09 trunk 35968) [x86_64-linux]
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport193
- Status changed from Rejected to Assigned
- Assignee set to usa (Usaku NAKAMURA)
Updated by usa (Usaku NAKAMURA) over 6 years ago
- Status changed from Assigned to Rejected
1.9.3 is out of date
Updated by normalperson (Eric Wong) over 6 years ago
usa@garbagecollect.jp wrote:
Status changed from Assigned to Rejected
1.9.3 is out of date
Backport #7358: Wrong fd redirection on fork
https://bugs.ruby-lang.org/issues/7358#change-67435
I think we actually fixed this for 2.3 around July/August 2015
after I made r51146 to add a new test. That snowballed into a
bunch of subsequent commits to fix things that summer :)