From owner-svn-src-stable-8@FreeBSD.ORG Mon Dec 10 02:33:17 2012 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id ABCCE5B5; Mon, 10 Dec 2012 02:33:17 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 8EDFB8FC0C; Mon, 10 Dec 2012 02:33:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBA2XHR9095254; Mon, 10 Dec 2012 02:33:17 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBA2XHqc095248; Mon, 10 Dec 2012 02:33:17 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201212100233.qBA2XHqc095248@svn.freebsd.org> From: Eitan Adler Date: Mon, 10 Dec 2012 02:33:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r244064 - stable/8/usr.sbin/chkgrp X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Dec 2012 02:33:17 -0000 Author: eadler Date: Mon Dec 10 02:33:16 2012 New Revision: 244064 URL: http://svnweb.freebsd.org/changeset/base/244064 Log: MFC r243084: Add support for a -q flag. While here make the custom argument parsing use getopt instead of hacking on it more. This change also fixes the method of silencing the compiler warning about gfn being used uninitialized. Approved by: cperciva (implicit) Modified: stable/8/usr.sbin/chkgrp/chkgrp.8 stable/8/usr.sbin/chkgrp/chkgrp.c Directory Properties: stable/8/usr.sbin/chkgrp/ (props changed) Modified: stable/8/usr.sbin/chkgrp/chkgrp.8 ============================================================================== --- stable/8/usr.sbin/chkgrp/chkgrp.8 Mon Dec 10 02:26:01 2012 (r244063) +++ stable/8/usr.sbin/chkgrp/chkgrp.8 Mon Dec 10 02:33:16 2012 (r244064) @@ -34,6 +34,7 @@ .Nd check the syntax of the group file .Sh SYNOPSIS .Nm +.Op Fl q .Op Ar groupfile .Sh DESCRIPTION The @@ -47,6 +48,12 @@ contains whitespace, and that the third numeric. It will also check for invalid characters in the group names and group members. +The following options are available: +.Bl -tag -width indent +.It Fl q +This option disables printing of text when the group format +is correct. +.El .Sh FILES .Bl -tag -width /etc/group -compact .It Pa /etc/group Modified: stable/8/usr.sbin/chkgrp/chkgrp.c ============================================================================== --- stable/8/usr.sbin/chkgrp/chkgrp.c Mon Dec 10 02:26:01 2012 (r244063) +++ stable/8/usr.sbin/chkgrp/chkgrp.c Mon Dec 10 02:33:16 2012 (r244064) @@ -34,11 +34,12 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include static char empty[] = { 0 }; -static void +static void __dead2 usage(void) { fprintf(stderr, "usage: chkgrp [groupfile]\n"); @@ -50,24 +51,33 @@ main(int argc, char *argv[]) { unsigned int i; size_t len; + int quiet; + int ch; int n = 0, k, e = 0; char *line, *f[4], *p; const char *cp, *gfn; FILE *gf; - /* check arguments */ - switch (argc) { - case 1: - gfn = "/etc/group"; - break; - case 2: - gfn = argv[1]; - break; - default: - gfn = NULL; /* silence compiler */ - usage(); + quiet = 0; + while ((ch = getopt(argc, argv, "q")) != -1) { + switch (ch) { + case 'q': + quiet = 1; + break; + case '?': + default: + printf("hello\n"); + usage(); + } } + if (optind == argc) + gfn = "/etc/group"; + else if (optind == argc - 1) + gfn = argv[optind]; + else + usage(); + /* open group file */ if ((gf = fopen(gfn, "r")) == NULL) err(EX_IOERR, "%s", gfn); /* XXX - is IO_ERR the correct exit code? */ @@ -163,7 +173,7 @@ main(int argc, char *argv[]) /* done */ fclose(gf); - if (e == 0) + if (e == 0 && quiet == 0) printf("%s is fine\n", gfn); exit(e ? EX_DATAERR : EX_OK); }