|
|
|
Allow Hostname to return FQDN when /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.
Patch Set 1 #Patch Set 2 : code review 181097: Allow Hostname to return FQDN when /bin/hostname does not #
Total comments: 1
Patch Set 3 : code review 181097: Allow Hostname to return FQDN when /bin/hostname does not #Total messages: 11
|
icarus
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review the following change.
|
16 years ago (2009年12月29日 21:31:05 UTC) #1 |
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review the following change.
What system do you notice this problem on? 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.
On 2009年12月31日 00:14:59, iant wrote: > What system do you notice this problem on? 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.
I think perhaps we should introduce os.Uname and plumb that in. 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.
2009年12月30日 <cw@f00f.org>: > I think perhaps we should introduce os.Uname and plumb that in. > > 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
On 2009年12月31日 03:35:43, cw wrote: > I think perhaps we should introduce os.Uname and plumb that in. 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.
On 2009年12月29日 21:31:05, icarus wrote: > Hello mailto:golang-dev@googlegroups.com (cc: mailto:golang-dev@googlegroups.com), > > 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.
On 2010年01月08日 08:27:47, rsc wrote: > On 2009年12月29日 21:31:05, icarus wrote: > > Hello mailto:golang-dev@googlegroups.com (cc: > mailto:golang-dev@googlegroups.com), > > > > 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 ? Done. (As an individual CLA).
LGTM catching up on code reviews, sorry for the delay.
*** Submitted as http://code.google.com/p/go/source/detail?r=cb37c45d40ae *** 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 <rsc@golang.org>