From owner-svn-src-all@freebsd.org Tue Nov 8 11:36:34 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 87FB1C37C68; Tue, 8 Nov 2016 11:36:34 +0000 (UTC) (envelope-from araujo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 411D3232; Tue, 8 Nov 2016 11:36:34 +0000 (UTC) (envelope-from araujo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA8BaXYR073939; Tue, 8 Nov 2016 11:36:33 GMT (envelope-from araujo@FreeBSD.org) Received: (from araujo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA8BaXrs073937; Tue, 8 Nov 2016 11:36:33 GMT (envelope-from araujo@FreeBSD.org) Message-Id: <201611081136.uA8BaXrs073937@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: araujo set sender to araujo@FreeBSD.org using -f From: Marcelo Araujo Date: Tue, 8 Nov 2016 11:36:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r308443 - head/bin/hostname X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 11:36:34 -0000 Author: araujo Date: Tue Nov 8 11:36:33 2016 New Revision: 308443 URL: https://svnweb.freebsd.org/changeset/base/308443 Log: Add -d flag that prints domain only. PR: 212875 Submitted by: Ben RUBSON Reviewed by: pi Modified: head/bin/hostname/hostname.1 head/bin/hostname/hostname.c Modified: head/bin/hostname/hostname.1 ============================================================================== --- head/bin/hostname/hostname.1 Tue Nov 8 10:10:55 2016 (r308442) +++ head/bin/hostname/hostname.1 Tue Nov 8 11:36:33 2016 (r308443) @@ -29,7 +29,7 @@ .\" @(#)hostname.1 8.2 (Berkeley) 4/28/95 .\" $FreeBSD$ .\" -.Dd December 7, 2006 +.Dd November 9, 2016 .Dt HOSTNAME 1 .Os .Sh NAME @@ -37,7 +37,8 @@ .Nd set or print name of current host system .Sh SYNOPSIS .Nm -.Op Fl fs +.Op Fl f +.Op Fl s|d .Op Ar name-of-host .Sh DESCRIPTION The @@ -62,6 +63,8 @@ This is the default behavior. .It Fl s Trim off any domain information from the printed name. +.It Fl d +Only print domain information. .El .Sh SEE ALSO .Xr gethostname 3 , Modified: head/bin/hostname/hostname.c ============================================================================== --- head/bin/hostname/hostname.c Tue Nov 8 10:10:55 2016 (r308442) +++ head/bin/hostname/hostname.c Tue Nov 8 11:36:33 2016 (r308443) @@ -54,11 +54,12 @@ static void usage(void) __dead2; int main(int argc, char *argv[]) { - int ch, sflag; + int ch, sflag, dflag; char *p, hostname[MAXHOSTNAMELEN]; sflag = 0; - while ((ch = getopt(argc, argv, "fs")) != -1) + dflag = 0; + while ((ch = getopt(argc, argv, "fsd")) != -1) switch (ch) { case 'f': /* @@ -70,6 +71,9 @@ main(int argc, char *argv[]) case 's': sflag = 1; break; + case 'd': + dflag = 1; + break; case '?': default: usage(); @@ -77,7 +81,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc > 1) + if (argc > 1 || (sflag && dflag)) usage(); if (*argv) { @@ -90,6 +94,10 @@ main(int argc, char *argv[]) p = strchr(hostname, '.'); if (p != NULL) *p = '\0'; + } else if (dflag) { + p = strchr(hostname, '.'); + if (p != NULL) + strcpy(hostname, ++p); } (void)printf("%s\n", hostname); } @@ -100,6 +108,6 @@ static void usage(void) { - (void)fprintf(stderr, "usage: hostname [-fs] [name-of-host]\n"); + (void)fprintf(stderr, "usage: hostname [-f] [s|d] [name-of-host]\n"); exit(1); }