summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRein Henrichs <rein@puppetlabs.com>2010-08-05 15:31:50 -0700
committerRein Henrichs <rein@puppetlabs.com>2010-08-05 15:31:50 -0700
commitb7fe98952af64c98bf7e82a1ea31f6223d78b6a6 (patch)
tree47778e63e28beeea8769f54318b4e0e9c3b312f2
parenta2bcacdc54fc9e9446bd5b084e70d60aaaeeebd2 (diff)
downloadfacter-b7fe98952af64c98bf7e82a1ea31f6223d78b6a6.tar.gz
facter-b7fe98952af64c98bf7e82a1ea31f6223d78b6a6.tar.xz
facter-b7fe98952af64c98bf7e82a1ea31f6223d78b6a6.zip
[#2330] Update uptime calculation to use /bin/cat
* Per #4466, Ruby has trouble reading files in /proc [1]. The alternative is to use `bin/cat`. * Also refactored methods to explicitly redirect standard error to /dev/null for *nix and BSD system calls. [1] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/155745
-rw-r--r--lib/facter/util/uptime.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb
index f8a17db..353ebf5 100644
--- a/lib/facter/util/uptime.rb
+++ b/lib/facter/util/uptime.rb
@@ -16,20 +16,19 @@ module Facter::Util::Uptime
private
def self.uptime_proc_uptime
- if File.exists? uptime_file
- r = File.read uptime_file
- r.split(" ").first.to_i
+ if output = `/bin/cat #{uptime_file} 2>/dev/null` and $?.success?
+ output.chomp.split(" ").first.to_i
end
end
def self.uptime_sysctl
- if (output = `#{uptime_sysctl_cmd}`) and $?.success?
+ if output = `#{uptime_sysctl_cmd} 2>/dev/null` and $?.success?
compute_uptime(Time.at(output.unpack('L').first))
end
end
def self.uptime_who_dash_b
- if (output = `#{uptime_who_cmd}`) and $?.success?
+ if output = `#{uptime_who_cmd} 2>/dev/null` and $?.success?
compute_uptime(Time.parse(output))
end
end
@@ -43,10 +42,10 @@ module Facter::Util::Uptime
end
def self.uptime_sysctl_cmd
- 'sysctl -b kern.boottime 2>/dev/null'
+ 'sysctl -b kern.boottime'
end
def self.uptime_who_cmd
- 'who -b 2>/dev/null'
+ 'who -b'
end
end