If the home folder of the user that the Ruby interpreter is running as does not exist, then the 'gem' method will crash
with an Errno::ENOENT exception. The problem is in rubygems.rb, self.set_paths:
# only create by matching user
next if Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid
It can be fixed by replacing it with:
# only create by matching user
home_folder_uid = File::Stat.new(Gem.user_home).uid rescue nil
next if Etc.getpwuid.uid != home_folder_uid
This fix is important for Phusion Passenger. Phusion Passenger supports privilege lowering: it runs a Rails application
as the owner of environment.rb. But if environment.rb is owned by root, then Phusion Passenger will run the application
as 'nobody'.
But on many systems, the user 'nobody' has the home folder '/nonexistent', which is indeed nonexistent. The 'gem' method
crashes upon trying to stat this folder.
This problem is one of the most reported Phusion Passenger issues. It only occurs in RubyGems 1.3. |