This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: getconf default output


Roland McGrath wrote:

Would it be possible to have the default output (no options) of getconf be all variables and their values instead of the usage?



Sure, send a patch to implement it.


A patch is attached. The directory assumption is simple defined with a macro at the top for easy modification if you wish. This list is useful for finding out what information is available or easy grepping for more than one value. What is printed by default now is totally useless. I don't agree that people always know the variable they are looking for, or that that is even the issue.

If this patch were landed, an update to the man page should happen to tell users what path is assumed. To not print out path-dependent variables, the removal of three or 4 lines from the patch is all that is necessary.

My implementation happens to model the IRIX sysconf command in its formatting and its path assumption. The path assumption only takes effect when NO arguments to the command are specified, of course.

--
Josh Aas
Linux System Software
Silicon Graphics, Inc. (SGI)

--- a/posix/getconf.c	2004-08-27 09:39:38.000000000 -0500
+++ b/posix/getconf.c	2004-08-27 17:31:05.000000000 -0500
@@ -27,6 +27,7 @@
 
 #include "../version.h"
 #define PACKAGE _libc_intl_domainname
+#define DEFAULT_PATH_STRING "/"
 
 struct conf
   {
@@ -894,6 +895,49 @@ usage (void)
   exit (2);
 }
 
+static void
+print_all (void)
+{
+  register const struct conf *c;
+  size_t clen;
+  long int value;
+  char *cvalue;
+  for (c = vars; c->name != NULL; ++c) {
+    printf("%-35s", c->name);
+    switch (c->call) {
+      case PATHCONF:
+        value = pathconf (DEFAULT_PATH_STRING, c->call_name);
+        if (value != -1) {
+          printf("%ld", value);
+        }
+        printf("\n");
+        break;
+      case SYSCONF:
+        value = sysconf (c->call_name);
+        if (value == -1l) {
+          if (c->call_name == _SC_UINT_MAX
+            || c->call_name == _SC_ULONG_MAX)
+            printf ("%lu", value);
+        }
+        else {
+          printf ("%ld", value);
+        }
+        printf ("\n");
+        break;
+      case CONFSTR:
+        clen = confstr (c->call_name, (char *) NULL, 0);
+        cvalue = (char *) malloc (clen);
+        if (cvalue == NULL)
+          error (3, 0, _("memory exhausted"));
+        if (confstr (c->call_name, cvalue, clen) != clen)
+          error (3, errno, "confstr");
+        printf ("%.*s\n", (int) clen, cvalue);
+        break;
+    } 
+  }
+  exit (0);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -953,8 +997,11 @@ warranty; not even for MERCHANTABILITY o
 	 with or without it.  */
     }
 
-  if (argc < 2 || argc > 3)
+  if (argc < 2)
+    print_all ();
+  else if (argc > 3) {
     usage ();
+  }
 
   for (c = vars; c->name != NULL; ++c)
     if (strcmp (c->name, argv[1]) == 0

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]