summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2026-03-24 14:13:07 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2026-03-24 14:49:12 +0900
commit83637aea6ea726f7fc4c17e56ac60c289e2d98db (patch)
treef8a3bc36ceee05fb3f092a5b06b429a8d71d8ce0
parent75de62b79bb1af97a905b2dce0a8cf6ffd64b083 (diff)
merge revision(s) 190b017fc6c21ff7b61c2b5ece0294785e4a4ca2: [Backport #21703]
[PATCH] Don't use non blocking pipes for RUBY_CRASH_REPORT [Bug #21703] RUBY_CRASH_REPORT does not work in some cases when shelling out on Linux. For example, given the following shell script dump.sh: #!/usr/bin/env bash cat > /tmp/crash And we see it fails like this: $ RUBY_CRASH_REPORT="|dump.sh" ruby -rfiddle -e "Fiddle::Pointer.new(1, 10)[0]" cat: -: Resource temporarily unavailable
-rw-r--r--io.c7
-rw-r--r--test/ruby/test_rubyoptions.rb21
-rw-r--r--version.h2
3 files changed, 28 insertions, 2 deletions
diff --git a/io.c b/io.c
index 70d6ed0b2c..1d4e94eb23 100644
--- a/io.c
+++ b/io.c
@@ -8051,7 +8051,12 @@ ruby_popen_writer(char *const *argv, rb_pid_t *pid)
int write_pair[2];
# endif
- int result = rb_cloexec_pipe(write_pair);
+#ifdef HAVE_PIPE2
+ int result = pipe2(write_pair, O_CLOEXEC);
+#else
+ int result = pipe(write_pair);
+#endif
+
*pid = -1;
if (result == 0) {
# ifdef HAVE_WORKING_FORK
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index 8697092bbc..9dfca44d3b 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -956,6 +956,27 @@ class TestRubyOptions < Test::Unit::TestCase
end
end
+ def test_crash_report_pipe_script
+ omit "only runs on Linux" unless RUBY_PLATFORM.include?("linux")
+
+ Tempfile.create(["script", ".sh"]) do |script|
+ Tempfile.create("crash_report") do |crash_report|
+ script.write(<<~BASH)
+ #!/usr/bin/env bash
+
+ cat > #{crash_report.path}
+ BASH
+ script.close
+
+ FileUtils.chmod("+x", script)
+
+ assert_crash_report("| #{script.path}") do
+ assert_include(File.read(crash_report.path), "[BUG] Segmentation fault at")
+ end
+ end
+ end
+ end
+
def test_DATA
Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
t.puts "puts DATA.read.inspect"
diff --git a/version.h b/version.h
index 55aff5818d..26194701aa 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 10
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 197
+#define RUBY_PATCHLEVEL 198
#include "ruby/version.h"
#include "ruby/internal/abi.h"