X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectdctl.c;h=31183b1c8b83b37963fb4b34052d400cffdc96f4;hb=448627953cde2f7b3b138f53f4f2c62f0d48b726;hp=d019d2742f3db6bef5d98f653ed144cdf4a42895;hpb=56536633afb68ded68ac7bd012060cb9337fbcc5;p=collectd.git diff --git a/src/collectdctl.c b/src/collectdctl.c index d019d274..31183b1c 100644 --- a/src/collectdctl.c +++ b/src/collectdctl.c @@ -72,6 +72,7 @@ extern char *optarg; extern int optind; +__attribute__((noreturn)) static void exit_usage (const char *name, int status) { fprintf ((status == 0) ? stdout : stderr, "Usage: %s [options] [cmd options]\n\n" @@ -120,7 +121,7 @@ static int count_chars (const char *str, char chr) { return count; } /* count_chars */ -static int array_grow (void **array, int *array_len, size_t elem_size) +static int array_grow (void **array, size_t *array_len, size_t elem_size) { void *tmp; @@ -184,7 +185,6 @@ static int getval (lcc_connection_t *c, int argc, char **argv) char **ret_values_names = NULL; int status; - size_t i; assert (strcasecmp (argv[0], "getval") == 0); @@ -193,7 +193,6 @@ static int getval (lcc_connection_t *c, int argc, char **argv) return (-1); } - memset (&ident, 0, sizeof (ident)); status = parse_identifier (c, argv[1], &ident); if (status != 0) return (status); @@ -203,7 +202,7 @@ static int getval (lcc_connection_t *c, int argc, char **argv) if (ret_values != NULL) \ free (ret_values); \ if (ret_values_names != NULL) { \ - for (i = 0; i < ret_values_num; ++i) \ + for (size_t i = 0; i < ret_values_num; ++i) \ free (ret_values_names[i]); \ free (ret_values_names); \ } \ @@ -218,7 +217,7 @@ static int getval (lcc_connection_t *c, int argc, char **argv) BAIL_OUT (-1); } - for (i = 0; i < ret_values_num; ++i) + for (size_t i = 0; i < ret_values_num; ++i) printf ("%s=%e\n", ret_values_names[i], ret_values[i]); BAIL_OUT (0); #undef BAIL_OUT @@ -229,13 +228,12 @@ static int flush (lcc_connection_t *c, int argc, char **argv) int timeout = -1; lcc_identifier_t *identifiers = NULL; - int identifiers_num = 0; + size_t identifiers_num = 0; char **plugins = NULL; - int plugins_num = 0; + size_t plugins_num = 0; int status; - int i; assert (strcasecmp (argv[0], "flush") == 0); @@ -250,7 +248,7 @@ static int flush (lcc_connection_t *c, int argc, char **argv) return (s); \ } while (0) - for (i = 1; i < argc; ++i) { + for (int i = 1; i < argc; ++i) { char *key, *value; key = argv[i]; @@ -314,7 +312,7 @@ static int flush (lcc_connection_t *c, int argc, char **argv) plugins[0] = NULL; } - for (i = 0; i < plugins_num; ++i) { + for (size_t i = 0; i < plugins_num; ++i) { if (identifiers_num == 0) { status = lcc_flush (c, plugins[i], NULL, timeout); if (status != 0) @@ -322,9 +320,7 @@ static int flush (lcc_connection_t *c, int argc, char **argv) (plugins[i] == NULL) ? "(all)" : plugins[i], lcc_strerror (c)); } else { - int j; - - for (j = 0; j < identifiers_num; ++j) { + for (size_t j = 0; j < identifiers_num; ++j) { status = lcc_flush (c, plugins[i], identifiers + j, timeout); if (status != 0) { char id[1024]; @@ -349,7 +345,6 @@ static int listval (lcc_connection_t *c, int argc, char **argv) size_t ret_ident_num = 0; int status; - size_t i; assert (strcasecmp (argv[0], "listval") == 0); @@ -372,7 +367,7 @@ static int listval (lcc_connection_t *c, int argc, char **argv) BAIL_OUT (status); } - for (i = 0; i < ret_ident_num; ++i) { + for (size_t i = 0; i < ret_ident_num; ++i) { char id[1024]; status = lcc_identifier_to_string (c, id, sizeof (id), ret_ident + i); @@ -398,7 +393,6 @@ static int putval (lcc_connection_t *c, int argc, char **argv) size_t values_len = 0; int status; - int i; assert (strcasecmp (argv[0], "putval") == 0); @@ -415,7 +409,7 @@ static int putval (lcc_connection_t *c, int argc, char **argv) if (status != 0) return (status); - for (i = 2; i < argc; ++i) { + for (int i = 2; i < argc; ++i) { char *tmp; tmp = strchr (argv[i], (int)'='); @@ -482,7 +476,7 @@ static int putval (lcc_connection_t *c, int argc, char **argv) values_len = 0; value = tmp; - while (value != 0) { + while (value != NULL) { char *dot, *endptr; tmp = strchr (value, (int)':'); @@ -507,7 +501,7 @@ static int putval (lcc_connection_t *c, int argc, char **argv) values_types[values_len] = LCC_TYPE_GAUGE; } else { /* integer */ - values[values_len].counter = strtol (value, &endptr, 0); + values[values_len].counter = (counter_t) strtoull (value, &endptr, 0); values_types[values_len] = LCC_TYPE_COUNTER; } ++values_len; @@ -551,21 +545,20 @@ int main (int argc, char **argv) { int status; while (42) { - int n; + int opt; - n = getopt (argc, argv, "s:h"); + opt = getopt (argc, argv, "s:h"); - if (n == -1) + if (opt == -1) break; - switch (n) { + switch (opt) { case 's': snprintf (address, sizeof (address), "unix:%s", optarg); address[sizeof (address) - 1] = '\0'; break; case 'h': exit_usage (argv[0], 0); - break; default: exit_usage (argv[0], 1); }