diff options
author | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-01-02 04:24:42 +0000 |
---|---|---|
committer | Adrien Thebo <adrien.thebo@gmail.com> | 2011-04-01 18:19:11 -0700 |
commit | 0c4a98b2271ed5d84f2aa8783398f08502b578ee (patch) | |
tree | bbf4454e596517048a376fcff6a96814232f74e6 | |
parent | cb52b06d4ce0bc2d7b7f6dbfb8ff2a882b63d107 (diff) | |
download | facter-0c4a98b2271ed5d84f2aa8783398f08502b578ee.tar.gz facter-0c4a98b2271ed5d84f2aa8783398f08502b578ee.tar.xz facter-0c4a98b2271ed5d84f2aa8783398f08502b578ee.zip |
Re-factor. Do not use pure-Ruby file reading against "/proc/cpuinfo" and possibly any entry under "/sys" from the sysfs file system.
-rw-r--r-- | lib/facter/physicalprocessorcount.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 86d0749..144183c 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -36,8 +36,12 @@ Facter.add('physicalprocessorcount') do # # (...) # - lookup_pattern = "#{sysfs_cpu_directory}/cpu*/topology/physical_package_id" - Dir[lookup_pattern].map { |i| File.read(i).strip }.uniq.size + lookup_pattern = "#{sysfs_cpu_directory}" + + "/cpu*/topology/physical_package_id" + + Facter::Util::Resolution.exec( + "cat #{lookup_pattern}" + ).scan(/\d+/).uniq.size else # # Try to count number of CPUs using the proc file system next ... @@ -45,7 +49,9 @@ Facter.add('physicalprocessorcount') do # We assume that /proc/cpuinfo has what we need and is so then we need # to make sure that we only count unique entries ... # - File.read('/proc/cpuinfo').scan(/physical.+:\s(\d+)/).uniq.size + Facter::Util::Resolution.exec( + "grep 'physical.\\+:' /proc/cpuinfo" + ).scan(/\d+/).uniq.size end end end |