getconf default output

Thorsten Kukuk kukuk@suse.de
Tue Jan 11 09:14:00 GMT 2005


On Tue, Aug 31, Andreas Schwab wrote:

> Ulrich Drepper <drepper@redhat.com> writes:
> 
> > Nix wrote:
> >
> >> What might make sense is printing out the names without the values,
> >
> > That's not much use.
> 
> I disagree.  It often happens to me that I'm looking for a specific
> parameter but can't remember exactly how it is spelled.  Getting the list
> of all names from running getconf is much faster than looking them up in
> the manual.  So at least having an option to print the list would be
> useful, IMHO.

Since other Unix like Solaris also have such an option and people
are asking for it, I bring this up again with an adjusted patch
we use already for SuSE Linux.
Like on Solaris I added the option "-a", which Writes the names of
the current configuration variables to the standard output.

I see only benefits from this patch, no disadvantages.

  Thorsten

-- 
Thorsten Kukuk         http://www.suse.de/~kukuk/      kukuk@suse.de
SuSE Linux Products GmbH       Maxfeldstr. 5       D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B
-------------- next part --------------
2005-01-11  Thorsten Kukuk  <kukuk@suse.de>

        * posix/getconf.c: Add new option -a to print the names of
        the current system configuration variables to stdout.
        Based on patch from Josh Aas <josha@sgi.com>.

--- posix/getconf.c
+++ posix/getconf.c	2005/01/11 09:07:54
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 1995-2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 1995-2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -941,9 +941,53 @@
   fprintf (stderr,
 	   _("Usage: %s [-v specification] variable_name [pathname]\n"),
 	   __progname);
+	   _("       %s -a [pathname]\n"), __progname);
   exit (2);
 }
 
+static void
+print_all (const char *path)
+{
+  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 (path, 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[])
 {
@@ -964,7 +1008,7 @@
 Copyright (C) %s Free Software Foundation, Inc.\n\
 This is free software; see the source for copying conditions.  There is NO\n\
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2004");
+"), "2005");
       fprintf (stderr, gettext ("Written by %s.\n"), "Roland McGrath");
       return 0;
     }
@@ -1050,6 +1094,16 @@
 	}
     }
 
+  if (argc > 1 && strcmp (argv[1], "-a") == 0)
+    {
+      if (argc == 2)
+	print_all ("/");
+      else if (argc == 3)
+	print_all (argv[2]);
+      else
+	usage ();
+    }
+
   if (argc < 2 || argc > 3)
     usage ();
 


More information about the Libc-alpha mailing list