Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 336863 - Rubygems and Ruby-1.9.* - operating_system.rb is being ignored.
Summary: Rubygems and Ruby-1.9.* - operating_system.rb is being ignored.
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: All Linux
: High major with 1 vote (vote)
Assignee: Gentoo Ruby Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 203706
  Show dependency tree
 
Reported: 2010-09-11 21:00 UTC by Codo
Modified: 2011-10-22 11:54 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Codo 2010-09-11 21:00:18 UTC
When using 1.9.*, gem_prelude.rb requires operating_system.rb.  When explicitly requiring rubygems (like in the gem command), the values from operating_system.rb are overriden by the rubygems library, thus ignoring it.

See:
http://www.sairyx.org/2010/09/ruby-1-9-2-rubygems-1-3-7-and-the-disappearance-of-gem-path/

Reproducible: Always

Steps to Reproduce:
1. Install ruby-1.9.2*
2. Install rubygems
3. Execute "gem environment"

Actual Results:  
installation dirs are "/usr/" instead of ""usr/local"

Expected Results:  
operating_system should override Gem::* methods defined in default.rb.

Rubygems is polluting the filesystem (and potentially overwriting files).

Portage 2.1.8.3 (default/linux/amd64/10.0/desktop, gcc-4.4.3, glibc-2.11.2-r0, 2.6.35-gentoo-r1 x86_64)
=================================================================
System uname: Linux-2.6.35-gentoo-r1-x86_64-Intel-R-_Core-TM-2_Duo_CPU_T9400_@_2.53GHz-with-gentoo-1.12.13
Timestamp of tree: Fri, 10 Sep 2010 22:30:01 +0000
ccache version 2.4 [disabled]
app-shells/bash:     4.0_p37
dev-java/java-config: 2.1.11
dev-lang/python:     2.6.5-r3, 3.1.2-r4
dev-util/ccache:     2.4-r7
dev-util/cmake:      2.8.1-r2
sys-apps/baselayout: 1.12.13
sys-apps/sandbox:    1.6-r2
sys-devel/autoconf:  2.13, 2.65
sys-devel/automake:  1.8.5-r3, 1.9.6-r3, 1.10.3, 1.11.1
sys-devel/binutils:  2.20.1-r1
sys-devel/gcc:       4.3.4, 4.4.3-r2
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.2.6b
sys-devel/make:      3.81-r2
virtual/os-headers:  2.6.30-r1
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -march=core2 -msse4.1"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/X11/xkb /usr/share/config /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe -march=core2 -msse4.1"
DISTDIR="/usr/portage/distfiles"
FEATURES="assume-digests distlocks fixpackages news parallel-fetch protect-owned sandbox sfperms strict unmerge-logs unmerge-orphans userfetch"
GENTOO_MIRRORS="/media/MyBook/public/downloads/gentoo_distfiles/ http://gentoo.virginmedia.com/"
LANG="en_GB.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="en_GB es"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"                                                                                                                                                          
PORTAGE_TMPDIR="/var/tmp"                                                                                                                                                   
PORTDIR="/usr/portage"                                                                                                                                                      
PORTDIR_OVERLAY="/var/lib/layman/kde /var/lib/layman/kde-sunset /var/lib/layman/qting-edge /var/lib/layman/ruby"                                                            
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X a52 aac acl acpi akonadi alsa amd64 apache2 berkdb bluetooth branding bzip2 cairo cdda cdparanoia cdr cleartype cli consolekit cracklib crypt css cups cxx dbus dri dts dvd dvdr emboss encode exif fam fax ffmpeg firefox firefox3 flac fortran ftp gdbm gif git glitz gnutls gphoto2 gpm gstreamer hal ibmacpi iconv ieee1394 imagemagick imap ipv6 jabber java javascript jingle jpeg kde kde4 kerberos lame laptop lcms ldap libnotify logrotate lzma mad midi mikmod mmx mmxext mng modules mp3 mp4 mpeg mudflap multilib musicbrainz mysql ncurses nls nptl nptlonly ogg opengl openmp pam pango pcre pda pdf perl phonon plasma png policykit ppds ppp pppd python qt3support qt4 rdp readline reflection ruby samba scanner sdl semantic-desktop session spell sql sse sse2 ssl startup-notification subversion svg synaptics sysfs syslog taglib tcpd threads thumbnail tiff timidity truetype unicode usb v4l v4l2 video vim-syntax vorbis webkit wifi x264 xcb xcomposite xine xml xorg xulrunner xv xvid yahoo zeroconf zip zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="mouse keyboard evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en_GB es" RUBY_TARGETS="ruby18 ruby19" USERLAND="GNU" VIDEO_CARDS="intel fglrx" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" 
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Codo 2010-09-11 21:01:41 UTC
I suggest moving/copying temporarily the contents of operating_system.rb to another file, and requiring it manually from the rubygems.rb file.

I know, it's nasty....  But, can't think of any other solution, other than fixing gem_prelude...
Comment 2 Stefano Crocco 2010-10-13 07:28:23 UTC
Wouldn't a patch replacing the line

require 'rubygems/defaults/operating_system'

in rubygems.rb (line number 1096) with 

load 'rubygems/defaults/operating_system.rb'

solve the problem?

Unless I'm mistaken, this issue is  caused by the fact that, since operating_system.rb has already been loaded when rubygems.rb is required, requiring it again from rubygems.rb has no effect, since require won't do nothing if the required file has already been loaded. load, instead, doesn't have this behaviour, and will always load the file. Using it, operating_system.rb would be loaded a second time from rubygems.rb, thus overwriting the methods defined by rubygems as it's supposed to do.

