diff options
| author | Jack Nagel | 2015-02-26 23:22:22 -0500 |
|---|---|---|
| committer | Jack Nagel | 2015-02-27 20:38:01 -0500 |
| commit | ab0bc5c76dfb3bda864aa3b6f375ef77f5e0277d (patch) | |
| tree | 5e4f5739e143ad0670ac6eadfc9a23820462d357 /Library/Homebrew/os | |
| parent | 7502fe06a51b0d2c54eca37d39d6fc7af3abbd62 (diff) | |
| download | homebrew-ab0bc5c76dfb3bda864aa3b6f375ef77f5e0277d.tar.bz2 | |
Add sysctl_n and sysctl_int methods to Mac hardware module
Diffstat (limited to 'Library/Homebrew/os')
| -rw-r--r-- | Library/Homebrew/os/mac/hardware.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Library/Homebrew/os/mac/hardware.rb b/Library/Homebrew/os/mac/hardware.rb index 158e928cd..40ab70e13 100644 --- a/Library/Homebrew/os/mac/hardware.rb +++ b/Library/Homebrew/os/mac/hardware.rb @@ -15,7 +15,7 @@ module MacCPUs # These methods use info spewed out by sysctl. # Look in <mach/machine.h> for decoding info. def type - @type ||= `/usr/sbin/sysctl -n hw.cputype`.to_i + @type ||= sysctl_int("hw.cputype") case @type when 7 :intel @@ -28,7 +28,7 @@ module MacCPUs def family if intel? - case @intel_family ||= `/usr/sbin/sysctl -n hw.cpufamily`.to_i + case @intel_family ||= sysctl_int("hw.cpufamily") when 0x73d67300 # Yonah: Core Solo/Duo :core when 0x426f69ef # Merom: Core 2 Duo @@ -49,7 +49,7 @@ module MacCPUs :dunno end elsif ppc? - case @ppc_family ||= `/usr/sbin/sysctl -n hw.cpusubtype`.to_i + case @ppc_family ||= sysctl_int("hw.cpusubtype") when 9 :g3 # PowerPC 750 when 10 @@ -67,11 +67,11 @@ module MacCPUs end def extmodel - @extmodel ||= `/usr/sbin/sysctl -n machdep.cpu.extmodel`.to_i + @extmodel ||= sysctl_int("machdep.cpu.extmodel") end def cores - @cores ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i + @cores ||= sysctl_int("hw.ncpu") end def bits @@ -99,7 +99,7 @@ module MacCPUs end def features - @features ||= `/usr/sbin/sysctl -n machdep.cpu.features`.split(" ").map do |s| + @features ||= sysctl_n("machdep.cpu.features").split(" ").map do |s| s.downcase.intern end end @@ -140,9 +140,15 @@ module MacCPUs def sysctl_bool(property) (@properties ||= {}).fetch(property) do - result = Utils.popen_read("/usr/sbin/sysctl", "-n", property, &:gets).to_i - # sysctl call succeded and printed 1 - @properties[property] = $?.success? && result == 1 + @properties[property] = sysctl_int(property) == 1 && $?.success? end end + + def sysctl_int(key) + sysctl_n(key).to_i + end + + def sysctl_n(key) + Utils.popen_read("/usr/sbin/sysctl", "-n", key) + end end |
