This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
[PATCH] nscd: list all tables in usage()
- From: Sami Kerola <kerolasa at iki dot fi>
- To: libc-help at sourceware dot org, Mike Frysinger <vapier at gentoo dot org>
- Cc: kerolasa at iki dot fi
- Date: Wed, 1 Jan 2014 20:20:07 +0000
- Subject: [PATCH] nscd: list all tables in usage()
- Authentication-results: sourceware.org; auth=none
- References: <201401011227 dot 22465 dot vapier at gentoo dot org>
On 1 January 2014 17:27, Mike Frysinger <vapier@gentoo.org> wrote:
> On Wednesday 01 January 2014 07:38:35 Sami Kerola wrote:
>> Usage output for option --invalidate=TABLE is not helpful without
>> list of tables. The list is also missing from nscd(8) manual which
>> made it pretty difficult to know what are the tables.
>
> can you show an example of before & after output ?
Hi Mike,
Here comes the new output. It has 'TABLE list: ...' line, and does not
differ any other way in-comparison with the old so I don't think there is
need to have the other output a side.
-- snip
$ ./nscd/nscd --help
Usage: nscd [OPTION...]
Name Service Cache Daemon.
-d, --debug Do not fork and display messages on the current
tty
-f, --config-file=NAME Read configuration data from NAME
-F, --foreground Do not fork, but otherwise behave like a daemon
-g, --statistics Print current configuration statistics
-i, --invalidate=TABLE Invalidate the specified cache
-K, --shutdown Shut the server down
-t, --nthreads=NUMBER Start NUMBER threads
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
TABLE list: passwd group hosts services netgroup
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
-- snip
>> --- a/nscd/nscd.c
>> +++ b/nscd/nscd.c
>> more_help (int key, const char *text, void *input)
>> {
>> - char *tp = NULL;
>> + char *tables, *p, *tp = NULL;
>> switch (key)
>> {
>> case ARGP_KEY_HELP_EXTRA:
>> + {
>> + dbtype cnt;
>> + size_t len;
>> + tables = xmalloc (sizeof (dbnames) + 1);
>
> i think GNU style says there should be a newline after the decls
Oh, good that you said. I had no idea about such convention.
>> + p = tables;
>> + for (cnt = 0; cnt < lastdb; cnt++)
>> + {
>> + len = strlen (dbnames[cnt]);
>> + memcpy (p, dbnames[cnt], len);
>> + p += len;
>> + *p++ = ' ';
>
> how about just strcat ? would be a little slower, but would be simpler
> code.
> tables = xmalloc (sizeof (dbnames) + 1);
> for (cnt = 0; cnt < lastdb; ++cnt) {
> strcat (tables, dbnames[cnt]);
> strcat (tables, ' ');
> }
Performance of usage() output surely cannot be critical. If the strcat()
is seen as easier to read I don't mind writing the change using it. See
the. Here is the second edition.
--->8----
From: Sami Kerola <kerolasa@iki.fi>
Date: Wed, 1 Jan 2014 20:17:20 +0000
Subject: [PATCH] nscd: list all tables in usage()
Usage output for option --invalidate=TABLE is not helpful without
list of tables. The list is also missing from nscd(8) manual which
made it pretty difficult to know what are the tables.
---
ChangeLog | 4 ++++
nscd/nscd.c | 20 +++++++++++++++++---
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c2c47d8..a9c7ddb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-01-01 Sami Kerola <kerolasa@iki.fi>
+
+ * nscd/nscd.c: Improve usage() output.
+
2014-01-01 Allan McRae <allan@archlinux.org>
* scripts/update-copyrights: Update configure input file suffix.
diff --git a/nscd/nscd.c b/nscd/nscd.c
index e7f04f8..755c060 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -442,15 +442,29 @@ parse_opt (int key, char *arg, struct argp_state *state)
static char *
more_help (int key, const char *text, void *input)
{
- char *tp = NULL;
+ char *tables, *tp = NULL;
switch (key)
{
case ARGP_KEY_HELP_EXTRA:
+ {
+ dbtype cnt;
+
+ tables = xcalloc (1, sizeof (dbnames) + 1);
+ for (cnt = 0; cnt < lastdb; cnt++)
+ {
+ strcat (tables, dbnames[cnt]);
+ strcat (tables, " ");
+ }
+ }
+
/* We print some extra information. */
if (asprintf (&tp, gettext ("\
+TABLE names are: %s\n\
+\n\
For bug reporting instructions, please see:\n\
-%s.\n"), REPORT_BUGS_TO) < 0)
- return NULL;
+%s.\n"), tables, REPORT_BUGS_TO) < 0)
+ tp = NULL;
+ free(tables);
return tp;
default:
break;
--
1.8.5.2