diff options
author | Markus Roberts <Markus@reality.com> | 2009-09-08 13:33:33 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-09-15 06:52:15 +1000 |
commit | 40cd6d413257e840b357ddd243499b8c441b0ff0 (patch) | |
tree | 40c658e1a91e3c9a42329b63871997f66a14de43 /lib/puppet/util/selinux.rb | |
parent | 630407d527905a9c874ae4b32a62849fdf6864b7 (diff) | |
download | puppet-40cd6d413257e840b357ddd243499b8c441b0ff0.tar.gz puppet-40cd6d413257e840b357ddd243499b8c441b0ff0.tar.xz puppet-40cd6d413257e840b357ddd243499b8c441b0ff0.zip |
Fix for #2605 by falling back to alternative solution to #1963
Two solutions were proposed and tested for #1963; both worked but one
(the read_nonblock solution) was used for performance reasons. This
solution does not work on older ruby implementations (1.8.1) because
read_nonblock is not available. This patch implements the alternative
fix (IO.popen) as a fallback to handles such cases.
Signed-off-by: Markus Roberts <Markus@reality.com>
Diffstat (limited to 'lib/puppet/util/selinux.rb')
-rw-r--r-- | lib/puppet/util/selinux.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index fdd40a66f..348eab7e9 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -154,14 +154,21 @@ module Puppet::Util::SELinux def read_mounts mounts = "" begin - mountfh = File.open("/proc/mounts") - # We use read_nonblock() in a loop rather than read() to work-around - # a linux kernel bug. See ticket #1963 for details. - while true - mounts += mountfh.read_nonblock(1024) + if File.instance_methods.include? "read_nonblock" + # If possible we use read_nonblock() in a loop rather than read() to work- + # a linux kernel bug. See ticket #1963 for details. + mountfh = File.open("/proc/mounts") + mounts += mountfh.read_nonblock(1024) while true + end + else + # Otherwise we shell out and let cat do it for us + mountfh = IO.popen("/bin/cat /proc/mounts") + mounts = mountfh.read end - rescue EOFError + ensure mountfh.close + rescue EOFError + # that's expected rescue return nil end |