diff options
author | Lauri Tirkkonen <lotheac@iki.fi> | 2016-05-12 21:35:29 +0300 |
---|---|---|
committer | Dan McDonald <danmcd@omniti.com> | 2016-05-23 10:48:22 -0400 |
commit | 5bebc427c96eee7cdbec9df37a3a6fdead337aba (patch) | |
tree | 07110676f257084c01e3ed57c249410180365b01 | |
parent | e934136d865d15afd445bc37a6e4d692d0f054db (diff) | |
download | illumos-joyent-5bebc427c96eee7cdbec9df37a3a6fdead337aba.tar.gz |
3758 RFE: Would like "hostname -s"
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Approved by: Dan McDonald <danmcd@omniti.com>
-rw-r--r-- | usr/src/cmd/hostname/hostname.c | 16 | ||||
-rw-r--r-- | usr/src/man/man1/hostname.1 | 45 |
2 files changed, 36 insertions, 25 deletions
diff --git a/usr/src/cmd/hostname/hostname.c b/usr/src/cmd/hostname/hostname.c index 1110aa7ba2..ac7f9f84ed 100644 --- a/usr/src/cmd/hostname/hostname.c +++ b/usr/src/cmd/hostname/hostname.c @@ -36,7 +36,6 @@ /* Portions Copyright 2007 Jeremy Teo */ /* Portions Copyright 2006 Stephen P. Potter */ -#pragma ident "%Z%%M% %I% %E% SMI" #include <unistd.h> #include <stdio.h> @@ -56,8 +55,8 @@ static char *progname; static void usage(void) { - (void) fprintf(stderr, gettext("usage: %s [system_name]\n"), - basename(progname)); + (void) fprintf(stderr, gettext("usage: %s [-s] [system_name]\n"), + basename(progname)); exit(1); } @@ -67,7 +66,8 @@ main(int argc, char *argv[]) char *nodename = NULL; char c_hostname[MAXHOSTNAMELEN]; int optlet; - char *optstring = "?"; + int sflag = 0; + char *optstring = "s"; (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); @@ -77,13 +77,17 @@ main(int argc, char *argv[]) opterr = 0; while ((optlet = getopt(argc, argv, optstring)) != -1) { switch (optlet) { + case 's': + sflag = 1; + break; case '?': usage(); + break; } } /* - * if called with no options, just print out the hostname/nodename + * if called with no arguments, just print out the hostname/nodename */ if (argc <= optind) { if (gethostname(c_hostname, sizeof (c_hostname)) < 0) { @@ -92,6 +96,8 @@ main(int argc, char *argv[]) basename(progname)); exit(1); } else { + if (sflag) + c_hostname[strcspn(c_hostname, ".")] = '\0'; (void) fprintf(stdout, "%s\n", c_hostname); } } else { diff --git a/usr/src/man/man1/hostname.1 b/usr/src/man/man1/hostname.1 index 2db91762f4..5b63dab64a 100644 --- a/usr/src/man/man1/hostname.1 +++ b/usr/src/man/man1/hostname.1 @@ -1,24 +1,29 @@ -'\" te .\" Copyright (c) 1992, Sun Microsystems, Inc. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH HOSTNAME 1 "Sep 14, 1992" -.SH NAME -hostname \- set or print name of current host system -.SH SYNOPSIS -.LP -.nf -\fB/usr/bin/hostname\fR [\fIname-of-host\fR] -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBhostname\fR command prints the name of the current host, as given before -the \fBlogin\fR prompt. The super-user can set the hostname by giving an -argument. -.SH SEE ALSO -.sp -.LP -\fBuname\fR(1), \fBattributes\fR(5) +.Dd May 12, 2016 +.Dt HOSTNAME 1 +.Os +.Sh NAME +.Nm hostname +.Nd set or print name of current host system +.Sh SYNOPSIS +.Nm +.Op Fl s +.Op Ar name-of-host +.Sh DESCRIPTION +The +.Nm +command prints the name of the current host, as given before the +.Xr login 1 +prompt. The super-user can set the hostname by giving +.Ar name-of-host . +.Sh OPTIONS +.Bl -tag -width Ds +.It Fl s +Prints only the part of the hostname preceding the first dot. +.El +.Sh SEE ALSO +.Xr uname 1 , +.Xr attributes 5 |