From: Sebastian Harl Date: Sun, 8 Aug 2010 21:23:40 +0000 (+0200) Subject: collectdctl: Added ‘listval’ command. X-Git-Tag: collectd-5.0.0-beta0~62 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1252d60cdbd86328ecb815e978dbfa380c29b385;p=collectd.git collectdctl: Added ‘listval’ command. --- diff --git a/src/collectdctl.c b/src/collectdctl.c index 6e53ddc1..85ad198d 100644 --- a/src/collectdctl.c +++ b/src/collectdctl.c @@ -58,6 +58,7 @@ static void exit_usage (const char *name, int status) { " * getval \n" " * flush [timeout=] [plugin=] [identifier=]\n" + " * listval\n" "\nIdentifiers:\n\n" @@ -245,8 +246,52 @@ static int flush (lcc_connection_t *c, int argc, char **argv) } return 0; +#undef BAIL_OUT } /* flush */ +static int listval (lcc_connection_t *c, int argc, char **argv) +{ + lcc_identifier_t *ret_ident = NULL; + size_t ret_ident_num = 0; + + int status; + size_t i; + + assert (strcasecmp (argv[0], "listval") == 0); + + if (argc != 1) { + fprintf (stderr, "ERROR: listval: Does not accept any arguments.\n"); + return (-1); + } + +#define BAIL_OUT(s) \ + do { \ + if (ret_ident != NULL) \ + free (ret_ident); \ + ret_ident_num = 0; \ + return (s); \ + } while (0) + + status = lcc_listval (c, &ret_ident, &ret_ident_num); + if (status != 0) + BAIL_OUT (status); + + for (i = 0; i < ret_ident_num; ++i) { + char id[1024]; + + status = lcc_identifier_to_string (c, id, sizeof (id), ret_ident + i); + if (status != 0) { + fprintf (stderr, "ERROR: listval: Failed to convert returned " + "identifier to a string.\n"); + continue; + } + + printf ("%s\n", id); + } + BAIL_OUT (0); +#undef BAIL_OUT +} /* listval */ + int main (int argc, char **argv) { char address[1024] = "unix:"DEFAULT_SOCK; @@ -292,6 +337,8 @@ int main (int argc, char **argv) { status = getval (c, argc - optind, argv + optind); else if (strcasecmp (argv[optind], "flush") == 0) status = flush (c, argc - optind, argv + optind); + else if (strcasecmp (argv[optind], "listval") == 0) + status = listval (c, argc - optind, argv + optind); else { fprintf (stderr, "%s: invalid command: %s\n", argv[0], argv[optind]); return (1);