Project

General

Profile

Bug #20587 » repro.rb

ivoanjo (Ivo Anjo), 07/12/2024 11:31 AM

 
$liveness = true
$looping = false
liveness_check = Thread.new do
print "Is Ruby alive? (Should print every 0.1s) "
while $liveness do
print '.'
before_sleep = Time.now
$looping = true
sleep 0.1
delay = Time.now - before_sleep
puts "\n[HICCUP -- VM was probably blocked for #{delay - 0.1}s!]" if delay > 0.5
end
end
Thread.pass while !$looping

directory = ARGV.last
result = case ARGV.first.to_sym
when :readdir
d = Dir.new(directory)
print "(Opened!)"
d.children
when :fdopendir
# This one doesn't seem to work as a reproducer, the opendir for d0 seems to get reused by libc and that one already
# released the GVL
raise 'Broken?'
d0 = Dir.new(directory)
d1 = Dir.for_fd(d0.fileno)
d1.to_s
when :chdir
Dir.chdir(directory) { }
when :fchdir
d = Dir.new(directory)
print "(Opened!)"
d.chdir { }
when :chroot
begin
Dir.chroot(directory)
rescue => e
e
end
when :lstat
Dir.glob("#{directory}/*", File::FNM_DOTMATCH)
when :stat
Dir.glob("#{directory}/", File::FNM_DOTMATCH)
when :fstatat
raise 'Did not figure out this one?'
else
raise "Unknown syscall #{ARGV.first}"
end

$liveness = false
liveness_check.join

puts "\n#{result.inspect}"
(1-1/2)