Support the "-f" option by simply ignoring it.

This allows script compatibility with Linux, whose
"hostname" is the same as BSD "hostname -s".
With this change, "hostname -f" is the same on
both systems.

MFC after: 7 days
This commit is contained in:
Tim Kientzle 2006-12-08 07:19:51 +00:00
parent 6027060830
commit a426a2865c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=165004
2 changed files with 11 additions and 2 deletions

View File

@ -29,7 +29,7 @@
.\" @(#)hostname.1 8.2 (Berkeley) 4/28/95
.\" $FreeBSD$
.\"
.Dd December 5, 2006
.Dd December 7, 2006
.Dt HOSTNAME 1
.Os
.Sh NAME
@ -37,6 +37,7 @@
.Nd set or print name of current host system
.Sh SYNOPSIS
.Nm
.Op Fl f
.Op Fl s
.Op Ar name-of-host
.Sh DESCRIPTION
@ -56,6 +57,9 @@ variable in
.Pp
Options:
.Bl -tag -width flag
.It Fl f
Include domain information in the printed name.
This is the default behavior.
.It Fl s
Trim off any domain information from the printed
name.

View File

@ -58,8 +58,13 @@ main(int argc, char *argv[])
char *p, hostname[MAXHOSTNAMELEN];
sflag = 0;
while ((ch = getopt(argc, argv, "s")) != -1)
while ((ch = getopt(argc, argv, "sf")) != -1)
switch (ch) {
case 'f':
/* On Linux, "hostname -f" prints FQDN. */
/* BSD "hostname" always print FQDN by
* default, so we accept but ignore -f. */
break;
case 's':
sflag = 1;
break;