From 40cd6d413257e840b357ddd243499b8c441b0ff0 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Tue, 8 Sep 2009 13:33:33 -0700 Subject: 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 --- lib/puppet/util/selinux.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'lib/puppet/util/selinux.rb') 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 -- cgit