svn commit: r324124 - in stable: 10/usr.bin/getconf 11/usr.bin/getconf

2017-09-30 Thread John Baldwin
Author: jhb
Date: Sat Sep 30 17:30:22 2017
New Revision: 324124
URL: https://svnweb.freebsd.org/changeset/base/324124

Log:
  MFC 323631: Add an -a flag to getconf.
  
  When -a is specified, the name and value of all system or path
  configuration values is reported to standard output.
  
  Sponsored by: Chelsio Communications

Modified:
  stable/11/usr.bin/getconf/confstr.gperf
  stable/11/usr.bin/getconf/getconf.1
  stable/11/usr.bin/getconf/getconf.c
  stable/11/usr.bin/getconf/getconf.h
  stable/11/usr.bin/getconf/pathconf.gperf
  stable/11/usr.bin/getconf/sysconf.gperf
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/10/usr.bin/getconf/confstr.gperf
  stable/10/usr.bin/getconf/getconf.1
  stable/10/usr.bin/getconf/getconf.c
  stable/10/usr.bin/getconf/getconf.h
  stable/10/usr.bin/getconf/pathconf.gperf
  stable/10/usr.bin/getconf/sysconf.gperf
Directory Properties:
  stable/10/   (props changed)

Modified: stable/11/usr.bin/getconf/confstr.gperf
==
--- stable/11/usr.bin/getconf/confstr.gperf Sat Sep 30 13:17:31 2017
(r324123)
+++ stable/11/usr.bin/getconf/confstr.gperf Sat Sep 30 17:30:22 2017
(r324124)
@@ -68,3 +68,14 @@ find_confstr(const char *name, int *key)
}
return 0;
 }
+
+void
+foreach_confstr(void (*func)(const char *, int))
+{
+   const struct map *mp;
+
+   for (mp = wordlist; mp->name != NULL; mp++) {
+   if (mp->valid)
+   func(mp->name, mp->key);
+   }
+}

Modified: stable/11/usr.bin/getconf/getconf.1
==
--- stable/11/usr.bin/getconf/getconf.1 Sat Sep 30 13:17:31 2017
(r324123)
+++ stable/11/usr.bin/getconf/getconf.1 Sat Sep 30 17:30:22 2017
(r324124)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 8, 2016
+.Dd September 15, 2017
 .Dt GETCONF 1
 .Os
 .Sh NAME
@@ -36,6 +36,9 @@
 .Nd retrieve standard configuration variables
 .Sh SYNOPSIS
 .Nm
+.Fl a
+.Op Ar file
+.Nm
 .Op Fl v Ar environment
 .Ar path_var
 .Ar file
@@ -45,20 +48,35 @@
 .Sh DESCRIPTION
 The
 .Nm
-utility prints the value of a
+utility prints the values of
 .Tn POSIX
 or
 .Tn X/Open
-path or system configuration variable to the standard output.
-If the specified variable is undefined, the string
+path or system configuration variables to the standard output.
+If a variable is undefined, the string
 .Dq Li undefined
 is output.
 .Pp
-The first form of the command, with two mandatory
+The first form of the command displays all of the path or system configuration
+variables to standard output.
+If
+.Ar file
+is provided,
+all path configuration variables are reported for
+.Ar file
+using
+.Xr pathconf 2 .
+Otherwise,
+all system configuration variables are reported using
+.Xr confstr 3
+and
+.Xr sysconf 3.
+.Pp
+The second form of the command, with two mandatory
 arguments, retrieves file- and file system-specific
 configuration variables using
 .Xr pathconf 2 .
-The second form, with a single argument, retrieves system
+The third form, with a single argument, retrieves system
 configuration variables using
 .Xr confstr 3
 and

Modified: stable/11/usr.bin/getconf/getconf.c
==
--- stable/11/usr.bin/getconf/getconf.c Sat Sep 30 13:17:31 2017
(r324123)
+++ stable/11/usr.bin/getconf/getconf.c Sat Sep 30 17:30:22 2017
(r324124)
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,6 +42,8 @@ __FBSDID("$FreeBSD$");
 
 #include "getconf.h"
 
+static voiddo_allsys(void);
+static voiddo_allpath(const char *path);
 static voiddo_confstr(const char *name, int key);
 static voiddo_sysconf(const char *name, int key);
 static voiddo_pathconf(const char *name, int key, const char *path);
@@ -49,7 +52,8 @@ static void
 usage(void)
 {
fprintf(stderr,
-"usage: getconf [-v prog_env] system_var\n"
+"usage: getconf -a [pathname]\n"
+"   getconf [-v prog_env] system_var\n"
 "   getconf [-v prog_env] path_var pathname\n");
exit(EX_USAGE);
 }
