http://codereview.appspot.com/181097/diff/1001/4
File src/pkg/os/os_test.go (right):
http://codereview.appspot.com/181097/diff/1001/4#newcode647
src/pkg/os/os_test.go:647: func strchr(s string, c uint8) int {
Use string.Index instead.
Debian 386, where hostname is set to "xxx.yy.com". This is the value in
/proc/sys/kernel/hostname. "/bin/hostname" returns "xxx", but
"/bin/hostname -f" returns "xxx.yy.com".
So either adding a "-f" or truncating at the "." will make the unit test
work. Truncating seems a more portable solution.
> http://codereview.appspot.com/181097/diff/1001/4
> File src/pkg/os/os_test.go (right):
> http://codereview.appspot.com/181097/diff/1001/4#newcode647
> src/pkg/os/os_test.go:647: func strchr(s string, c uint8) int {
> Use string.Index instead.
Thanks for the comment. It wasn't clear how self contained one should be
making the file. The other uses of the strings package was just the
Bytes function.
For linux it's a syscall wrapper, darwin will be more or less the same
(the syscall isn't exposed presently though) and sysctl for freebsd.
At which point we can avoid /bin/hostname entirely.
I was under the impression that darwin uses sysctls as well for this.
Either way, yes -- I think this interface should go into os, as it's
not a syscall everywhere, and that would address portability concerns.
--dho
there's no point. the struct passed to uname has
unspecified array lengths in it, and the man page
says that reading /proc/sys/kernel/hostname is
equivalent to getting it from uname.
> I'd like you to review the following change.
This looks good, but could you please complete the CLA as
described at http://golang.org/doc/contribute.html#copyright ?
Thanks.
> This looks good, but could you please complete the CLA as
> described at http://golang.org/doc/contribute.html#copyright ?
Done. (As an individual CLA).
catching up on code reviews, sorry for the delay.
os: in test, allow Hostname to return FQDN even if /bin/hostname does
not
Hostname reads the file /proc/sys/kernel/hostname to determine
the value it returns. Some people set this to a Fully Qualified
Doamin Name. At least one implementation of /bin/hostname
truncates the name it gets (often from the "uname" system call)
at the first dot unless it is given a "-f" flag. This change makes
the unit test also truncate at the first dot and checks if the strings
then match. This seems more portable than adding an extra flag
to the called /bin/hostname program.
R=rsc
CC=golang-dev
http://codereview.appspot.com/181097
Committer: Russ Cox <r...@golang.org>