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.
This commit is contained in:
Jeremy Evans 2021-10-04 14:13:47 -07:00
Родитель 16ce578da1
Коммит ee89543e09
2 изменённых файлов: 27 добавлений и 4 удалений

28
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 */
}

Просмотреть файл

@ -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