Forum: Ruby-core [ruby-trunk - Bug #7358][Open] Wrong fd redirection on fork

1bb1c1a41b92d9f18e2890c3f6d33970?d=identicon&s=25 felipec (Felipe Contreras) (Guest)
on 2012-11-15 13:34
(Received via mailing list)
Issue #7358 has been reported by felipec (Felipe Contreras).

----------------------------------------
Bug #7358: Wrong fd redirection on fork
https://bugs.ruby-lang.org/issues/7358

Author: felipec (Felipe Contreras)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3p327


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)
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 drbrain (Eric Hodel) (Guest)
on 2012-11-17 02:40
(Received via mailing list)
Issue #7358 has been updated by drbrain (Eric Hodel).

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

----------------------------------------
Bug #7358: Wrong fd redirection on fork
https://bugs.ruby-lang.org/issues/7358#change-33005

Author: felipec (Felipe Contreras)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3p327


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)
1bb1c1a41b92d9f18e2890c3f6d33970?d=identicon&s=25 felipec (Felipe Contreras) (Guest)
on 2013-09-04 03:35
(Received via mailing list)
Issue #7358 has been updated by felipec (Felipe Contreras).


drbrain (Eric Hodel) wrote:
> =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.

That's not what I want, and yes, setting that does nothing, or *should*
do nothing, but that's now what the command above did, it failed.

Fortunately it seems to be fixed now.
----------------------------------------
Bug #7358: Wrong fd redirection on fork
https://bugs.ruby-lang.org/issues/7358#change-41593

Author: felipec (Felipe Contreras)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3p327
Backport:


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)
1bb1c1a41b92d9f18e2890c3f6d33970?d=identicon&s=25 felipec (Felipe Contreras) (Guest)
on 2013-09-08 09:23
(Received via mailing list)
Issue #7358 has been updated by felipec (Felipe Contreras).


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/2fb032b74be9f3...

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
----------------------------------------
Bug #7358: Wrong fd redirection on fork
https://bugs.ruby-lang.org/issues/7358#change-41679

Author: felipec (Felipe Contreras)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3p327
Backport:


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)
This topic is locked and can not be replied to.