Bug #4466
Files in /proc should not be read directly by Ruby
| Status: | Closed | Start date: | 08/04/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | - | |||
| Target version: | - | |||
| Keywords: | Affected Facter version: | |||
| Branch: | ||||
| Votes: | 2 |
Description
Per a thread on the dev mailing list, Ruby reads files in /proc unreliably. The current solution in some places is to use /bin/cat, for example %x{ /bin/cat /proc/uptime }, instead of using File.read or variants. We should make sure files in /proc are never read by Ruby directly.
From Paul Berry:
Correct me if I’m wrong, but it looks like the core problem is that reading from /proc files directly in Ruby is unreliable, because those files don’t always respond to select() calls the way the Ruby interpreter expects. Sadly, the Linux kernel maintainers don’t appear to have any intention of fixing this behavior (https://bugzilla.kernel.org/show_bug.cgi?id=11014), so we’re stuck with it.
There are other places in Facter that read directly from /proc. We should probably fix them too:
./lib/facter/processor.rb:14: File.readlines("/proc/cpuinfo").each do |l| ./lib/facter/selinux.rb:11: if (File.read("/proc/self/attr/current") != "kernel\0") ./lib/facter/util/ip.rb:135: bondinfo = IO.readlines("/proc/net/bonding/#{bonddev}") ./lib/facter/util/memory.rb:23: File.readlines("/proc/meminfo").each do |l| ./lib/facter/util/virtual.rb:24: txt = File.read("/proc/self/status") ./lib/facter/util/virtual.rb:47: txt = File.read("/proc/cpuinfo") ./lib/facter/util/vlans.rb:7: output = File.open('/proc/net/vlan/config').read
Related issues
History
Updated by Nan Liu over 1 year ago
cat is used as a worked around to a proc fs bug fixed in Linux 2.6.13: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/155745
Updated by Paul Nasrat over 1 year ago
- Status changed from Unreviewed to Accepted
Updated by MaxiM Basunov 10 months ago
These errors leads to reporting strings to stderr while running Puppet via cron.
Could not retrieve selinux: Invalid argument - /proc/self/attr/current
Could not retrieve selinux: Invalid argument - /proc/self/attr/current
Could not retrieve selinux: Invalid argument - /proc/self/attr/current
Could not retrieve selinux: Invalid argument - /proc/self/attr/current
Could not retrieve selinux: Invalid argument - /proc/self/attr/current
Could not retrieve selinux: Invalid argument - /proc/self/attr/current
Could not retrieve selinux: Invalid argument - /proc/self/attr/current
Some information from host and tests:
# uname -a
Linux server.lid-info.com 2.6.18-194.17.4.el5 #1 SMP Mon Oct 25 15:50:53 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS release 5.5 (Final)
# sestatus
SELinux status: disabled
# cat /proc/self/attr/current
cat: /proc/self/attr/current: Invalid argument
irb(main):001:0> File.read("/proc/self/attr/current")
Errno::EINVAL: Invalid argument - /proc/self/attr/current
from (irb):2:in `read'
from (irb):2
from :0
irb(main):001:0> %x{ /bin/cat /proc/self/attr/current }
/bin/cat: /proc/self/attr/current: Invalid argument
=> ""
So, any stderr should be ceased.
Updated by James Turnbull 3 months ago
- Status changed from Accepted to Closed
Red Hat ticket – https://bugzilla.redhat.com/show_bug.cgi?id=751214. Closing as an upstream issue.