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, UnameFFIStruct, UnameStruct

Constant Summary collapse

VERSION =

The version of the sys-uname gem.

'1.2.0'.freeze

Class Method Summary collapse

Class Method Details

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

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



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

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.



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

def self.dhcp_cache
  uname.dhcp_cache
end

.hw_providerObject

The name of the of the hardware provider.



290
291
292
# File 'lib/sys/unix/uname.rb', line 290

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.



284
285
286
# File 'lib/sys/unix/uname.rb', line 284

def self.hw_serial
  uname.hw_serial.to_i
end

.isa_listObject

The variant instruction set architectures executable on the current system.



277
278
279
# File 'lib/sys/unix/uname.rb', line 277

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.



236
237
238
# File 'lib/sys/unix/uname.rb', line 236

def self.machine
  uname.machine
end

.modelObject

Returns the model type.

Example:

Uname.model # => 'MacBookPro5,3'


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

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.



206
207
208
# File 'lib/sys/unix/uname.rb', line 206

def self.nodename
  uname.nodename
end

.platformObject

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



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

def self.platform
  uname.platform
end

.release(host = Socket.gethostname) ⇒ Object

Returns the release number, e.g. 5.1.2600.



216
217
218
# File 'lib/sys/unix/uname.rb', line 216

def self.release
  uname.release
end

.srpc_domainObject

The Secure Remote Procedure Call domain name.



296
297
298
# File 'lib/sys/unix/uname.rb', line 296

def self.srpc_domain
  uname.srpc_domain
end

.sysname(host = Socket.gethostname) ⇒ Object

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



194
195
196
# File 'lib/sys/unix/uname.rb', line 194

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.



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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/sys/unix/uname.rb', line 133

def self.uname
  utsname = UnameFFIStruct.new

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

  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

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

  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

  if RbConfig::CONFIG['host_os'] =~ /hpux/i
    struct[:id_number] = utsname[:__id_number].to_s
  end

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

  # Let's add a members method that works for testing and compatibility
  if struct.members.nil?
    struct.instance_eval(%Q{
      def members
        @table.keys.map{ |k| k.to_s }
      end
    })
  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.



226
227
228
# File 'lib/sys/unix/uname.rb', line 226

def self.version
  uname.version
end