From ee89543e09a2d4e4c503267c248ba7bfffa668cb Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Mon, 4 Oct 2021 14:13:47 -0700 Subject: Fix regression on Solaris after change to use realpath on loaded features After the change to use realpath on loaded features, Solaris CI started failing in test_no_curdir (which tests behavior for running ruby without a working directory). I was able to trace the problem to the following call chain: rb_call_inits->Init_Thread->Init_thread_sync->rb_provide-> get_loaded_features_index->rb_check_realpath->rb_dir_getwd_ospath-> ruby_getcwd This will throw an exception, but because Ruby hasn't been fully initialized at the point the exception is thrown, it just exits with a status of 1. The bug here is that rb_check_realpath should not raise an exception, it should return nil. This bug is hit on Solaris because Solaris uses the realpath emulation instead of native realpath, and the realpath emualation raised instead of returning nil if the mode was RB_REALPATH_CHECK. Use rb_rescue in the realpath emulation if the mode is RB_REALPATH_CHECK, and swallow any exceptions raised and return nil. --- file.c | 28 +++++++++++++++++++++++++++- test/ruby/test_process.rb | 3 --- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/file.c b/file.c index 10da703059..d60a46c350 100644 --- a/file.c +++ b/file.c @@ -4400,6 +4400,21 @@ rb_check_realpath_emulate(VALUE basedir, VALUE path, rb_encoding *origenc, enum static VALUE rb_file_join(VALUE ary); +#ifndef HAVE_REALPATH +static VALUE +rb_check_realpath_emulate_try(VALUE arg) +{ + VALUE *args = (VALUE *)arg; + return rb_check_realpath_emulate(args[0], args[1], (const rb_encoding *)args[2], RB_REALPATH_CHECK); +} + +static VALUE +rb_check_realpath_emulate_rescue(VALUE arg, VALUE exc) +{ + return Qnil; +} +#endif /* HAVE_REALPATH */ + static VALUE rb_check_realpath_internal(VALUE basedir, VALUE path, rb_encoding *origenc, enum rb_realpath_mode mode) { @@ -4466,7 +4481,18 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, rb_encoding *origenc, enum RB_GC_GUARD(unresolved_path); return resolved; #else - return rb_check_realpath_emulate(basedir, path, origenc, mode); + if (mode == RB_REALPATH_CHECK) { + VALUE arg[3]; + arg[0] = basedir; + arg[1] = path; + arg[2] = (VALUE)origenc; + + return rb_rescue(rb_check_realpath_emulate_try, (VALUE)arg, + rb_check_realpath_emulate_rescue, Qnil); + } + else { + return rb_check_realpath_emulate(basedir, path, origenc, mode); + } #endif /* HAVE_REALPATH */ } diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 98c934945c..07aa58418b 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1732,9 +1732,6 @@ class TestProcess < Test::Unit::TestCase end def test_no_curdir - if /solaris/i =~ RUBY_PLATFORM - skip "Temporary skip to avoid CI failures after commit to use realpath on required files" - end with_tmpchdir {|d| Dir.mkdir("vd") status = nil -- cgit v1.2.3