blob: 4a5c332d618922e5ab5282b3c118bd144c70b0c4 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001#
2# This is not a runnable script, it is a Perl module, a collection of variables, subroutines, etc.
3# To get help about exported variables and subroutines, execute the following command:
4#
5# perldoc Uname.pm
6#
7# or see POD (Plain Old Documentation) embedded to the source...
8#
9#
10#//===----------------------------------------------------------------------===//
11#//
Chandler Carruth57b08b02019-01-19 10:56:40 +000012#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
13#// See https://llvm.org/LICENSE.txt for license information.
14#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Jim Cownie5e8470a2013-09-27 10:38:44 +000015#//
16#//===----------------------------------------------------------------------===//
17#
18
19package Uname;
20
21use strict;
22use warnings;
23use warnings::register;
24use Exporter;
25
26use POSIX;
27use File::Glob ":glob";
28use Net::Domain qw{};
29
30# Following code does not work with Perl 5.6 on Linux* OS and Windows* OS:
31#
32# use if $^O eq "darwin", tools => qw{};
33#
34# The workaround for Perl 5.6:
35#
36BEGIN {
37 if ( $^O eq "darwin" or $^O eq "linux" ) {
38 require tools;
39 import tools;
40 }; # if
41 if ( $^O eq "MSWin32" ) {
42 require Win32;
43 }; # if
44}; # BEGIN
45
46my $mswin = qr{\A(?:MSWin32|Windows_NT)\z};
47
48my @posix = qw{ kernel_name fqdn kernel_release kernel_version machine };
49 # Properties supported by POSIX::uname().
50my @linux =
51 qw{ processor hardware_platform operating_system };
52 # Properties reported by uname in Linux* OS.
53my @base = ( @posix, @linux );
54 # Base properties.
55my @aux =
56 (
57 qw{ host_name domain_name },
58 map( "operating_system_$_", qw{ name release codename description } )
59 );
Alp Toker8f2d3f02014-02-24 10:40:15 +000060 # Auxiliary properties.
Jim Cownie5e8470a2013-09-27 10:38:44 +000061my @all = ( @base, @aux );
62 # All the properties.
63my @meta = qw{ base_names all_names value };
64 # Meta functions.
65
66our $VERSION = "0.07";
67our @ISA = qw{ Exporter };
68our @EXPORT = qw{};
69our @EXPORT_OK = ( @all, @meta );
70our %EXPORT_TAGS =
71 (
72 base => [ @base ],
73 all => [ @all ],
74 meta => [ @meta ],
75 );
76
77my %values;
78 # Hash of values. Some values are strings, some may be references to code which should be
79 # evaluated to get real value. This trick is implemented because call to Net::Domain::hostfqdn()
80 # is relatively slow.
81
82# Get values from POSIX::uname().
83@values{ @posix } = POSIX::uname();
84
85# On some systems POSIX::uname() returns "short" node name (without domain name). To be consistent
86# on all systems, we will get node name from alternative source.
87if ( $^O =~ m/cygwin/i ) {
88 # Function from Net::Domain module works well, but on Cygwin it prints to
89 # stderr "domainname: not found". So we will use environment variables for now.
90 $values{ fqdn } = lc( $ENV{ COMPUTERNAME } . "." . $ENV{ USERDNSDOMAIN } );
91} else {
92 # On systems other than Cygwin, let us use Net::Domain::hostfqdn(), but do it only node name
93 # is really requested.
94 $values{ fqdn } =
95 sub {
96 my $fqdn = Net::Domain::hostfqdn(); # "fqdn" stands for "fully qualified doamain name".
97 # On some systems POSIX::uname() and Net::Domain::hostfqdn() reports different names.
98 # Let us issue a warning if they significantly different. Names are insignificantly
99 # different if POSIX::uname() matches the beginning of Net::Domain::hostfqdn().
100 if (
101 $fqdn eq substr( $fqdn, 0, length( $fqdn ) )
102 &&
103 (
104 length( $fqdn ) == length( $fqdn )
105 ||
106 substr( $fqdn, length( $fqdn ), 1 ) eq "."
107 )
108 ) {
109 # Ok.
110 } else {
111 warnings::warnif(
112 "POSIX::uname() and Net::Domain::hostfqdn() reported different names: " .
113 "\"$values{ fqdn }\" and \"$fqdn\" respectively\n"
114 );
115 }; # if
116 return $fqdn;
117 }; # sub
118}; # if
119
120if ( $^O =~ $mswin ) {
121 if (
122 $values{ machine } =~ m{\A(?:x86|[56]86)\z}
123 and
124 exists( $ENV{ PROCESSOR_ARCHITECTURE } ) and $ENV{ PROCESSOR_ARCHITECTURE } eq "x86"
125 and
126 exists( $ENV{ PROCESSOR_ARCHITEW6432 } )
127 ) {
128 if ( $ENV{ PROCESSOR_ARCHITEW6432 } eq "AMD64" ) {
129 $values{ machine } = "x86_64";
130 }; # if
131 }; # if
132}; # if
133
134# Some values are not returned by POSIX::uname(), let us compute them.
135
136# processor.
137$values{ processor } = $values{ machine };
138
139# hardware_platform.
140if ( 0 ) {
Joerg Sonnenberger40252ce2015-09-21 19:42:05 +0000141} elsif ( $^O eq "linux" or $^O eq "freebsd" or $^O eq "netbsd" ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000142 if ( 0 ) {
143 } elsif ( $values{ machine } =~ m{\Ai[3456]86\z} ) {
144 $values{ hardware_platform } = "i386";
Alp Toker763b9392014-02-28 09:42:41 +0000145 } elsif ( $values{ machine } =~ m{\A(x86_64|amd64)\z} ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000146 $values{ hardware_platform } = "x86_64";
Jim Cownie181b4bb2013-12-23 17:28:57 +0000147 } elsif ( $values{ machine } =~ m{\Aarmv7\D*\z} ) {
148 $values{ hardware_platform } = "arm";
Andrey Churbanovd1c55042015-01-19 18:29:35 +0000149 } elsif ( $values{ machine } =~ m{\Appc64le\z} ) {
150 $values{ hardware_platform } = "ppc64le";
Jim Cownie3051f972014-08-07 10:12:54 +0000151 } elsif ( $values{ machine } =~ m{\Appc64\z} ) {
152 $values{ hardware_platform } = "ppc64";
Andrey Churbanovcbda8682015-01-13 14:43:35 +0000153 } elsif ( $values{ machine } =~ m{\Aaarch64\z} ) {
154 $values{ hardware_platform } = "aarch64";
Sylvestre Ledrucd9d3742016-12-08 09:22:24 +0000155 } elsif ( $values{ machine } =~ m{\Amips64\z} ) {
156 $values{ hardware_platform } = "mips64";
157 } elsif ( $values{ machine } =~ m{\Amips\z} ) {
158 $values{ hardware_platform } = "mips";
Jim Cownie5e8470a2013-09-27 10:38:44 +0000159 } else {
160 die "Unsupported machine (\"$values{ machine }\") returned by POSIX::uname(); stopped";
161 }; # if
162} elsif ( $^O eq "darwin" ) {
163 if ( 0 ) {
164 } elsif ( $values{ machine } eq "x86" or $values{ machine } eq "i386" ) {
165 $values{ hardware_platform } =
166 sub {
167 my $platform = "i386";
168 # Some OSes on Intel(R) 64 still reports "i386" machine. Verify it by using
169 # the value returned by 'sysctl -n hw.optional.x86_64'. On Intel(R) 64-bit systems the
170 # value == 1; on 32-bit systems the 'hw.optional.x86_64' property either does not exist
171 # or the value == 0. The path variable does not contain a path to sysctl when
172 # started by crontab.
173 my $sysctl = ( which( "sysctl" ) or "/usr/sbin/sysctl" );
174 my $output;
175 debug( "Executing $sysctl..." );
176 execute( [ $sysctl, "-n", "hw.optional.x86_64" ], -stdout => \$output, -stderr => undef );
177 chomp( $output );
178 if ( 0 ) {
179 } elsif ( "$output" eq "" or "$output" eq "0" ) {
180 $platform = "i386";
181 } elsif ( "$output" eq "1" ) {
182 $platform = "x86_64";
183 } else {
184 die "Unsupported value (\"$output\") returned by \"$sysctl -n hw.optional.x86_64\"; stopped";
185 }; # if
186 return $platform;
187 }; # sub {
188 } elsif ( $values{ machine } eq "x86_64" ) {
189 # Some OS X* versions report "x86_64".
190 $values{ hardware_platform } = "x86_64";
191 } else {
192 die "Unsupported machine (\"$values{ machine }\") returned by POSIX::uname(); stopped";
193 }; # if
194} elsif ( $^O =~ $mswin ) {
195 if ( 0 ) {
196 } elsif ( $values{ machine } =~ m{\A(?:x86|[56]86)\z} ) {
197 $values{ hardware_platform } = "i386";
198 } elsif ( $values{ machine } eq "x86_64" or $values{ machine } eq "amd64" ) {
199 # ActivePerl for IA-32 architecture returns "x86_64", while ActivePerl for Intel(R) 64 returns "amd64".
200 $values{ hardware_platform } = "x86_64";
201 } else {
202 die "Unsupported machine (\"$values{ machine }\") returned by POSIX::uname(); stopped";
203 }; # if
204} elsif ( $^O eq "cygwin" ) {
205 if ( 0 ) {
206 } elsif ( $values{ machine } =~ m{\Ai[3456]86\z} ) {
207 $values{ hardware_platform } = "i386";
208 } elsif ( $values{ machine } eq "x86_64" ) {
209 $values{ hardware_platform } = "x86_64";
210 } else {
211 die "Unsupported machine (\"$values{ machine }\") returned by POSIX::uname(); stopped";
212 }; # if
213} else {
214 die "Unsupported OS (\"$^O\"); stopped";
215}; # if
216
217# operating_system.
218if ( 0 ) {
219} elsif ( $values{ kernel_name } eq "Linux" ) {
220 $values{ operating_system } = "GNU/Linux";
Alp Toker8f2d3f02014-02-24 10:40:15 +0000221 my $release; # Name of chosen "*-release" file.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000222 my $bulk; # Content of release file.
223 # On Ubuntu, lsb-release is quite informative, e. g.:
224 # DISTRIB_ID=Ubuntu
225 # DISTRIB_RELEASE=9.04
226 # DISTRIB_CODENAME=jaunty
227 # DISTRIB_DESCRIPTION="Ubuntu 9.04"
228 # Try lsb-release first. But on some older systems lsb-release is not informative.
229 # It may contain just one line:
230 # LSB_VERSION="1.3"
231 $release = "/etc/lsb-release";
232 if ( -e $release ) {
233 $bulk = read_file( $release );
234 } else {
235 $bulk = "";
236 }; # if
237 if ( $bulk =~ m{^DISTRIB_} ) {
238 # Ok, this lsb-release is informative.
239 $bulk =~ m{^DISTRIB_ID\s*=\s*(.*?)\s*$}m
240 or runtime_error( "$release: There is no DISTRIB_ID:", $bulk, "(eof)" );
241 $values{ operating_system_name } = $1;
242 $bulk =~ m{^DISTRIB_RELEASE\s*=\s*(.*?)\s*$}m
243 or runtime_error( "$release: There is no DISTRIB_RELEASE:", $bulk, "(eof)" );
244 $values{ operating_system_release } = $1;
245 $bulk =~ m{^DISTRIB_CODENAME\s*=\s*(.*?)\s*$}m
246 or runtime_error( "$release: There is no DISTRIB_CODENAME:", $bulk, "(eof)" );
247 $values{ operating_system_codename } = $1;
248 $bulk =~ m{^DISTRIB_DESCRIPTION\s*="?\s*(.*?)"?\s*$}m
249 or runtime_error( "$release: There is no DISTRIB_DESCRIPTION:", $bulk, "(eof)" );
250 $values{ operating_system_description } = $1;
251 } else {
252 # Oops. lsb-release is missed or not informative. Try other *-release files.
253 $release = "/etc/system-release";
254 if ( not -e $release ) { # Use /etc/system-release" if such file exists.
255 # Otherwise try other "/etc/*-release" files, but ignore "/etc/lsb-release".
256 my @releases = grep( $_ ne "/etc/lsb-release", bsd_glob( "/etc/*-release" ) );
257 # On some Fedora systems there are two files: fedora-release and redhat-release
258 # with identical content. If fedora-release present, ignore redjat-release.
259 if ( grep( $_ eq "/etc/fedora-release", @releases ) ) {
260 @releases = grep( $_ ne "/etc/redhat-release", @releases );
261 }; # if
262 if ( @releases == 1 ) {
263 $release = $releases[ 0 ];
264 } else {
265 if ( @releases == 0 ) {
266 # No *-release files found, try debian_version.
267 $release = "/etc/debian_version";
268 if ( not -e $release ) {
269 $release = undef;
270 warning( "No release files found in \"/etc/\" directory." );
271 }; # if
272 } else {
273 $release = undef;
274 warning( "More than one release files found in \"/etc/\" directory:", @releases );
275 }; # if
276 }; # if
277 }; # if
278 if ( defined( $release ) ) {
279 $bulk = read_file( $release );
280 if ( $release =~ m{system|redhat|fedora} ) {
281 # Red Hat or Fedora. Parse the first line of file.
282 # Typical values of *-release (one of):
283 # Red Hat Enterprise Linux* OS Server release 5.2 (Tikanga)
284 # Red Hat Enterprise Linux* OS AS release 3 (Taroon Update 4)
285 # Fedora release 10 (Cambridge)
286 $bulk =~ m{\A(.*)$}m
287 or runtime_error( "$release: Cannot find the first line:", $bulk, "(eof)" );
288 my $first_line = $1;
289 $values{ operating_system_description } = $first_line;
Jim Cownie181b4bb2013-12-23 17:28:57 +0000290 $first_line =~ m{\A(.*?)\s+release\s+(.*?)(?:\s+\((.*?)(?:\s+Update\s+(.*?))?\))?\s*$}
Jim Cownie5e8470a2013-09-27 10:38:44 +0000291 or runtime_error( "$release:1: Cannot parse line:", $first_line );
292 $values{ operating_system_name } = $1;
293 $values{ operating_system_release } = $2 . ( defined( $4 ) ? ".$4" : "" );
294 $values{ operating_system_codename } = $3;
295 } elsif ( $release =~ m{SuSE} ) {
296 # Typical SuSE-release:
297 # SUSE Linux* OS Enterprise Server 10 (x86_64)
298 # VERSION = 10
299 # PATCHLEVEL = 2
300 $bulk =~ m{\A(.*)$}m
301 or runtime_error( "$release: Cannot find the first line:", $bulk, "(eof)" );
302 my $first_line = $1;
303 $values{ operating_system_description } = $first_line;
304 $first_line =~ m{^(.*?)\s*(\d+)\s*\(.*?\)\s*$}
305 or runtime_error( "$release:1: Cannot parse line:", $first_line );
306 $values{ operating_system_name } = $1;
307 $bulk =~ m{^VERSION\s*=\s*(.*)\s*$}m
308 or runtime_error( "$release: There is no VERSION:", $bulk, "(eof)" );
309 $values{ operating_system_release } = $1;
310 if ( $bulk =~ m{^PATCHLEVEL\s*=\s*(.*)\s*$}m ) {
311 $values{ operating_system_release } .= ".$1";
312 }; # if
313 } elsif ( $release =~ m{debian_version} ) {
314 # Debian. The file debian_version contains just version number, nothing more:
315 # 4.0
316 my $name = "Debian";
317 $bulk =~ m{\A(.*)$}m
318 or runtime_error( "$release: Cannot find the first line:", $bulk, "(eof)" );
319 my $version = $1;
320 $values{ operating_system_name } = $name;
321 $values{ operating_system_release } = $version;
322 $values{ operating_system_codename } = "unknown";
323 $values{ operating_system_description } = sprintf( "%s %s", $name, $version );
324 }; # if
325 }; # if
326 }; # if
327 if ( not defined( $values{ operating_system_name } ) ) {
328 $values{ operating_system_name } = "GNU/Linux";
329 }; # if
330} elsif ( $values{ kernel_name } eq "Darwin" ) {
331 my %codenames = (
332 10.4 => "Tiger",
333 10.5 => "Leopard",
334 10.6 => "Snow Leopard",
335 );
336 my $darwin;
337 my $get_os_info =
338 sub {
339 my ( $name ) = @_;
340 if ( not defined $darwin ) {
341 $darwin->{ operating_system } = "Darwin";
342 # sw_vers prints OS X* version to stdout:
343 # ProductName: OS X*
344 # ProductVersion: 10.4.11
345 # BuildVersion: 8S2167
346 # It does not print codename, so we code OS X* codenames here.
347 my $sw_vers = which( "sw_vers" ) || "/usr/bin/sw_vers";
348 my $output;
349 debug( "Executing $sw_vers..." );
350 execute( [ $sw_vers ], -stdout => \$output, -stderr => undef );
351 $output =~ m{^ProductName:\s*(.*)\s*$}m
352 or runtime_error( "There is no ProductName in sw_vers output:", $output, "(eof)" );
353 my $name = $1;
354 $output =~ m{^ProductVersion:\s*(.*)\s*$}m
355 or runtime_error( "There is no ProductVersion in sw_vers output:", $output, "(eof)" );
356 my $release = $1;
357 # Sometimes release reported as "10.4.11" (3 componentes), sometimes as "10.6".
358 # Handle both variants.
359 $release =~ m{^(\d+.\d+)(?:\.\d+)?(?=\s|$)}
360 or runtime_error( "Cannot parse OS X* version: $release" );
361 my $version = $1;
362 my $codename = ( $codenames{ $version } or "unknown" );
363 $darwin->{ operating_system_name } = $name;
364 $darwin->{ operating_system_release } = $release;
365 $darwin->{ operating_system_codename } = $codename;
366 $darwin->{ operating_system_description } = sprintf( "%s %s (%s)", $name, $release, $codename );
367 }; # if
368 return $darwin->{ $name };
369 }; # sub
370 $values{ operating_system } = sub { $get_os_info->( "operating_system" ); };
371 $values{ operating_system_name } = sub { $get_os_info->( "operating_system_name" ); };
372 $values{ operating_system_release } = sub { $get_os_info->( "operating_system_release" ); };
373 $values{ operating_system_codename } = sub { $get_os_info->( "operating_system_codename" ); };
374 $values{ operating_system_description } = sub { $get_os_info->( "operating_system_description" ); };
375} elsif ( $values{ kernel_name } =~ m{\AWindows[ _]NT\z} ) {
376 $values{ operating_system } = "MS Windows";
377 # my @os_name = Win32::GetOSName();
378 # $values{ operating_system_release } = $os_name[ 0 ];
379 # $values{ operating_system_update } = $os_name[ 1 ];
380} elsif ( $values{ kernel_name } =~ m{\ACYGWIN_NT-} ) {
381 $values{ operating_system } = "MS Windows";
Alp Toker763b9392014-02-28 09:42:41 +0000382} elsif ( $values{ kernel_name } =~ m{\AFreeBSD} ) {
383 $values{ operating_system } = "FreeBSD";
Joerg Sonnenberger40252ce2015-09-21 19:42:05 +0000384} elsif ( $values{ kernel_name } =~ m{\ANetBSD} ) {
385 $values{ operating_system } = "NetBSD";
Jim Cownie5e8470a2013-09-27 10:38:44 +0000386} else {
Alp Toker763b9392014-02-28 09:42:41 +0000387 die "Unsupported kernel_name (\"$values{ kernel_name }\") returned by POSIX::uname(); stopped";
Jim Cownie5e8470a2013-09-27 10:38:44 +0000388}; # if
389
390# host_name and domain_name
391$values{ host_name } =
392 sub {
393 my $fqdn = value( "fqdn" );
394 $fqdn =~ m{\A([^.]*)(?:\.(.*))?\z};
395 my $host_name = $1;
396 if ( not defined( $host_name ) or $host_name eq "" ) {
397 die "Unexpected error: undefined or empty host name; stopped";
398 }; # if
399 return $host_name;
400 };
401$values{ domain_name } =
402 sub {
403 my $fqdn = value( "fqdn" );
404 $fqdn =~ m{\A([^.]*)(?:\.(.*))?\z};
405 my $domain_name = $2;
406 if ( not defined( $domain_name ) or $domain_name eq "" ) {
407 die "Unexpected error: undefined or empty domain name; stopped";
408 }; # if
409 return $domain_name;
410 };
411
412# Replace undefined values with "unknown".
413foreach my $name ( @all ) {
414 if ( not defined( $values{ $name } ) ) {
415 $values{ $name } = "unknown";
416 }; # if
417}; # foreach $name
418
419# Export functions reporting properties.
420foreach my $name ( @all ) {
421 no strict "refs";
422 *$name = sub { return value( $name ); };
423}; # foreach $name
424
425# This function returns base names.
426sub base_names {
427 return @base;
428}; # sub base_names
429
430# This function returns all the names.
431sub all_names {
432 return @all;
433}; # sub all_names
434
435# This function returns value by the specified name.
436sub value($) {
437 my $name = shift( @_ );
438 if ( ref( $values{ $name } ) ) {
439 my $value = $values{ $name }->();
440 $values{ $name } = $value;
441 }; # if
442 return $values{ $name };
443}; # sub value
444
445return 1;
446
447__END__
448
449=pod
450
451=head1 NAME
452
453B<Uname.pm> -- A few subroutines to get system information usually provided by
454C</bin/uname> and C<POSIX::uname()>.
455
456=head1 SYNOPSIS
457
458 use Uname;
459
460 # Base property functions.
461 $kernel_name = Uname::kernel_name();
462 $fqdn = Uname::fqdn();
463 $kernel_release = Uname::kernel_release();
464 $kernel_version = Uname::kernel_version();
465 $machine = Uname::machine();
466 $processor = Uname::processor();
467 $hardware_platform = Uname::hardware_platform();
468 $operating_system = Uname::operating_system();
469
Alp Toker8f2d3f02014-02-24 10:40:15 +0000470 # Auxiliary property functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000471 $host_name = Uname::host_name();
472 $domain_name = Uname::domain_name();
473 $os_name = Uname::operating_system_name();
474 $os_release = Uname::operating_system_release();
475 $os_codename = Uname::operating_system_codename();
476 $os_description = Uname::operating_system_description();
477
478 # Meta functions.
479 @base_names = Uname::base_names();
480 @all_names = Uname::all_names();
481 $kernel_name = Uname::value( "kernel_name" );
482
483=head1 DESCRIPTION
484
485B<Uname.pm> resembles functionality found in C<POSIX::uname()> function or in C<uname> program.
486However, both C<POSIX::uname()> and C</bin/uname> have some disadvantages:
487
488=over
489
490=item *
491
492C<uname> may be not available in some environments, for example, in Windows* OS
493(C<uname> may be found in some third-party software packages, like MKS Toolkit or Cygwin, but it is
494not a part of OS).
495
496=item *
497
498There are many different versions of C<uname>. For example, C<uname> on OS X* does not
499recognize options C<-i>, C<-o>, and any long options.
500
501=item *
502
503Different versions of C<uname> may report the same property differently. For example,
504C<uname> on Linux* OS reports machine as C<i686>, while C<uname> on OS X* reports the same machine as
505C<x86>.
506
507=item *
508
509C<POSIX::uname()> returns list of values. I cannot recall what is the fourth element of the list.
510
511=back
512
513=head2 Base Functions
514
515Base property functions provide the information as C<uname> program.
516
517=over
518
519=item B<kernel_name()>
520
521Returns the kernel name, as reported by C<POSIX::uname()>.
522
523=item B<fqdn()>
524
525Returns the FQDN, fully qualified domain name. On some systems C<POSIX::uname()> reports short node
526name (with no domain name), on others C<POSIX::uname()> reports full node name. This
527function strive to return FQDN always (by refining C<POSIX::uname()> with
528C<Net::Domain::hostfqdn()>).
529
530=item B<kernel_release()>
531
532Returns the kernel release string, as reported by C<POSIX::uname()>. Usually the string consists of
533several numbers, separated by dots and dashes, but may also include some non-numeric substrings like
534"smp".
535
536=item B<kernel_version()>
537
538Returns the kernel version string, as reported by C<POSIX::uname()>. It is B<not> several
539dot-separated numbers but much longer string describing the kernel.
540For example, on Linux* OS it includes build date.
541If you look for something identifying the kernel, look at L<kernel_release>.
542
543=item B<machine()>
544
545Returns the machine hardware name, as reported by POSIX::uname(). Not reliable. Different OSes may
546report the same machine hardware name differently. For example, Linux* OS reports C<i686>, while OS X*
547reports C<x86> on the same machine.
548
549=item B<processor()>
550
551Returns the processor type. Not reliable. Usually the same as C<machine>.
552
553=item B<hardware_platform()>
554
555One of: C<i386> or C<x86_64>.
556
557=item B<operating_system()>
558
559One of: C<GNU/Linux>, C<OS X*>, or C<MS Windows>.
560
561=back
562
Alp Toker8f2d3f02014-02-24 10:40:15 +0000563=head2 Auxiliary Functions
Jim Cownie5e8470a2013-09-27 10:38:44 +0000564
Alp Toker8f2d3f02014-02-24 10:40:15 +0000565Auxiliary functions extends base functions with information not reported by C<uname> program.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000566
Alp Toker8f2d3f02014-02-24 10:40:15 +0000567Auxiliary functions collect information from different sources. For example, on OS X*, they may
Jim Cownie5e8470a2013-09-27 10:38:44 +0000568call C<sw_vers> program to find out OS release; on Linux* OS they may parse C</etc/redhat-release> file,
569etc.
570
571=over
572
573=item B<host_name()>
574
575Returns host name (FQDN with dropped domain part).
576
577=item B<domain_name()>
578
579Returns domain name (FQDN with dropped host part).
580
581=item B<operating_system_name>
582
583Name of operating system or name of Linux* OS distribution, like "Fedora" or
584"Red Hat Enterprise Linux* OS Server".
585
586=item B<operating_system_release>
587
588Release (version) of operating system or Linux* OS distribution. Usually it is a series of
589dot-separated numbers.
590
591=item B<operating_system_codename>
592
593Codename of operating system release or Linux* OS distribution. For example, Fedora 10 is "Cambridge"
594while OS X* 10.4 is "Tiger".
595
596=item B<operating_system_description>
597
598Longer string. Usually it includes all the operating system properting mentioned above -- name,
599release, codename in parentheses.
600
601=back
602
603=head2 Meta Functions
604
605=over
606
607=item B<base_names()>
608
609This function returns the list of base property names.
610
611=item B<all_names()>
612
613This function returns the list of all property names.
614
615=item B<value(> I<name> B<)>
616
617This function returns the value of the property specified by I<name>.
618
619=back
620
621=head1 EXAMPLES
622
623 use Uname;
624
625 print( Uname::string(), "\n" );
626
627 foreach my $name ( Uname::all_names() ) {
628 print( "$name=\"" . Uname::value( $name ) . "\"\n" );
629 }; # foreach $name
630
631=head1 SEE ALSO
632
633L<POSIX::uname>, L<uname>.
634
635=cut
636
637# end of file #
638