Re: code review 181097: Allow Hostname to return FQDN when /bin/hostname does not (issue181097)

900 views
Skip to first unread message

ia...@golang.org

unread,
Dec 30, 2009, 7:14:59 PM12/30/09
to gol...@icarus.freeuk.com, golan...@googlegroups.com, golan...@googlegroups.com, re...@codereview.appspotmail.com
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.

http://codereview.appspot.com/181097

gol...@icarus.freeuk.com

unread,
Dec 30, 2009, 8:37:43 PM12/30/09
to golan...@googlegroups.com, ia...@golang.org, golan...@googlegroups.com, re...@codereview.appspotmail.com
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.


http://codereview.appspot.com/181097

c...@f00f.org

unread,
Dec 30, 2009, 10:35:44 PM12/30/09
to gol...@icarus.freeuk.com, golan...@googlegroups.com, ia...@golang.org, golan...@googlegroups.com, re...@codereview.appspotmail.com
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.


http://codereview.appspot.com/181097

Devon H. O'Dell

unread,
Dec 30, 2009, 10:42:57 PM12/30/09
to gol...@icarus.freeuk.com, golan...@googlegroups.com, ia...@golang.org, c...@f00f.org, re...@codereview.appspotmail.com
2009/12/30 <c...@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

r...@golang.org

unread,
Jan 8, 2010, 3:24:05 AM1/8/10
to gol...@icarus.freeuk.com, ia...@golang.org, c...@f00f.org, golan...@googlegroups.com, re...@codereview.appspotmail.com
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.

http://codereview.appspot.com/181097

r...@golang.org

unread,
Jan 8, 2010, 3:27:48 AM1/8/10
to gol...@icarus.freeuk.com, ia...@golang.org, c...@f00f.org, golan...@googlegroups.com, re...@codereview.appspotmail.com
On 2009/12/29 21:31:05, icarus wrote:
> Hello mailto:golan...@googlegroups.com (cc:
mailto:golan...@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.


http://codereview.appspot.com/181097

gol...@icarus.freeuk.com

unread,
Jan 11, 2010, 6:34:12 PM1/11/10
to ia...@golang.org, c...@f00f.org, r...@golang.org, golan...@googlegroups.com, re...@codereview.appspotmail.com
On 2010/01/08 08:27:47, rsc wrote:
> On 2009/12/29 21:31:05, icarus wrote:
> > Hello mailto:golan...@googlegroups.com (cc:
> mailto:golan...@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).

http://codereview.appspot.com/181097

r...@google.com

unread,
Jan 26, 2010, 3:36:52 PM1/26/10
to gol...@icarus.freeuk.com, r...@golang.org, golan...@googlegroups.com, re...@codereview.appspotmail.com
LGTM

catching up on code reviews, sorry for the delay.


http://codereview.appspot.com/181097/show

r...@golang.org

unread,
Jan 26, 2010, 4:16:05 PM1/26/10
to gol...@icarus.freeuk.com, golan...@googlegroups.com, re...@codereview.appspotmail.com
*** 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 <r...@golang.org>


http://codereview.appspot.com/181097/show

Reply all
Reply to author
Forward
0 new messages