Front page | perl.perl5.porters |
Postings from February 2000
fixing Sys::Hostname
From:
Tom Christiansen
Date:
February 5, 2000 05:46
Subject:
fixing Sys::Hostname
Message ID:
6923.949758404@chthon
The latest changes to Sys::Hostname's (no, that's not the ::s module
:-) hostname() function need to be addressed. Why? Because they
by default needlessly pull in a ziggabyte of POSIX material just
to get at uname(). The performance hit is dramatic and permanent.
Yet, even were this free, is the still wrong thing to do! That's
because the (struct utsname).nodename field isn't good enough.
POSIX states that the format of each member is implementation-dependent.
The first problem is that with respect to uname(), POSIX explicitly
states that:
The inclusion of the nodename member in this structure does not
imply that it is sufficient information for interfacing to
communications networks.
The second problem is that the standard requires the nodename field
to be of no particular size. On some systems, this results in
effectively unusable fields containing as few as eight characters--which,
for reasons of appeasing the hysterical porpoises, must not be
changed.
Here's what we have to do.
We already at Configure time the check to determine whether the
system contains gethostname(2). Yet, we do not let the user call
it! We should change the module so that it calls the proper function
right out of the C library, and stop playing these dumb hacks. If
the function does not exist, only then we should call the `hostname`
program if we can. It's much faster than pulling in POSIX::uname.
Only in the absence of gethostname(2) and hostname(1) should uname(3)
be attempted, since it is apt to be wrong, and very expensive to
boot. Even still, you should call it from C, not Perl, so you don't
pay that insane POSIX module's price for such basic functionality.
--tom
-
fixing Sys::Hostname
by Tom Christiansen