From b7fe98952af64c98bf7e82a1ea31f6223d78b6a6 Mon Sep 17 00:00:00 2001 From: Rein Henrichs Date: Thu, 5 Aug 2010 15:31:50 -0700 Subject: [#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 --- lib/facter/util/uptime.rb | 13 ++++++------- 1 file 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 -- cgit