File tree Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,3 @@ def new_io(name, mode = "w:utf-8")
85
85
File . new ( name , mode )
86
86
end
87
87
end
88
-
89
- def find_unused_fd
90
- Dir . entries ( "/dev/fd" ) . map ( &:to_i ) . max + 1
91
- end
Original file line number Diff line number Diff line change 193
193
map_fd_fixture = fixture __FILE__ , "map_fd.rb"
194
194
cmd = <<-EOC
195
195
f = File.open(#{ @name . inspect } , "w+")
196
- child_fd = f.fileno + 1
197
- File.open(#{ @child_fd_file . inspect } , "w") { |io| io.print child_fd }
198
- Process.exec "#{ ruby_cmd ( map_fd_fixture ) } \# {child_fd}", { child_fd => f }
196
+ File.open(#{ __FILE__ . inspect } , "r") do |io|
197
+ child_fd = io.fileno
198
+ File.open(#{ @child_fd_file . inspect } , "w") { |io| io.print child_fd }
199
+ Process.exec "#{ ruby_cmd ( map_fd_fixture ) } \# {child_fd}", { child_fd => f }
200
+ end
199
201
EOC
200
202
201
203
ruby_exe ( cmd , escape : true )
Original file line number Diff line number Diff line change @@ -706,13 +706,15 @@ def child_pids(pid)
706
706
end
707
707
708
708
it "maps the key to a file descriptor in the child that inherits the file descriptor from the parent specified by the value" do
709
- child_fd = find_unused_fd
710
- args = ruby_cmd ( fixture ( __FILE__ , "map_fd.rb" ) , args : [ child_fd . to_s ] )
711
- pid = Process . spawn ( *args , { child_fd => @io } )
712
- Process . waitpid pid
713
- @io . rewind
714
-
715
- @io . read . should == "writing to fd: #{ child_fd } "
709
+ File . open ( __FILE__ , "r" ) do |f |
710
+ child_fd = f . fileno
711
+ args = ruby_cmd ( fixture ( __FILE__ , "map_fd.rb" ) , args : [ child_fd . to_s ] )
712
+ pid = Process . spawn ( *args , { child_fd => @io } )
713
+ Process . waitpid pid
714
+ @io . rewind
715
+
716
+ @io . read . should == "writing to fd: #{ child_fd } "
717
+ end
716
718
end
717
719
end
718
720
end
You can’t perform that action at this time.
0 commit comments