Opened 12 years ago

Closed 12 years ago

#1250 closed bug (fixed)

hostname not fully implemented

Reported by: jonas.kirilla Owned by: axeld
Priority: normal Milestone: R1
Component: System/libroot.so Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

Shell command 'hostname' returns 'beast'. Shell command 'uname --nodename' returns 'unknown'.

Both are hardcoded values. /etc/hostname is ignored.

Setting a hostname using 'hostname foo' does not work.

Implementation ideas:

src/system/libroot/posix/sys/uname.c

  • call gethostname(), copy this to utsname->nodename

src/system/libroot/posix/unistd/hostname.c

  • implement reading of /etc/hostname if present, in gethostname()
  • implement writing of /etc/hostname, in sethostname()

The supplied patch makes uname.c consult gethostname() so both shell commands agree that (for now) the name of the host is 'beast'.

I will try to also make a patch for hostname.c.

Attachments (1)

uname.c.diff (1010 bytes) - added by jonas.kirilla 12 years ago.

Download all attachments as: .zip

Change History (4)

Changed 12 years ago by jonas.kirilla

Attachment: uname.c.diff added

comment:1 Changed 12 years ago by jonas.kirilla

  1. Looking at it some more I may have to rewrite the patch for uname.c, as gethostname() can return errors.
  1. hostname -> nodename truncation okay?

Utsname.nodename is limited by _SYS_NAMELEN to 32 bytes, whereas MAXHOSTNAMELEN is defined as 256 in sys/param.h. Calling gethostname() with a too short string would of course truncate it. I don't know if this truncation of the hostname is a problem for uname or not.

FreeBSD appears to use a 32 bytes field length for utsname in the kernel, and 256 when in user space. http://fxr.watson.org/fxr/source/sys/utsname.h?v=RELENG62

  1. HOST_NAME_MAX appears to be the better choice over MAXHOSTNAMELEN

http://www.opengroup.org/onlinepubs/009695399/functions/gethostname.html

The FreeBSD man page on GETHOSTNAME(3) has this to say:

STANDARDS The gethostname() function conforms to IEEE Std 1003.1-2001 (POSIX.1). Callers should be aware that {HOST_NAME_MAX} may be variable or infinite, but is guaranteed to be no less than {_POSIX_HOST_NAME_MAX}. On older systems, this limit was defined in the non-standard header <sys/param.h> as MAXHOSTNAMELEN, and counted the terminating null. The sethostname() function and the error returns for gethostname() are not standardized.

So far I haven't figured out whether HOST_NAME_MAX is used in Linux. I've only found a lot of MAXHOSTNAMELEN in the sources.

  1. Would things such as these be better discussed on the development mailinglist?

comment:2 Changed 12 years ago by jonas.kirilla

FWIW, in glibc gethostname() is implemented with a call to uname(), the other way around from what my patch does.

http://www.gnu.org/software/libc/manual/html_node/Platform-Type.html#Platform-Type

comment:3 Changed 12 years ago by axeld

Resolution: fixed
Status: newclosed

Thanks for your work! It's fixed in hrev22492.

Note: See TracTickets for help on using tickets.