Skip to content

Commit

Permalink
Merge pull request #21 from djberg96/dragonfly
Browse files Browse the repository at this point in the history
Add Dragonfly support, remove Solaris
  • Loading branch information
djberg96 authored Jun 10, 2024
2 parents 1fe29d7 + e5e98d2 commit d33346d
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 179 deletions.
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ p Sys::Platform.linux? # => true
p Sys::Platform::ARCH # => :x86_64
```

## Solaris Notes
Users on SunOS get several extra methods:

* architecture
* platform
* hw_serial
* hw_provider
* srpc_domain
* isa_list
* dhcp_cache

Note that Solaris is essentially a dead OS at this point, so it will not be
supported going forward, and will likely be dropped in the next major release.

## BSD flavors, including OS X
Users on BSD platforms get the extra `Uname.model` method.

Expand Down
38 changes: 3 additions & 35 deletions doc/uname.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VERSION

== Class Methods
Uname.sysname
Returns the operating system name, e.g. "SunOS"
Returns the operating system name, e.g. "Darwin".

Uname.nodename
Returns the nodename. This is usually, but not necessarily, the
Expand All @@ -48,41 +48,12 @@ Uname.release

Uname.uname
Returns a struct of type UnameStruct that contains sysname, nodename,
machine, version, and release. On Solaris, it will also include
architecture and platform. On HP-UX, it will also include id_number.
machine, version, and release. On HP-UX, it will also include id_number.

MS Windows - there are many more, and different, fields in the struct.
Please see the MSDN documenation on the Win32_OperatingSystem WMI class
for a complete explanation of what each of these members mean.

== Solaris Only
Uname.architecture
Returns the instruction set architecture, e.g. "sparc"

Uname.platform
Returns the platform identifier, e.g. "SUNW,Sun-Blade-100"

Uname.isa_list
Returns a space separated string containing a list of all variant
instruction set architectures executable on the current system.

They are listed in order of performance, from best to worst.

Uname.hw_provider
Returns the name of the hardware manufacturer.

Uname.hw_serial_number
Returns the ASCII representation of the hardware-specific serial number
of the machine that executes the function.

Uname.srpc_domain
Returns the name of the Secure Remote Procedure Call domain, if any.

Uname.dhcp_cache
Returns a hexidecimal encoding, in String form, of the name of the
interface configured by boot(1M) followed by the DHCPACK reply from
the server.

== BSD Platforms Only (including OS X)
Uname.model
Returns the model type, e.g. "PowerBook5,1"
Expand All @@ -105,14 +76,11 @@ UnameStruct members mean.
None that I'm aware of. Please log any bugs on the project page at
https://github.com/djberg96/sys-uname

== Future Plans
Add additional info for Linux, Solaris, BSD.

== License
Apache-2.0

== Copyright
(C) 2002-2023 Daniel J. Berger
(C) 2002-2024 Daniel J. Berger
All Rights Reserved

== Warranty
Expand Down
14 changes: 1 addition & 13 deletions examples/uname_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,7 @@
puts 'Release: ' + Uname.release
puts 'Machine: ' + Uname.machine # May be "unknown" on Win32

if RbConfig::CONFIG['host_os'] =~ /sun|solaris/i
print "\nSolaris specific tests\n"
puts "==========================="
puts 'Architecture: ' + Uname.architecture
puts 'Platform: ' + Uname.platform
puts 'Instruction Set List: ' + Uname.isa_list.split.join(", ")
puts 'Hardware Provider: ' + Uname.hw_provider
puts 'Serial Number: ' + Uname.hw_serial_number.to_s
puts 'SRPC Domain: ' + Uname.srpc_domain # might be empty
puts 'DHCP Cache: ' + Uname.dhcp_cache # might be empty
end

if RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|bsd|mach/i
if RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|bsd|dragonfly|mach/i
print "\nBSD/OS X specific tests\n"
puts "======================="
puts 'Model: ' + Uname.model
Expand Down
9 changes: 1 addition & 8 deletions lib/sys/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class Platform
RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase.to_sym
when /linux/i
:linux
when /sunos|solaris/i
:solaris
when /bsd/i
when /bsd|dragonfly/i
:bsd
end

Expand All @@ -45,11 +43,6 @@ def self.linux?
Uname.sysname =~ /linux/i ? true : false
end

# Returns whether or not you're on Solaris
def self.solaris?
Uname.sysname =~ /sunos|solaris/i ? true : false
end

# Returns whether or not you're on any BSD platform
def self.bsd?
Uname.sysname =~ /bsd/i ? true : false
Expand Down
58 changes: 6 additions & 52 deletions lib/sys/unix/uname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class Error < StandardError; end
case RbConfig::CONFIG['host_os']
when /linux/i
BUFSIZE = 65
when /bsd/i
BUFSIZE = 32 # TODO: version method chopped
when /sunos|solaris/i
BUFSIZE = 257
when /bsd|dragonfly/i
BUFSIZE = 32
else
BUFSIZE = 256
end
Expand Down Expand Up @@ -87,20 +85,7 @@ class UnameFFIStruct < FFI::Struct

fields.push('domainname') if RbConfig::CONFIG['host_os'] =~ /linux/i
fields.push('id_number') if RbConfig::CONFIG['host_os'] =~ /hpux/i

if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
fields.push(
'architecture',
'dhcp_cache',
'hw_provider',
'hw_serial',
'isa_list',
'platform',
'srpc_domain'
)
end

fields.push('model') if RbConfig::CONFIG['host_os'] =~ /darwin|bsd/i
fields.push('model') if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i

private_constant :UnameFFIStruct

Expand All @@ -111,9 +96,7 @@ class UnameFFIStruct < FFI::Struct
# Returns a struct that contains the sysname, nodename, machine, version
# and release of your system.
#
# On OS X it will also include the model.
#
# On Solaris, it will also include the architecture and platform.
# On OS X and BSD platforms it will also include the model.
#
# On HP-UX, it will also include the id_number.
#
Expand All @@ -135,27 +118,8 @@ def self.uname
struct[:version] = utsname[:version].to_s
struct[:machine] = utsname[:machine].to_s

struct[:model] = get_model() if RbConfig::CONFIG['host_os'] =~ /darwin|bsd/i

if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
struct[:architecture] = get_si(SI_ARCHITECTURE)
struct[:platform] = get_si(SI_PLATFORM)
struct[:hw_serial] = get_si(SI_HW_SERIAL)
struct[:hw_provider] = get_si(SI_HW_PROVIDER)
struct[:srpc_domain] = get_si(SI_SRPC_DOMAIN)
struct[:isa_list] = get_si(SI_ISALIST)
struct[:dhcp_cache] = get_si(SI_DHCP_CACHE)

# FFI and Solaris don't get along so well, so we try again
struct[:sysname] = get_si(SI_SYSNAME) if struct.sysname.empty?
struct[:nodename] = get_si(SI_HOSTNAME) if struct.nodename.empty?
struct[:release] = get_si(SI_RELEASE) if struct.release.empty?
struct[:version] = get_si(SI_VERSION) if struct.version.empty?
struct[:machine] = get_si(SI_MACHINE) if struct.machine.empty?
end

struct[:model] = get_model() if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i
struct[:id_number] = utsname[:__id_number].to_s if RbConfig::CONFIG['host_os'] =~ /hpux/i

struct[:domainname] = utsname[:domainname].to_s if RbConfig::CONFIG['host_os'] =~ /linux/i

# Let's add a members method that works for testing and compatibility
Expand All @@ -174,7 +138,7 @@ def members
#
# Example:
#
# Uname.sysname # => 'SunOS'
# Uname.sysname # => 'Darwin'
#
def self.sysname
uname.sysname
Expand Down Expand Up @@ -298,15 +262,5 @@ def self.get_model
end

private_class_method :get_model

# Returns the various sysinfo information based on +flag+.
#
def self.get_si(flag)
buf = 0.chr * BUFSIZE
sysinfo(flag, buf, BUFSIZE)
buf.strip
end

private_class_method :get_si
end
end
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
require 'sys/uname'

RSpec.configure do |config|
config.filter_run_excluding(:solaris) unless RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
config.filter_run_excluding(:bsd) unless RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|macos|bsd/i
config.filter_run_excluding(:bsd) unless RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|macos|bsd|dragonfly/i
config.filter_run_excluding(:hpux) unless RbConfig::CONFIG['host_os'] =~ /hpux/i
config.filter_run_excluding(:linux) unless RbConfig::CONFIG['host_os'] =~ /linux/i
config.filter_run_excluding(:windows) unless Gem.win_platform?
Expand Down
5 changes: 0 additions & 5 deletions spec/sys_platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
expect(described_class.unix?).not_to eql(Gem.win_platform?)
end

example 'the solaris? method is defined and returns a boolean' do
expect(described_class).to respond_to(:solaris?)
expect(described_class.solaris?).to eql(true).or eql(false)
end

example 'the linux? method is defined and returns a boolean' do
expect(described_class).to respond_to(:linux?)
expect(described_class.linux?).to eql(true).or eql(false)
Expand Down
50 changes: 0 additions & 50 deletions spec/sys_uname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
expect(described_class).to respond_to(:nodename)
expect{ described_class.nodename }.not_to raise_error
expect(described_class.nodename).to be_a(String)
expect(described_class.nodename.size).to be > 0
end

example 'release singleton method works as expected' do
Expand All @@ -71,50 +70,6 @@
end
end

context 'singleton methods for Solaris only', :solaris do
example 'architecture singleton method works as expected on solaris' do
expect(described_class).to respond_to(:architecture)
expect{ described_class.architecture }.not_to raise_error
expect(described_class.architecture).to be_a(String)
end

example 'platform singleton method works as expected on solaris' do
expect(described_class).to respond_to(:platform)
expect{ described_class.platform }.not_to raise_error
expect(described_class.platform).to be_a(String)
end

example 'isa_list singleton method works as expected on solaris' do
expect(described_class).to respond_to(:isa_list)
expect{ described_class.isa_list }.not_to raise_error
expect(described_class.isa_list).to be_a(String)
end

example 'hw_provider singleton method works as expected on solaris' do
expect(described_class).to respond_to(:hw_provider)
expect{ described_class.hw_provider }.not_to raise_error
expect(described_class.hw_provider).to be_a(String)
end

example 'hw_serial singleton method works as expected on solaris' do
expect(described_class).to respond_to(:hw_serial)
expect{ described_class.hw_serial }.not_to raise_error
expect(described_class.hw_serial).to be_a(Integer)
end

example 'srpc_domain singleton method works as expected on solaris' do
expect(described_class).to respond_to(:srpc_domain)
expect{ described_class.srpc_domain }.not_to raise_error
expect(described_class.srpc_domain).to be_a(String)
end

example 'dhcp_cache singleton method works as expected on solaris' do
expect(described_class).to respond_to(:dhcp_cache)
expect{ described_class.dhcp_cache }.not_to raise_error
expect(described_class.dhcp_cache).to be_a(String)
end
end

context 'singleton methods for BSD and Darwin only', :bsd do
example 'model singleton method works as expected on BSD and Darwin' do
expect(described_class).to respond_to(:model)
Expand All @@ -137,11 +92,6 @@
expect(described_class.uname.members.sort).to eql(members.sort)
end

example 'uname struct contains expected members on solaris', :solaris do
members.push(:architecture, :platform, :hw_serial, :hw_provider, :srpc_domain, :isa_list, :dhcp_cache)
expect(described_class.uname.members.sort).to eql(members.sort)
end

example 'uname struct contains expected members on bsd or osx', :bsd do
members.push(:model)
expect(described_class.uname.members.sort).to eql(members.sort)
Expand Down

0 comments on commit d33346d

Please sign in to comment.