Date: Thu, 15 Nov 2012 15:16:51 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r243084 - head/usr.sbin/chkgrp Message-ID: <201211151516.qAFFGp38005962@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eadler Date: Thu Nov 15 15:16:50 2012 New Revision: 243084 URL: http://svnweb.freebsd.org/changeset/base/243084 Log: 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 MFC after: 1 week Modified: head/usr.sbin/chkgrp/chkgrp.8 head/usr.sbin/chkgrp/chkgrp.c Modified: head/usr.sbin/chkgrp/chkgrp.8 ============================================================================== --- head/usr.sbin/chkgrp/chkgrp.8 Thu Nov 15 15:06:24 2012 (r243083) +++ head/usr.sbin/chkgrp/chkgrp.8 Thu Nov 15 15:16:50 2012 (r243084) @@ -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: head/usr.sbin/chkgrp/chkgrp.c ============================================================================== --- head/usr.sbin/chkgrp/chkgrp.c Thu Nov 15 15:06:24 2012 (r243083) +++ head/usr.sbin/chkgrp/chkgrp.c Thu Nov 15 15:16:50 2012 (r243084) @@ -37,11 +37,12 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <sysexits.h> static char empty[] = { 0 }; -static void +static void __dead2 usage(void) { fprintf(stderr, "usage: chkgrp [groupfile]\n"); @@ -53,24 +54,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_NOINPUT, "%s", gfn); @@ -178,7 +188,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); } _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211151516.qAFFGp38005962>