diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-01-23 08:48:46 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-01-23 08:48:46 +0000 |
commit | 6bb694c13adc449f32ff24c71221152025ccae6c (patch) | |
tree | 436f56d32b9cdd603737522700ebef6336749492 /lib | |
parent | 4c6b0ea912393b78c22246724423fc4d6c34fadb (diff) | |
download | perl-6bb694c13adc449f32ff24c71221152025ccae6c.tar.gz |
prefer POSIX::uname() rather than syscalls, which require attempting
to load syscall.ph (from David Huggins-Daines <dhd@eradicator.org>)
p4raw-id: //depot/perl@4851
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sys/Hostname.pm | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/Sys/Hostname.pm b/lib/Sys/Hostname.pm index 4d93f91f9e..87d10520df 100644 --- a/lib/Sys/Hostname.pm +++ b/lib/Sys/Hostname.pm @@ -71,44 +71,44 @@ sub hostname { } else { # Unix - # method 2 - syscall is preferred since it avoids tainting problems + # method 2 - use POSIX.pm, prefer the standard library to system calls eval { local $SIG{__DIE__}; - { - package main; - require "syscall.ph"; - } + require POSIX; + $host = (POSIX::uname())[1]; + } + # method 3 - otherwise syscall is preferred since it avoids tainting problems + || eval { + local $SIG{__DIE__}; + require "syscall.ph"; $host = "\0" x 65; ## preload scalar - syscall(&main::SYS_gethostname, $host, 65) == 0; + syscall(&SYS_gethostname, $host, 65) == 0; } - # method 2a - syscall using systeminfo instead of gethostname + # method 3a - syscall using systeminfo instead of gethostname # -- needed on systems like Solaris || eval { local $SIG{__DIE__}; - { - package main; - require "sys/syscall.ph"; - require "sys/systeminfo.ph"; - } + require "sys/syscall.ph"; + require "sys/systeminfo.ph"; $host = "\0" x 65; ## preload scalar - syscall(&main::SYS_systeminfo, &main::SI_HOSTNAME, $host, 65) != -1; + syscall(&SYS_systeminfo, &SI_HOSTNAME, $host, 65) != -1; } - # method 3 - trusty old hostname command + # method 4 - trusty old hostname command || eval { local $SIG{__DIE__}; local $SIG{CHLD}; $host = `(hostname) 2>/dev/null`; # bsdish } - # method 4 - sysV uname command (may truncate) + # method 5 - sysV uname command (may truncate) || eval { local $SIG{__DIE__}; $host = `uname -n 2>/dev/null`; ## sysVish } - # method 5 - Apollo pre-SR10 + # method 6 - Apollo pre-SR10 || eval { local $SIG{__DIE__}; ($host,$a,$b,$c,$d)=split(/[:\. ]/,`/com/host`,6); |