Skip to content

Commit 647fc84

Browse files
committed
Merge pull request #474 in G/truffleruby from fix-dup-close-on-exec to master
* commit '86dadc7f325c9b8ad24998bd9b5d88097ee68ca9': Tag spuriously failing specs. Remove code for clearing the close-on-exec flag as the `dup2` function always clears that flag in the new FD. Update CHANGELOG for close-on-exec bug fixes. Remove an unnecessary guard wrapper. Reopened IO instances should always be set to close-on-exec. Dup'd IO instances should always be set to close-on-exec.
2 parents 2677d97 + 86dadc7 commit 647fc84

File tree

17 files changed

+97
-29
lines changed

17 files changed

+97
-29
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Bug fixes:
1111
* Adding missing support for the `close_others` option to `exec` and `spawn`.
1212
* Allow signal `0` to be used with `Process.kill`.
1313
* FFI::Pointer now does the correct range checks for signed and unsigned values.
14+
* Allow signal `0` to be used with `Process.kill` (#1474).
15+
* `IO#dup` now properly sets the new `IO` instance to be close-on-exec.
16+
* `IO#reopen` now properly resets the receiver to be close-on-exec.
1417

1518
Changes:
1619

lib/truffle/fcntl.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
module Fcntl
1010
F_DUPFD = Truffle::Config['platform.fcntl.F_DUPFD']
11+
F_DUPFD_CLOEXEC = Truffle::Config['platform.fcntl.F_DUPFD_CLOEXEC']
1112
F_GETFD = Truffle::Config['platform.fcntl.F_GETFD']
1213
F_GETLK = Truffle::Config['platform.fcntl.F_GETLK']
1314
F_SETFD = Truffle::Config['platform.fcntl.F_SETFD']

spec/ruby/core/dir/shared/open.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
dir.should be_kind_of(Dir)
6262
end
6363

64-
guard -> { platform_is_not :windows } do
64+
platform_is_not :windows do
6565
it 'sets the close-on-exec flag for the directory file descriptor' do
6666
Dir.send(@method, DirSpecs.mock_dir) do |dir|
6767
io = IO.for_fd(dir.fileno)

spec/ruby/core/file/reopen_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@file.read.should == @content_b
2626
end
2727

28-
it "calls #to_path to convern an Object" do
28+
it "calls #to_path to convert an Object" do
2929
@file = File.new(@name_a).reopen(mock_to_path(@name_b), "r")
3030
@file.read.should == @content_b
3131
end

spec/ruby/core/io/dup_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,12 @@
6666
it "raises IOError on closed stream" do
6767
lambda { IOSpecs.closed_io.dup }.should raise_error(IOError)
6868
end
69+
70+
it "always sets the close-on-exec flag for the new IO object" do
71+
@f.close_on_exec = true
72+
@f.dup.close_on_exec?.should == true
73+
74+
@f.close_on_exec = false
75+
@f.dup.close_on_exec?.should == true
76+
end
6977
end

spec/ruby/core/io/reopen_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@
162162
end
163163
end
164164

165+
it "always resets the close-on-exec flag to true on non-STDIO objects" do
166+
@io = new_io @name, "w"
167+
168+
@io.close_on_exec = true
169+
@io.reopen @other_name
170+
@io.close_on_exec?.should == true
171+
172+
@io.close_on_exec = false
173+
@io.reopen @other_name
174+
@io.close_on_exec?.should == true
175+
end
176+
165177
it "creates the file if it doesn't exist if the IO is opened in write mode" do
166178
@io = new_io @name, "w"
167179

@@ -294,6 +306,18 @@ def @io.to_io; flunk; end
294306
File.read(@other_name).should == "io data"
295307
end
296308

309+
it "always resets the close-on-exec flag to true on non-STDIO objects" do
310+
@other_io.close_on_exec = true
311+
@io.close_on_exec = true
312+
@io.reopen @other_io
313+
@io.close_on_exec?.should == true
314+
315+
@other_io.close_on_exec = false
316+
@io.close_on_exec = false
317+
@io.reopen @other_io
318+
@io.close_on_exec?.should == true
319+
end
320+
297321
it "may change the class of the instance" do
298322
@io.reopen @other_io
299323
@io.should be_an_instance_of(File)

spec/tags/core/process/spawn_tags.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ ci:Process.spawn redirects STDOUT to the given file if out: String
8888
ci:Process.spawn redirects STDOUT to the given file if out: [String name, String mode]
8989
ci:Process.spawn redirects STDERR to the given file if err: String
9090
fails:Process.spawn raises an Errno::EACCES or Errno::EISDIR when passed a directory
91+
fails(spurious failure):Process.spawn when passed close_others: false does not close file descriptors >= 3 in the child process if fds are set close_on_exec=false
92+
fails(spurious failure):Process.spawn when passed close_others: false closes file descriptors >= 3 in the child process because they are set close_on_exec by default
93+
fails(spurious failure):Process.spawn when passed close_others: true closes file descriptors >= 3 in the child process even if fds are set close_on_exec=false

spec/tags/core/thread/raise_tags.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fails(spurious failure):Thread#raise on a running thread can go unhandled
2+

src/main/java/org/truffleruby/platform/darwin/DarwinNativeConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public static void load(NativeConfiguration configuration, RubyContext context)
335335
configuration.config("platform.fcntl.F_GETFL", 3);
336336
configuration.config("platform.fcntl.F_SETFL", 4);
337337
configuration.config("platform.fcntl.F_DUPFD", 0);
338+
configuration.config("platform.fcntl.F_DUPFD_CLOEXEC", 67);
338339
configuration.config("platform.fcntl.F_GETFD", 1);
339340
configuration.config("platform.fcntl.F_SETFD", 2);
340341
configuration.config("platform.fcntl.FD_CLOEXEC", 1);

src/main/java/org/truffleruby/platform/linux/LinuxNativeConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public static void load(NativeConfiguration configuration, RubyContext context)
335335
configuration.config("platform.fcntl.F_GETFL", 3);
336336
configuration.config("platform.fcntl.F_SETFL", 4);
337337
configuration.config("platform.fcntl.F_DUPFD", 0);
338+
configuration.config("platform.fcntl.F_DUPFD_CLOEXEC", 1030);
338339
configuration.config("platform.fcntl.F_GETFD", 1);
339340
configuration.config("platform.fcntl.F_SETFD", 2);
340341
configuration.config("platform.fcntl.FD_CLOEXEC", 1);

0 commit comments

Comments
 (0)