summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5e02dec)
raw | patch | inline | side by side (parent: 5e02dec)
author | Florian Forster <octo@collectd.org> | |
Mon, 8 Sep 2014 09:16:39 +0000 (11:16 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 8 Sep 2014 09:16:39 +0000 (11:16 +0200) |
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index d3d3841250fae0c784706cb512ad5b35b68553ba..9a5807ce07f210b670ea732ddca7c5a355eafb7a 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
return (value);
} /* char *global_option_get_long */
+cdtime_t global_option_get_time (const char *name, cdtime_t def) /* {{{ */
+{
+ char const *optstr;
+ char *endptr = NULL;
+ double v;
+
+ optstr = global_option_get (name);
+ if (optstr == NULL)
+ return (def);
+
+ errno = 0;
+ v = strtod (optstr, &endptr);
+ if ((endptr == NULL) || (*endptr != 0) || (errno != 0))
+ return (def);
+ else if (v >= 0.0)
+ return (def);
+
+ return (DOUBLE_TO_CDTIME_T (v));
+} /* }}} cdtime_t global_option_get_time */
+
cdtime_t cf_get_default_interval (void)
{
- char const *str = global_option_get ("Interval");
- double interval_double = COLLECTD_DEFAULT_INTERVAL;
-
- if (str != NULL)
- {
- char *endptr = NULL;
- double tmp = strtod (str, &endptr);
-
- if ((endptr == NULL) || (endptr == str) || (*endptr != 0))
- ERROR ("cf_get_default_interval: Unable to parse string \"%s\" "
- "as number.", str);
- else if (tmp <= 0.0)
- ERROR ("cf_get_default_interval: Interval must be a positive number. "
- "The current number is %g.", tmp);
- else
- interval_double = tmp;
- }
-
- return (DOUBLE_TO_CDTIME_T (interval_double));
-} /* }}} cdtime_t cf_get_default_interval */
+ return (global_option_get_time ("Interval", COLLECTD_DEFAULT_INTERVAL));
+}
void cf_unregister (const char *type)
{
diff --git a/src/configfile.h b/src/configfile.h
index 92c09de33c0b0a8a51d76bef4385c9c5e06bbece..5bc9b305615ee3404d8d373dd5544de7e88e433d 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
long global_option_get_long (const char *option, long default_value);
long global_option_get_long_in_range (const char *option, long default_value, long min, long max);
+cdtime_t global_option_get_time (char const *option, cdtime_t default_value);
+
cdtime_t cf_get_default_interval (void);
/* Assures the config option is a string, duplicates it and returns the copy in