[Midnightbsd-cvs] src [7813] trunk/usr.sbin/chkgrp: add support for q flag in chkgrp.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Sep 6 19:22:59 EDT 2016
Revision: 7813
http://svnweb.midnightbsd.org/src/?rev=7813
Author: laffer1
Date: 2016-09-06 19:22:59 -0400 (Tue, 06 Sep 2016)
Log Message:
-----------
add support for q flag in chkgrp.
Modified Paths:
--------------
trunk/usr.sbin/chkgrp/chkgrp.8
trunk/usr.sbin/chkgrp/chkgrp.c
Modified: trunk/usr.sbin/chkgrp/chkgrp.8
===================================================================
--- trunk/usr.sbin/chkgrp/chkgrp.8 2016-09-06 23:21:34 UTC (rev 7812)
+++ trunk/usr.sbin/chkgrp/chkgrp.8 2016-09-06 23:22:59 UTC (rev 7813)
@@ -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 @@
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: trunk/usr.sbin/chkgrp/chkgrp.c
===================================================================
--- trunk/usr.sbin/chkgrp/chkgrp.c 2016-09-06 23:21:34 UTC (rev 7812)
+++ trunk/usr.sbin/chkgrp/chkgrp.c 2016-09-06 23:22:59 UTC (rev 7813)
@@ -34,11 +34,12 @@
#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");
@@ -50,24 +51,33 @@
{
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 @@
/* done */
fclose(gf);
- if (e == 0)
+ if (e == 0 && quiet == 0)
printf("%s is fine\n", gfn);
exit(e ? EX_DATAERR : EX_OK);
}
More information about the Midnightbsd-cvs
mailing list