Class: Sys::Uname

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/sys/unix/uname.rb,
lib/sys/uname.rb,
lib/sys/windows/uname.rb

Overview

The Uname class encapsulates uname (platform) information.

Defined Under Namespace

Classes: Error, UnameStruct

Constant Summary collapse

VERSION =

The version of the sys-uname gem.

'1.2.3'

Class Method Summary collapse

Class Method Details

.architecture(cpu_num = 0, host = Socket.gethostname) ⇒ Object

Returns the CPU architecture, e.g. “x86”



241
242
243
# File 'lib/sys/unix/uname.rb', line 241

def self.architecture
  uname.architecture
end

.dhcp_cacheObject

The string consisting of the ASCII hexidecimal encoding of the name of the interface configured by boot(1M) followed by the DHCPACK reply from the server.



255
256
257
# File 'lib/sys/unix/uname.rb', line 255

def self.dhcp_cache
  uname.dhcp_cache
end

.hw_providerObject

The name of the of the hardware provider.



275
276
277
# File 'lib/sys/unix/uname.rb', line 275

def self.hw_provider
  uname.hw_provider
end

.hw_serialObject

The ASCII representation of the hardware-specific serial number of the physical machine on which the function is executed.



269
270
271
# File 'lib/sys/unix/uname.rb', line 269

def self.hw_serial
  uname.hw_serial.to_i
end

.isa_listObject

The variant instruction set architectures executable on the current system.



262
263
264
# File 'lib/sys/unix/uname.rb', line 262

def self.isa_list
  uname.isa_list
end

.machine(cpu_num = 0, host = Socket.gethostname) ⇒ Object

Returns the machine hardware type. e.g. “i686”. – This may or may not return the expected value because some CPU types were unknown to the OS when the OS was originally released. It appears that MS doesn’t necessarily patch this, either.



221
222
223
# File 'lib/sys/unix/uname.rb', line 221

def self.machine
  uname.machine
end

.modelObject

Returns the model type.

Example:

Uname.model # => 'MacBookPro5,3'


232
233
234
# File 'lib/sys/unix/uname.rb', line 232

def self.model
  uname.model
end

.nodename(host = Socket.gethostname) ⇒ Object

Returns the nodename. This is usually, but not necessarily, the same as the system’s hostname.



191
192
193
# File 'lib/sys/unix/uname.rb', line 191

def self.nodename
  uname.nodename
end

.platformObject

The specific model of the hardware platform, e.g Sun-Blade-1500, etc.



247
248
249
# File 'lib/sys/unix/uname.rb', line 247

def self.platform
  uname.platform
end

.release(host = Socket.gethostname) ⇒ Object

Returns the release number, e.g. 5.1.2600.



201
202
203
# File 'lib/sys/unix/uname.rb', line 201

def self.release
  uname.release
end

.srpc_domainObject

The Secure Remote Procedure Call domain name.



281
282
283
# File 'lib/sys/unix/uname.rb', line 281

def self.srpc_domain
  uname.srpc_domain
end

.sysname(host = Socket.gethostname) ⇒ Object

Returns the operating system name, e.g. “Microsoft Windows XP Home”



179
180
181
# File 'lib/sys/unix/uname.rb', line 179

def self.sysname
  uname.sysname
end

.uname(host = Socket.gethostname) ⇒ Object

Returns a struct of type UnameStruct that contains sysname, nodename, machine, version, and release, as well as a plethora of other fields. Please see the MSDN documentation for what each of these fields mean.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/sys/unix/uname.rb', line 126

def self.uname
  utsname = UnameFFIStruct.new

  raise Error, 'uname() function call failed' if uname_c(utsname) < 0

  struct = UnameStruct.new
  struct[:sysname]  = utsname[:sysname].to_s
  struct[:nodename] = utsname[:nodename].to_s
  struct[:release]  = utsname[:release].to_s
  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[: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
  if struct.members.nil?
    struct.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
      def members
        @table.keys.map(&:to_s)
      end
    RUBY
  end

  struct.freeze
end

.version(host = Socket.gethostname) ⇒ Object

Returns the version plus patch information of the operating system, separated by a hyphen, e.g. “2915-Service Pack 2”. – The instance name is unpredictable, so we have to resort to using the ‘InstancesOf’ method to get the data we need, rather than including it as part of the connection.



211
212
213
# File 'lib/sys/unix/uname.rb', line 211

def self.version
  uname.version
end