I tried applying this change to rubygems.rb on my system and a quick test seems to show it works.
Comment 3 Codo 2010-10-13 08:53:01 UTC
(In reply to comment #2)
> Wouldn't a patch replacing the line
> 
> require 'rubygems/defaults/operating_system'
> 
> in rubygems.rb (line number 1096) with 
> 
> load 'rubygems/defaults/operating_system.rb'
> 
> solve the problem?
It seems like it will.  Looking at the sources on 1.9.2-p0, the chain of calls in require and load are:
rb_load --> rb_load_internal --> rb_load_file
rb_require --> rb_require_safe --> rb_load_internal --> rb_load_file
(both from load.c)

I haven't looked really into the exact behaviour of rb_require, but I think it will work.

> Unless I'm mistaken, this issue is  caused by the fact that, since
> operating_system.rb has already been loaded when rubygems.rb is required,
> requiring it again from rubygems.rb has no effect, since require won't do
> nothing if the required file has already been loaded. load, instead, doesn't
> have this behaviour, and will always load the file. Using it,
> operating_system.rb would be loaded a second time from rubygems.rb, thus
> overwriting the methods defined by rubygems as it's supposed to do.
Indeed.  I agree as well that would be fix.

> I tried applying this change to rubygems.rb on my system and a quick test seems
> to show it works.
> 
I am patching my system now with the change (I am using 1.9.2) and will post back!
Comment 4 Hans de Graaff gentoo-dev Security 2010-11-26 09:06:37 UTC
Any further feedback from the folks who have been testing this fix? I'd like to add this fix to CVS and unmask ruby 1.9, so some additional feedback would be helpful.
Comment 5 Stefano Crocco 2010-11-26 12:25:49 UTC
I've been testing replacing require with load in line 1096 of rubygems.rb as I suggested in comment #2 since October, and everything works correctly. The only issue is that this causes two warnings due to portage_gems_dir and system_config_path being overwritten when operating_system.rb is loaded the second time. This can be solved by adding the lines

undef :portage_gems_dir rescue nil

and 

undef :system_config_path rescue nil

just before defining these methods in operating_system.rb
Comment 6 Codo 2010-11-26 12:39:21 UTC
My system is still using require (not load), but I might have hacked it somewhere else when I encountered the problem.

I suggest reading the link I attached and put in a clean install.  I'm sorry i can't break my install right now (I am working and have no time).  Good luck folks!

(I encountered the problem when executing gem install as root....)
Comment 7 Codo 2011-01-29 09:54:41 UTC
(In reply to comment #5)
> I've been testing replacing require with load in line 1096 of rubygems.rb as I
> suggested in comment #2 since October, and everything works correctly.
Stefano, I checked again and I am running with require...  Can you make it fail by switching back to 'require'?

Additionally, can you post the output of your
$ equery list rubygems
$ equery list ruby
Comment 8 Stefano Crocco 2011-01-29 11:01:32 UTC
(In reply to comment #7)
> (In reply to comment #5)
> > I've been testing replacing require with load in line 1096 of rubygems.rb as I
> > suggested in comment #2 since October, and everything works correctly.
> Stefano, I checked again and I am running with require...  Can you make it fail
> by switching back to 'require'?
> 
> Additionally, can you post the output of your
> $ equery list rubygems
> $ equery list ruby
> 

Using require instead of load, the GEM PATHS as reported by gem env is:
- /usr/lib/ruby/gems/1.9.1                                                                                                                                                                           
- /home/stefano/.gem/ruby/1.9.1

Changing it to use load, it becomes:
- /usr/local/lib/ruby/gems/1.9.1
- /home/stefano/.gem/ruby/1.9.1
- /usr/lib/ruby/gems/1.9.1

equery list rubygems gives:
[IP-] [  ] dev-ruby/rubygems-1.3.7-r4:0

equery list ruby gives
[IP-] [  ] dev-lang/ruby-1.8.7_p302:1.8
[IP-] [  ] dev-lang/ruby-1.9.2:1.9
Comment 9 James Le Cuirot gentoo-dev 2011-05-05 22:42:37 UTC
I tried changing that line to load and it doesn't make any difference. Does this still work for you, Stefano?
Comment 10 Codo 2011-05-21 14:58:55 UTC
Downgrade to dev-lang/ruby-1.9.2....

dev-lang/ruby-1.9.2-r1's got a bug....  As usual, no time, but you can check what patches are being applied.

As per the 'load' / 'require' change, it doesn't seem to matter anymore....
Comment 11 Hans de Graaff gentoo-dev Security 2011-05-24 06:05:04 UTC
It looks like newer versions of rubygems (1.7.2) no longer have operating_system.rb at all, so my plan is to patch the defaults.rb directly with support for our setup in those newer versions. That should also work in the case where rubygems is required directly, and thus fix things for ruby 1.9.
Comment 12 Hans de Graaff gentoo-dev Security 2011-06-25 14:21:20 UTC
(In reply to comment #11)
> It looks like newer versions of rubygems (1.7.2) no longer have
> operating_system.rb at all, so my plan is to patch the defaults.rb directly
> with support for our setup in those newer versions. That should also work in
> the case where rubygems is required directly, and thus fix things for ruby 1.9.

Actually these versions do still support operating_system.rb, so this needs to be tested with a newer rubygems version, and possible fixed in rubygems.
Comment 13 Alex Legler (RETIRED) archtester gentoo-dev Security 2011-08-24 17:10:36 UTC
Please try rubygems-1.8.7 (p.masked), it should fix the issue.
Comment 14 Hans de Graaff gentoo-dev Security 2011-10-22 11:54:46 UTC
This is fixed with ruby 1.9.3_rc1 which I added to the tree today in combination with a new rubygems.