mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) 8034e9c3d0
: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
This commit is contained in:
parent
c989d90754
commit
b65cea7429
3 changed files with 24 additions and 10 deletions
2
io.c
2
io.c
|
@ -8038,7 +8038,7 @@ popen_finish(VALUE port, VALUE klass)
|
|||
if (NIL_P(port)) {
|
||||
/* child */
|
||||
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_stderr());
|
||||
_exit(0);
|
||||
|
|
|
@ -922,15 +922,29 @@ class TestProcess < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_popen_fork
|
||||
IO.popen("-") {|io|
|
||||
if !io
|
||||
puts "fooo"
|
||||
else
|
||||
assert_equal("fooo\n", io.read)
|
||||
if Process.respond_to?(:fork)
|
||||
def test_popen_fork
|
||||
IO.popen("-") do |io|
|
||||
if !io
|
||||
puts "fooo"
|
||||
else
|
||||
assert_equal("fooo\n", io.read)
|
||||
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
|
||||
|
||||
def test_fd_inheritance
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 1
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 10
|
||||
#define RUBY_PATCHLEVEL 11
|
||||
|
||||
#include "ruby/version.h"
|
||||
#include "ruby/internal/abi.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue