sys-uname 0.8.5-x86-mingw32 → 0.9.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/doc/uname.txt CHANGED
@@ -1,127 +1,127 @@
1
- == Description
2
- A Ruby interface for getting operating system information. The name comes
3
- from the Unix 'uname' command, but this library works on Windows as well.
4
-
5
- == Synopsis
6
- require 'sys/uname'
7
- include Sys
8
-
9
- # Unix
10
- puts Uname.nodename => my_host
11
- puts Uname.version => #1 Fri Oct 24 22:43:28 MDT 2003
12
- puts Uname.sysname => Linux
13
- puts Uname.machine => i686
14
- puts Uname.release => 2.4.22-21mdk
15
-
16
- p Uname.uname => Show all UnameStruct members
17
-
18
- # Windows
19
- u = Uname.uname
20
- puts u.caption => 'Microsoft Windows XP Home Edition
21
- puts u.csd_version => 'Service Pack 2'
22
-
23
- == Constants
24
- VERSION
25
- The current version number of the sys-uname library. This is a String.
26
-
27
- == Class Methods
28
- Uname.sysname
29
- Returns the operating system name. e.g. "SunOS"
30
-
31
- Uname.nodename
32
- Returns the nodename. This is usually, but not necessarily, the
33
- same as the system's hostname.
34
-
35
- You cannot currently set the nodename (root or otherwise). This may
36
- be added in a future release.
37
-
38
- Uname.machine
39
- Returns the machine hardware type. e.g. "i686"
40
-
41
- Uname.version
42
- Returns the operating system version. e.g. "5.8". In the case of MS
43
- Windows, it returns the version plus patch information, separated by
44
- a hyphen, e.g. "2915-Service Pack 2".
45
-
46
- Uname.release
47
- Returns the operating system release. e.g. "2.2.16-3"
48
-
49
- Uname.uname
50
- Returns a struct of type UnameStruct that contains sysname, nodename,
51
- machine, version, and release. On Solaris, it will also include
52
- architecture and platform. On HP-UX, it will also include id_number.
53
-
54
- MS Windows - there are many more, and different, fields in the struct.
55
- Please see the MSDN documenation on the Win32_OperatingSystem WMI class
56
- for a complete explanation of what each of these members mean.
57
-
58
- == Solaris Only
59
- Uname.architecture
60
- Returns the instruction set architecture. e.g. "sparc"
61
-
62
- Uname.platform
63
- Returns the platform identifier. e.g. "SUNW,Sun-Blade-100"
64
-
65
- Uname.isa_list
66
- Returns a space separated string containing a list of all variant
67
- instruction set architectures executable on the current system.
68
-
69
- They are listed in order of performance, from best to worst.
70
-
71
- Uname.hw_provider
72
- Returns the name of the hardware manufacturer.
73
-
74
- Uname.hw_serial_number
75
- Returns the ASCII representation of the hardware-specific serial number
76
- of the machine that executes the function.
77
-
78
- Uname.srpc_domain
79
- Returns the name of the Secure Remote Procedure Call domain, if any.
80
-
81
- Uname.dhcp_cache
82
- Returns a hexidecimal encoding, in String form, of the name of the
83
- interface configured by boot(1M) followed by the DHCPACK reply from
84
- the server.
85
-
86
- == BSD Platforms Only (including OS X)
87
- Uname.model
88
- Returns the model type, e.g. "PowerBook5,1"
89
-
90
- == HP-UX Only
91
- Uname.id
92
- Returns the id number, e.g. 234233587. This is a String, not a Fixnum.
93
-
94
- == Notes
95
- Not all of the information that you might be used to seeing with
96
- a 'uname -a' is available. This may be added in future releases,
97
- but since different implementations provide different information
98
- (via different header files) it will be a bit of a pain.
99
-
100
- Windows users - please see the MSDN documentation for the
101
- Win32_OperatingSystem class for a complete list of what each of the
102
- UnameStruct members mean.
103
-
104
- == Known Bugs
105
- None that I'm aware of. Please log any bugs on the project page at
106
- http://www.rubyforge.org/projects/sysutils.
107
-
108
- == Future Plans
109
- Add additional info for Linux, Solaris, BSD.
110
-
111
- == License
112
- Artistic 2.0
113
-
114
- == Copyright
115
- (C) 2002-2010 Daniel J. Berger
116
- All Rights Reserved
117
-
118
- == Warranty
119
- This package is provided "as is" and without any express or
120
- implied warranties, including, without limitation, the implied
121
- warranties of merchantability and fitness for a particular purpose.
122
-
123
- == Author
124
- Daniel Berger
125
-
126
- == See Also
127
- uname(1) for unix, or WMI for MS Windows.
1
+ == Description
2
+ A Ruby interface for getting operating system information. The name comes
3
+ from the Unix 'uname' command, but this library works on Windows as well.
4
+
5
+ == Synopsis
6
+ require 'sys/uname'
7
+ include Sys
8
+
9
+ # Unix
10
+ puts Uname.nodename => my_host
11
+ puts Uname.version => #1 Fri Oct 24 22:43:28 MDT 2003
12
+ puts Uname.sysname => Linux
13
+ puts Uname.machine => i686
14
+ puts Uname.release => 2.4.22-21mdk
15
+
16
+ p Uname.uname => Show all UnameStruct members
17
+
18
+ # Windows
19
+ u = Uname.uname
20
+ puts u.caption => 'Microsoft Windows XP Home Edition
21
+ puts u.csd_version => 'Service Pack 2'
22
+
23
+ == Constants
24
+ VERSION
25
+ The current version number of the sys-uname library. This is a String.
26
+
27
+ == Class Methods
28
+ Uname.sysname
29
+ Returns the operating system name. e.g. "SunOS"
30
+
31
+ Uname.nodename
32
+ Returns the nodename. This is usually, but not necessarily, the
33
+ same as the system's hostname.
34
+
35
+ You cannot currently set the nodename (root or otherwise). This may
36
+ be added in a future release.
37
+
38
+ Uname.machine
39
+ Returns the machine hardware type. e.g. "i686"
40
+
41
+ Uname.version
42
+ Returns the operating system version. e.g. "5.8". In the case of MS
43
+ Windows, it returns the version plus patch information, separated by
44
+ a hyphen, e.g. "2915-Service Pack 2".
45
+
46
+ Uname.release
47
+ Returns the operating system release. e.g. "2.2.16-3"
48
+
49
+ Uname.uname
50
+ Returns a struct of type UnameStruct that contains sysname, nodename,
51
+ machine, version, and release. On Solaris, it will also include
52
+ architecture and platform. On HP-UX, it will also include id_number.
53
+
54
+ MS Windows - there are many more, and different, fields in the struct.
55
+ Please see the MSDN documenation on the Win32_OperatingSystem WMI class
56
+ for a complete explanation of what each of these members mean.
57
+
58
+ == Solaris Only
59
+ Uname.architecture
60
+ Returns the instruction set architecture. e.g. "sparc"
61
+
62
+ Uname.platform
63
+ Returns the platform identifier. e.g. "SUNW,Sun-Blade-100"
64
+
65
+ Uname.isa_list
66
+ Returns a space separated string containing a list of all variant
67
+ instruction set architectures executable on the current system.
68
+
69
+ They are listed in order of performance, from best to worst.
70
+
71
+ Uname.hw_provider
72
+ Returns the name of the hardware manufacturer.
73
+
74
+ Uname.hw_serial_number
75
+ Returns the ASCII representation of the hardware-specific serial number
76
+ of the machine that executes the function.
77
+
78
+ Uname.srpc_domain
79
+ Returns the name of the Secure Remote Procedure Call domain, if any.
80
+
81
+ Uname.dhcp_cache
82
+ Returns a hexidecimal encoding, in String form, of the name of the
83
+ interface configured by boot(1M) followed by the DHCPACK reply from
84
+ the server.
85
+
86
+ == BSD Platforms Only (including OS X)
87
+ Uname.model
88
+ Returns the model type, e.g. "PowerBook5,1"
89
+
90
+ == HP-UX Only
91
+ Uname.id
92
+ Returns the id number, e.g. 234233587. This is a String, not a Fixnum.
93
+
94
+ == Notes
95
+ Not all of the information that you might be used to seeing with
96
+ a 'uname -a' is available. This may be added in future releases,
97
+ but since different implementations provide different information
98
+ (via different header files) it will be a bit of a pain.
99
+
100
+ Windows users - please see the MSDN documentation for the
101
+ Win32_OperatingSystem class for a complete list of what each of the
102
+ UnameStruct members mean.
103
+
104
+ == Known Bugs
105
+ None that I'm aware of. Please log any bugs on the project page at
106
+ http://www.rubyforge.org/projects/sysutils.
107
+
108
+ == Future Plans
109
+ Add additional info for Linux, Solaris, BSD.
110
+
111
+ == License
112
+ Ruby's
113
+
114
+ == Copyright
115
+ (C) 2002-2012 Daniel J. Berger
116
+ All Rights Reserved
117
+
118
+ == Warranty
119
+ This package is provided "as is" and without any express or
120
+ implied warranties, including, without limitation, the implied
121
+ warranties of merchantability and fitness for a particular purpose.
122
+
123
+ == Author
124
+ Daniel Berger
125
+
126
+ == See Also
127
+ uname(1) for unix, or WMI for MS Windows.
@@ -1,41 +1,42 @@
1
- ########################################################################
2
- # uname_test.rb
3
- #
4
- # Generic test script for general futzing. Modify as you see fit. This
5
- # should generally be run via the 'rake example' task.
6
- ########################################################################
7
- require 'sys/uname'
8
- include Sys
9
-
10
- puts "VERSION: " + Uname::VERSION
11
- puts 'Nodename: ' + Uname.nodename
12
- puts 'Sysname: ' + Uname.sysname
13
- puts 'Version: ' + Uname.version
14
- puts 'Release: ' + Uname.release
15
- puts 'Machine: ' + Uname.machine # May be "unknown" on Win32
16
-
17
- if RUBY_PLATFORM =~ /sun|solaris/i
18
- print "\nSolaris specific tests\n"
19
- puts "==========================="
20
- puts 'Architecture: ' + Uname.architecture
21
- puts 'Platform: ' + Uname.platform
22
- puts 'Instruction Set List: ' + Uname.isa_list.split.join(", ")
23
- puts 'Hardware Provider: ' + Uname.hw_provider
24
- puts 'Serial Number: ' + Uname.hw_serial_number.to_s
25
- puts 'SRPC Domain: ' + Uname.srpc_domain # might be empty
26
- puts 'DHCP Cache: ' + Uname.dhcp_cache # might be empty
27
- end
28
-
29
- if RUBY_PLATFORM =~ /powerpc|darwin|bsd|mach/i
30
- print "\nBSD/OS X specific tests\n"
31
- puts "======================="
32
- puts 'Model: ' + Uname.model
33
- end
34
-
35
- if RUBY_PLATFORM =~ /hpux/i
36
- print "\nHP-UX specific tests\n"
37
- puts "========================"
38
- puts "ID: " + Uname.id
39
- end
40
-
41
- print "\nTest finished successfully\n"
1
+ ########################################################################
2
+ # uname_test.rb
3
+ #
4
+ # Generic test script for general futzing. Modify as you see fit. This
5
+ # should generally be run via the 'rake example' task.
6
+ ########################################################################
7
+ require 'sys/uname'
8
+ require 'rbconfig'
9
+ include Sys
10
+
11
+ puts "VERSION: " + Uname::VERSION
12
+ puts 'Nodename: ' + Uname.nodename
13
+ puts 'Sysname: ' + Uname.sysname
14
+ puts 'Version: ' + Uname.version
15
+ puts 'Release: ' + Uname.release
16
+ puts 'Machine: ' + Uname.machine # May be "unknown" on Win32
17
+
18
+ if RbConfig::CONFIG['host_os'] =~ /sun|solaris/i
19
+ print "\nSolaris specific tests\n"
20
+ puts "==========================="
21
+ puts 'Architecture: ' + Uname.architecture
22
+ puts 'Platform: ' + Uname.platform
23
+ puts 'Instruction Set List: ' + Uname.isa_list.split.join(", ")
24
+ puts 'Hardware Provider: ' + Uname.hw_provider
25
+ puts 'Serial Number: ' + Uname.hw_serial_number.to_s
26
+ puts 'SRPC Domain: ' + Uname.srpc_domain # might be empty
27
+ puts 'DHCP Cache: ' + Uname.dhcp_cache # might be empty
28
+ end
29
+
30
+ if RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|bsd|mach/i
31
+ print "\nBSD/OS X specific tests\n"
32
+ puts "======================="
33
+ puts 'Model: ' + Uname.model
34
+ end
35
+
36
+ if RbConfig::CONFIG['host_os'] =~ /hpux/i
37
+ print "\nHP-UX specific tests\n"
38
+ puts "========================"
39
+ puts "ID: " + Uname.id
40
+ end
41
+
42
+ print "\nTest finished successfully\n"
@@ -0,0 +1,327 @@
1
+ require 'ffi'
2
+ require 'rbconfig'
3
+ require 'ostruct'
4
+
5
+ # The Sys module serves as a namespace only.
6
+ module Sys
7
+ # The Uname class encapsulates information about the system.
8
+ class Uname
9
+ extend FFI::Library
10
+ ffi_lib('c')
11
+
12
+ # Error raised if the uname() function fails.
13
+ class Error < StandardError; end
14
+
15
+ # The version of the sys-uname library
16
+ VERSION = '0.9.0'
17
+
18
+ # :stopdoc
19
+
20
+ # Buffer size for uname struct char arrays
21
+ case RbConfig::CONFIG['host_os']
22
+ when /linux/i
23
+ BUFSIZE = 65
24
+ when /bsd/i
25
+ BUFSIZE = 32 # TODO: version method chopped
26
+ when /sunos|solaris/i
27
+ BUFSIZE = 257
28
+ else
29
+ BUFSIZE = 256
30
+ end
31
+
32
+ attach_function :uname, [:pointer], :int
33
+
34
+ begin
35
+ attach_function :sysctl, [:pointer, :uint, :pointer, :pointer, :pointer, :size_t], :int
36
+ CTL_HW = 6 # Generic hardware/cpu
37
+ HW_MODEL = 2 # Specific machine model
38
+ rescue FFI::NotFoundError
39
+ # Ignore. Not suppored.
40
+ end
41
+
42
+ begin
43
+ attach_function :sysinfo, [:int, :pointer, :long], :long
44
+ SI_SYSNAME = 1 # OS name
45
+ SI_HOSTNAME = 2 # Node name
46
+ SI_RELEASE = 3 # Operating system release
47
+ SI_VERSION = 4 # Version field of utsname
48
+ SI_MACHINE = 5 # Machine type
49
+ SI_ARCHITECTURE = 6 # Instruction set architecture
50
+ SI_HW_SERIAL = 7 # Hardware serial number
51
+ SI_HW_PROVIDER = 8 # Hardware manufacturer
52
+ SI_SRPC_DOMAIN = 9 # Secure RPC domain
53
+ SI_PLATFORM = 513 # Platform identifier
54
+ SI_ISALIST = 514 # Supported isalist
55
+ SI_DHCP_CACHE = 515 # Kernel cached DHCPACK
56
+ rescue FFI::NotFoundError
57
+ # Ignore. Not suppored.
58
+ end
59
+
60
+ # Temporarily remove the uname method to avoid function name conflict
61
+ class << self
62
+ alias :uname_c :uname
63
+ remove_method :uname
64
+ end
65
+
66
+ class UnameFFIStruct < FFI::Struct
67
+ members = [
68
+ :sysname, [:char, BUFSIZE],
69
+ :nodename, [:char, BUFSIZE],
70
+ :release, [:char, BUFSIZE],
71
+ :version, [:char, BUFSIZE],
72
+ :machine, [:char, BUFSIZE]
73
+ ]
74
+
75
+ if RbConfig::CONFIG['host_os'] =~ /linux/i
76
+ members.push(:domainname, [:char, BUFSIZE])
77
+ end
78
+
79
+ if RbConfig::CONFIG['host_os'] =~ /hpux/i
80
+ members.push(:__id_number, [:char, BUFSIZE])
81
+ end
82
+
83
+ layout(*members)
84
+ end
85
+
86
+ fields = %w[
87
+ sysname
88
+ nodename
89
+ release
90
+ version
91
+ machine
92
+ ]
93
+
94
+ if RbConfig::CONFIG['host_os'] =~ /linux/i
95
+ fields.push('domainname')
96
+ end
97
+
98
+ if RbConfig::CONFIG['host_os'] =~ /hpux/i
99
+ fields.push('id_number')
100
+ end
101
+
102
+ if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
103
+ fields.push(
104
+ 'architecture',
105
+ 'dhcp_cache',
106
+ 'hw_provider',
107
+ 'hw_serial',
108
+ 'isa_list',
109
+ 'platform',
110
+ 'srpc_domain'
111
+ )
112
+ end
113
+
114
+ if RbConfig::CONFIG['host_os'] =~ /darwin|bsd/i
115
+ fields.push('model')
116
+ end
117
+
118
+ # :startdoc:
119
+
120
+ UnameStruct = Struct.new("UnameStruct", *fields)
121
+
122
+ # Returns a struct that contains the sysname, nodename, machine, version
123
+ # and release of your system.
124
+ #
125
+ # On OS X it will also include the model.
126
+ #
127
+ # On Solaris, it will also include the architecture and platform.
128
+ #
129
+ # On HP-UX, it will also include the id_number.
130
+ #
131
+ # Example:
132
+ #
133
+ # require 'sys/uname'
134
+ #
135
+ # p Sys::Uname.uname
136
+ #
137
+ def self.uname
138
+ utsname = UnameFFIStruct.new
139
+
140
+ if uname_c(utsname) < 0
141
+ raise Error, "uname() function call failed"
142
+ end
143
+
144
+ struct = UnameStruct.new
145
+ struct[:sysname] = utsname[:sysname].to_s
146
+ struct[:nodename] = utsname[:nodename].to_s
147
+ struct[:release] = utsname[:release].to_s
148
+ struct[:version] = utsname[:version].to_s
149
+ struct[:machine] = utsname[:machine].to_s
150
+
151
+ if RbConfig::CONFIG['host_os'] =~ /darwin|bsd/i
152
+ struct[:model] = get_model()
153
+ end
154
+
155
+ if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
156
+ struct[:architecture] = get_si(SI_ARCHITECTURE)
157
+ struct[:platform] = get_si(SI_PLATFORM)
158
+ struct[:hw_serial] = get_si(SI_HW_SERIAL)
159
+ struct[:hw_provider] = get_si(SI_HW_PROVIDER)
160
+ struct[:srpc_domain] = get_si(SI_SRPC_DOMAIN)
161
+ struct[:isa_list] = get_si(SI_ISALIST)
162
+ struct[:dhcp_cache] = get_si(SI_DHCP_CACHE)
163
+
164
+ # FFI and Solaris don't get along so well, so we try again
165
+ struct[:sysname] = get_si(SI_SYSNAME) if struct.sysname.empty?
166
+ struct[:nodename] = get_si(SI_HOSTNAME) if struct.nodename.empty?
167
+ struct[:release] = get_si(SI_RELEASE) if struct.release.empty?
168
+ struct[:version] = get_si(SI_VERSION) if struct.version.empty?
169
+ struct[:machine] = get_si(SI_MACHINE) if struct.machine.empty?
170
+ end
171
+
172
+ if RbConfig::CONFIG['host_os'] =~ /hpux/i
173
+ struct[:id_number] = utsname[:__id_number].to_s
174
+ end
175
+
176
+ if RbConfig::CONFIG['host_os'] =~ /linux/i
177
+ struct[:domainname] = utsname[:domainname].to_s
178
+ end
179
+
180
+ # Let's add a members method that works for testing and compatibility
181
+ if struct.members.nil?
182
+ struct.instance_eval(%Q{
183
+ def members
184
+ @table.keys.map{ |k| k.to_s }
185
+ end
186
+ })
187
+ end
188
+
189
+ struct.freeze
190
+ end
191
+
192
+ # Returns the name of this implementation of the operating system.
193
+ #
194
+ # Example:
195
+ #
196
+ # Uname.sysname # => 'SunOS'
197
+ #
198
+ def self.sysname
199
+ uname.sysname
200
+ end
201
+
202
+ # Returns the name of this node within the communications network to
203
+ # which this node is attached, if any. This is often, but not
204
+ # necessarily, the same as the host name.
205
+ #
206
+ # Example:
207
+ #
208
+ # Uname.nodename # => 'your_host.foo.com'
209
+ #
210
+ def self.nodename
211
+ uname.nodename
212
+ end
213
+
214
+ # Returns the current release level of your operating system.
215
+ #
216
+ # Example:
217
+ #
218
+ # Uname.release # => '2.2.16-3'
219
+ #
220
+ def self.release
221
+ uname.release
222
+ end
223
+
224
+ # Returns the current version level of your operating system.
225
+ #
226
+ # Example:
227
+ #
228
+ # Uname.version # => '5.9'
229
+ #
230
+ def self.version
231
+ uname.version
232
+ end
233
+
234
+ # Returns the machine hardware type.
235
+ #
236
+ # Example:
237
+ #
238
+ # Uname.machine # => 'i686'
239
+ #
240
+ def self.machine
241
+ uname.machine
242
+ end
243
+
244
+ if defined? :sysctl
245
+ # Returns the model type.
246
+ #
247
+ # Example:
248
+ #
249
+ # Uname.model # => 'MacBookPro5,3'
250
+ #
251
+ def self.model
252
+ uname.model
253
+ end
254
+ end
255
+
256
+ if defined? :sysinfo
257
+ # The basic instruction set architecture of the current
258
+ # system, e.g. sparc, i386, etc.
259
+ #
260
+ def self.architecture
261
+ uname.architecture
262
+ end
263
+
264
+ # The specific model of the hardware platform, e.g Sun-Blade-1500, etc.
265
+ #
266
+ def self.platform
267
+ uname.platform
268
+ end
269
+
270
+ # The string consisting of the ASCII hexidecimal encoding of the name
271
+ # of the interface configured by boot(1M) followed by the DHCPACK reply
272
+ # from the server.
273
+ #
274
+ def self.dhcp_cache
275
+ uname.dhcp_cache
276
+ end
277
+
278
+ # The variant instruction set architectures executable on the
279
+ # current system.
280
+ #
281
+ def self.isa_list
282
+ uname.isa_list
283
+ end
284
+
285
+ # The ASCII representation of the hardware-specific serial number
286
+ # of the physical machine on which the function is executed.
287
+ #
288
+ def self.hw_serial
289
+ uname.hw_serial.to_i
290
+ end
291
+
292
+ # The name of the of the hardware provider.
293
+ #
294
+ def self.hw_provider
295
+ uname.hw_provider
296
+ end
297
+
298
+ # The Secure Remote Procedure Call domain name.
299
+ #
300
+ def self.srpc_domain
301
+ uname.srpc_domain
302
+ end
303
+ end
304
+
305
+ private
306
+
307
+ # Returns the model for systems that define sysctl().
308
+ #
309
+ def self.get_model
310
+ buf = 0.chr * BUFSIZE
311
+ mib = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_HW, HW_MODEL])
312
+ size = FFI::MemoryPointer.new(:long, 1).write_int(buf.size)
313
+
314
+ sysctl(mib, 2, buf, size, nil, 0)
315
+
316
+ buf.strip
317
+ end
318
+
319
+ # Returns the various sysinfo information based on +flag+.
320
+ #
321
+ def self.get_si(flag)
322
+ buf = 0.chr * BUFSIZE
323
+ sysinfo(flag, buf, BUFSIZE)
324
+ buf.strip
325
+ end
326
+ end
327
+ end