Skip to content

Commit 190b017

Browse files
committed
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
1 parent 32a4545 commit 190b017

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

io.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8079,7 +8079,12 @@ ruby_popen_writer(char *const *argv, rb_pid_t *pid)
80798079
int write_pair[2];
80808080
# endif
80818081

8082-
int result = rb_cloexec_pipe(write_pair);
8082+
#ifdef HAVE_PIPE2
8083+
int result = pipe2(write_pair, O_CLOEXEC);
8084+
#else
8085+
int result = pipe(write_pair);
8086+
#endif
8087+
80838088
*pid = -1;
80848089
if (result == 0) {
80858090
# ifdef HAVE_WORKING_FORK

test/ruby/test_rubyoptions.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,27 @@ def test_crash_report_pipe
954954
end
955955
end
956956

957+
def test_crash_report_pipe_script
958+
omit "only runs on Linux" unless RUBY_PLATFORM.include?("linux")
959+
960+
Tempfile.create(["script", ".sh"]) do |script|
961+
Tempfile.create("crash_report") do |crash_report|
962+
script.write(<<~BASH)
963+
#!/usr/bin/env bash
964+
965+
cat > #{crash_report.path}
966+
BASH
967+
script.close
968+
969+
FileUtils.chmod("+x", script)
970+
971+
assert_crash_report("| #{script.path}") do
972+
assert_include(File.read(crash_report.path), "[BUG] Segmentation fault at")
973+
end
974+
end
975+
end
976+
end
977+
957978
def test_DATA
958979
Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
959980
t.puts "puts DATA.read.inspect"

0 commit comments

Comments
 (0)