summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ad007ff)
raw | patch | inline | side by side (parent: ad007ff)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 19 Aug 2010 12:33:27 +0000 (14:33 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 19 Aug 2010 12:33:27 +0000 (14:33 +0200) |
src/collectd-tg.c | patch | blob | history |
diff --git a/src/collectd-tg.c b/src/collectd-tg.c
index 7b86deb27daa8dbe47cd13ab3896371d0c87e11f..3cc9df7de4bce2b3b33682539fc2dc04595abb28 100644 (file)
--- a/src/collectd-tg.c
+++ b/src/collectd-tg.c
#include <string.h>
#include <time.h>
#include <signal.h>
+#include <errno.h>
#include "utils_heap.h"
return (0);
} /* }}} int send_value */
+static int get_integer_opt (const char *str, int *ret_value) /* {{{ */
+{
+ char *endptr;
+ int tmp;
+
+ errno = 0;
+ endptr = NULL;
+ tmp = (int) strtol (str, &endptr, /* base = */ 0);
+ if (errno != 0)
+ {
+ fprintf (stderr, "Unable to parse option as a number: \"%s\": %s\n",
+ str, strerror (errno));
+ exit (EXIT_FAILURE);
+ }
+ else if (endptr == str)
+ {
+ fprintf (stderr, "Unable to parse option as a number: \"%s\"\n", str);
+ exit (EXIT_FAILURE);
+ }
+ else if (*endptr != 0)
+ {
+ fprintf (stderr, "Garbage after end of value: \"%s\"\n", str);
+ exit (EXIT_FAILURE);
+ }
+
+ *ret_value = tmp;
+ return (0);
+} /* }}} int get_integer_opt */
+
static int read_options (int argc, char **argv) /* {{{ */
{
int opt;
- while ((opt = getopt (argc, argv, "n:H:p:d:D:h")) != -1)
+ while ((opt = getopt (argc, argv, "n:H:p:i:d:D:h")) != -1)
{
switch (opt)
{
case 'n':
- {
- int tmp = atoi (optarg);
- if (tmp < 1)
- {
- fprintf (stderr, "Unable to parse option as a number: \"%s\"\n",
- optarg);
- exit (EXIT_FAILURE);
- }
- conf_num_values = tmp;
- }
+ get_integer_opt (optarg, &conf_num_values);
break;
case 'H':
- {
- int tmp = atoi (optarg);
- if (tmp < 1)
- {
- fprintf (stderr, "Unable to parse option as a number: \"%s\"\n",
- optarg);
- exit (EXIT_FAILURE);
- }
- conf_num_hosts = tmp;
- }
+ get_integer_opt (optarg, &conf_num_hosts);
break;
case 'p':
- {
- int tmp = atoi (optarg);
- if (tmp < 1)
- {
- fprintf (stderr, "Unable to parse option as a number: \"%s\"\n",
- optarg);
- exit (EXIT_FAILURE);
- }
- conf_num_plugins = tmp;
- }
+ get_integer_opt (optarg, &conf_num_plugins);
break;
case 'd':