@@ -57,13 +61,18 @@ usage(void)
 int
 main(int argc, char **argv)
 {
+   bool aflag;
int c, key, valid;
const char *name, *vflag, *alt_path;
intmax_t limitval;
 
+   aflag = false;
vflag = NULL;
-   while ((c = getopt(argc, argv, "v:")) != -1) {
+   while ((c = getopt(argc, argv, "av:")) != -1) {
switch (c) {
+   case 'a':
+   aflag = true;
+   break;
case 'v':
vflag = optarg;
break;
@@ -73,6 +82,16 @@ main(int argc, char **argv)
}
}
 
+   if (aflag) {
+   if (vflag != NULL)
+ 

svn commit: r324124 - in stable: 10/usr.bin/getconf 11/usr.bin/getconf

2017-09-30 Thread John Baldwin
Author: jhb
Date: Sat Sep 30 17:30:22 2017
New Revision: 324124
URL: https://svnweb.freebsd.org/changeset/base/324124

Log:
  MFC 323631: Add an -a flag to getconf.
  
  When -a is specified, the name and value of all system or path
  configuration values is reported to standard output.
  
  Sponsored by: Chelsio Communications

Modified:
  stable/10/usr.bin/getconf/confstr.gperf
  stable/10/usr.bin/getconf/getconf.1
  stable/10/usr.bin/getconf/getconf.c
  stable/10/usr.bin/getconf/getconf.h
  stable/10/usr.bin/getconf/pathconf.gperf
  stable/10/usr.bin/getconf/sysconf.gperf
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/usr.bin/getconf/confstr.gperf
  stable/11/usr.bin/getconf/getconf.1
  stable/11/usr.bin/getconf/getconf.c
  stable/11/usr.bin/getconf/getconf.h
  stable/11/usr.bin/getconf/pathconf.gperf
  stable/11/usr.bin/getconf/sysconf.gperf
Directory Properties:
  stable/11/   (props changed)

Modified: stable/10/usr.bin/getconf/confstr.gperf
==
--- stable/10/usr.bin/getconf/confstr.gperf Sat Sep 30 13:17:31 2017
(r324123)
+++ stable/10/usr.bin/getconf/confstr.gperf Sat Sep 30 17:30:22 2017
(r324124)
@@ -68,3 +68,14 @@ find_confstr(const char *name, int *key)
}
return 0;
 }
+
+void
+foreach_confstr(void (*func)(const char *, int))
+{
+   const struct map *mp;
+
+   for (mp = wordlist; mp->name != NULL; mp++) {
+   if (mp->valid)
+   func(mp->name, mp->key);
+   }
+}

Modified: stable/10/usr.bin/getconf/getconf.1
==
--- stable/10/usr.bin/getconf/getconf.1 Sat Sep 30 13:17:31 2017
(r324123)
+++ stable/10/usr.bin/getconf/getconf.1 Sat Sep 30 17:30:22 2017
(r324124)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 8, 2016
+.Dd September 15, 2017
 .Dt GETCONF 1
 .Os
 .Sh NAME
@@ -36,6 +36,9 @@
 .Nd retrieve standard configuration variables
 .Sh SYNOPSIS
 .Nm
+.Fl a
+.Op Ar file
+.Nm
 .Op Fl v Ar environment
 .Ar path_var
 .Ar file
@@ -45,20 +48,35 @@
 .Sh DESCRIPTION
 The
 .Nm
-utility prints the value of a
+utility prints the values of
 .Tn POSIX
 or
 .Tn X/Open
-path or system configuration variable to the standard output.
-If the specified variable is undefined, the string
+path or system configuration variables to the standard output.
+If a variable is undefined, the string
 .Dq Li undefined
 is output.
 .Pp
-The first form of the command, with two mandatory
+The first form of the command displays all of the path or system configuration
+variables to standard output.
+If
+.Ar file
+is provided,
+all path configuration variables are reported for
+.Ar file
+using
+.Xr pathconf 2 .
+Otherwise,
+all system configuration variables are reported using
+.Xr confstr 3
+and
+.Xr sysconf 3.
+.Pp
+The second form of the command, with two mandatory
 arguments, retrieves file- and file system-specific
 configuration variables using
 .Xr pathconf 2 .
-The second form, with a single argument, retrieves system
+The third form, with a single argument, retrieves system
 configuration variables using
 .Xr confstr 3
 and

Modified: stable/10/usr.bin/getconf/getconf.c
==
--- stable/10/usr.bin/getconf/getconf.c Sat Sep 30 13:17:31 2017
(r324123)
+++ stable/10/usr.bin/getconf/getconf.c Sat Sep 30 17:30:22 2017
(r324124)
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,6 +42,8 @@ __FBSDID("$FreeBSD$");
 
 #include "getconf.h"
 
+static voiddo_allsys(void);
+static voiddo_allpath(const char *path);
 static voiddo_confstr(const char *name, int key);
 static voiddo_sysconf(const char *name, int key);
 static voiddo_pathconf(const char *name, int key, const char *path);
@@ -49,7 +52,8 @@ static void
 usage(void)
 {
fprintf(stderr,
-"usage: getconf [-v prog_env] system_var\n"
+"usage: getconf -a [pathname]\n"
+"   getconf [-v prog_env] system_var\n"
 "   getconf [-v prog_env] path_var pathname\n");
exit(EX_USAGE);
 }
@@ -57,13 +61,18 @@ usage(void)
 int
 main(int argc, char **argv)
 {
+   bool aflag;
int c, key, valid;
const char *name, *vflag, *alt_path;
intmax_t limitval;
 
+   aflag = false;
vflag = NULL;
-   while ((c = getopt(argc, argv, "v:")) != -1) {
+   while ((c = getopt(argc, argv, "av:")) != -1) {
switch (c) {
+   case 'a':
+   aflag = true;
+   break;
case 'v':
vflag = optarg;
break;
@@ -73,6 +82,16 @@ main(int argc, char **argv)
}
}
 
+   if (aflag) {
+   if (vflag != NULL)
+