[Bug #20995] Protect IO.popen
block from exiting by exception
This commit is contained in:
parent
6cf11ad76e
commit
8034e9c3d0
Notes:
git
2025-01-02 08:06:34 +00:00
2
io.c
2
io.c
@ -8038,7 +8038,7 @@ popen_finish(VALUE port, VALUE klass)
|
|||||||
if (NIL_P(port)) {
|
if (NIL_P(port)) {
|
||||||
/* child */
|
/* child */
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
rb_yield(Qnil);
|
rb_protect(rb_yield, Qnil, NULL);
|
||||||
rb_io_flush(rb_ractor_stdout());
|
rb_io_flush(rb_ractor_stdout());
|
||||||
rb_io_flush(rb_ractor_stderr());
|
rb_io_flush(rb_ractor_stderr());
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
@ -922,15 +922,29 @@ class TestProcess < Test::Unit::TestCase
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Process.respond_to?(:fork)
|
||||||
def test_popen_fork
|
def test_popen_fork
|
||||||
IO.popen("-") {|io|
|
IO.popen("-") do |io|
|
||||||
if !io
|
if !io
|
||||||
puts "fooo"
|
puts "fooo"
|
||||||
else
|
else
|
||||||
assert_equal("fooo\n", io.read)
|
assert_equal("fooo\n", io.read)
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
rescue NotImplementedError
|
end
|
||||||
|
|
||||||
|
def test_popen_fork_ensure
|
||||||
|
IO.popen("-") do |io|
|
||||||
|
if !io
|
||||||
|
STDERR.reopen(STDOUT)
|
||||||
|
raise "fooo"
|
||||||
|
else
|
||||||
|
assert_empty io.read
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue RuntimeError
|
||||||
|
abort "[Bug #20995] should not reach here"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fd_inheritance
|
def test_fd_inheritance
|
||||||
|
Loading…
x
Reference in New Issue
Block a user