static cf_value_map_t cf_value_map[] = {{"TypesDB", dispatch_value_typesdb},
{"PluginDir", dispatch_value_plugindir},
static cf_value_map_t cf_value_map[] = {{"TypesDB", dispatch_value_typesdb},
{"PluginDir", dispatch_value_plugindir},
for (cf_cb = first_callback; cf_cb != NULL; cf_cb = cf_cb->next)
if (strcasecmp(cf_cb->type, type) == 0)
break;
for (cf_cb = first_callback; cf_cb != NULL; cf_cb = cf_cb->next)
if (strcasecmp(cf_cb->type, type) == 0)
break;
DEBUG("type = %s, key = %s, value = %s", ESCAPE_NULL(type), orig_key,
ESCAPE_NULL(orig_value));
DEBUG("type = %s, key = %s, value = %s", ESCAPE_NULL(type), orig_key,
ESCAPE_NULL(orig_value));
"the plugin isn't loaded or didn't register "
"a configuration callback.",
type);
"the plugin isn't loaded or didn't register "
"a configuration callback.",
type);
- ssnprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number);
- return (global_option_set(ci->key, tmp, 0));
+ snprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number);
+ return global_option_set(ci->key, tmp, 0);
} /* int dispatch_value_typesdb */
static int dispatch_value_plugindir(oconfig_item_t *ci) {
assert(strcasecmp(ci->key, "PluginDir") == 0);
if (ci->values_num != 1)
} /* int dispatch_value_typesdb */
static int dispatch_value_plugindir(oconfig_item_t *ci) {
assert(strcasecmp(ci->key, "PluginDir") == 0);
if (ci->values_num != 1)
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0)
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0)
} /* int dispatch_value_loadplugin */
static int dispatch_value_plugin(const char *plugin, oconfig_item_t *ci) {
} /* int dispatch_value_loadplugin */
static int dispatch_value_plugin(const char *plugin, oconfig_item_t *ci) {
- ssnprintf(buffer_ptr, buffer_free, " %s", ci->values[i].value.string);
+ snprintf(buffer_ptr, buffer_free, " %s", ci->values[i].value.string);
- status = ssnprintf(buffer_ptr, buffer_free, " %lf",
- ci->values[i].value.number);
+ status =
+ snprintf(buffer_ptr, buffer_free, " %lf", ci->values[i].value.number);
- status = ssnprintf(buffer_ptr, buffer_free, " %s",
- ci->values[i].value.boolean ? "true" : "false");
+ status = snprintf(buffer_ptr, buffer_free, " %s",
+ ci->values[i].value.boolean ? "true" : "false");
} /* int dispatch_value */
static int dispatch_block_plugin(oconfig_item_t *ci) {
const char *name;
if (strcasecmp(ci->key, "Plugin") != 0)
} /* int dispatch_value */
static int dispatch_block_plugin(oconfig_item_t *ci) {
const char *name;
if (strcasecmp(ci->key, "Plugin") != 0)
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0) {
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0) {
}
static int dispatch_block(oconfig_item_t *ci) {
if (strcasecmp(ci->key, "LoadPlugin") == 0)
}
static int dispatch_block(oconfig_item_t *ci) {
if (strcasecmp(ci->key, "LoadPlugin") == 0)
- temp =
- realloc(dst->children, sizeof(oconfig_item_t) *
- (dst->children_num + src->children_num - 1));
+ temp = realloc(dst->children,
+ sizeof(oconfig_item_t) *
+ (dst->children_num + src->children_num - 1));
} /* int cf_ci_replace_child */
static int cf_ci_append_children(oconfig_item_t *dst, oconfig_item_t *src) {
oconfig_item_t *temp;
if ((src == NULL) || (src->children_num == 0))
} /* int cf_ci_replace_child */
static int cf_ci_append_children(oconfig_item_t *dst, oconfig_item_t *src) {
oconfig_item_t *temp;
if ((src == NULL) || (src->children_num == 0))
/* Now replace the i'th child in `root' with `new'. */
if (cf_ci_replace_child(root, new, i) < 0) {
sfree(new->values);
sfree(new);
/* Now replace the i'th child in `root' with `new'. */
if (cf_ci_replace_child(root, new, i) < 0) {
sfree(new->values);
sfree(new);
} /* int cf_include_all */
static oconfig_item_t *cf_read_file(const char *file, const char *pattern,
} /* int cf_include_all */
static oconfig_item_t *cf_read_file(const char *file, const char *pattern,
root = oconfig_parse_file(file);
if (root == NULL) {
ERROR("configfile: Cannot read file `%s'.", file);
root = oconfig_parse_file(file);
if (root == NULL) {
ERROR("configfile: Cannot read file `%s'.", file);
} /* oconfig_item_t *cf_read_file */
static int cf_compare_string(const void *p1, const void *p2) {
} /* oconfig_item_t *cf_read_file */
static int cf_compare_string(const void *p1, const void *p2) {
- char errbuf[1024];
- ERROR("configfile: opendir failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
- return (NULL);
+ ERROR("configfile: opendir failed: %s", STRERRNO);
+ return NULL;
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
closedir(dh);
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
closedir(dh);
- status = ssnprintf(name, sizeof(name), "%s/%s", dir, de->d_name);
+ status = snprintf(name, sizeof(name), "%s/%s", dir, de->d_name);
if ((status < 0) || ((size_t)status >= sizeof(name))) {
ERROR("configfile: Not including `%s/%s' because its"
" name is too long.",
if ((status < 0) || ((size_t)status >= sizeof(name))) {
ERROR("configfile: Not including `%s/%s' because its"
" name is too long.",
}
qsort((void *)filenames, filenames_num, sizeof(*filenames),
}
qsort((void *)filenames, filenames_num, sizeof(*filenames),
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
}
status = wordexp(path, &we, WRDE_NOCMD);
if (status != 0) {
ERROR("configfile: wordexp (%s) failed.", path);
}
status = wordexp(path, &we, WRDE_NOCMD);
if (status != 0) {
ERROR("configfile: wordexp (%s) failed.", path);
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
- char errbuf[1024];
- WARNING("configfile: stat (%s) failed: %s", path_ptr,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("configfile: stat (%s) failed: %s", path_ptr, STRERRNO);
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
- char errbuf[1024];
- ERROR("configfile: stat (%s) failed: %s", path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
- return (NULL);
+ ERROR("configfile: stat (%s) failed: %s", path, STRERRNO);
+ return NULL;
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot set unknown global option `%s'.", option);
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot set unknown global option `%s'.", option);
}
if (cf_global_options[i].from_cli && (!from_cli)) {
DEBUG("configfile: Ignoring %s `%s' option because "
"it was overriden by a command-line option.",
option, value);
}
if (cf_global_options[i].from_cli && (!from_cli)) {
DEBUG("configfile: Ignoring %s `%s' option because "
"it was overriden by a command-line option.",
option, value);
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot get unknown global option `%s'.", option);
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot get unknown global option `%s'.", option);
- return ((cf_global_options[i].value != NULL) ? cf_global_options[i].value
- : cf_global_options[i].def);
+ return (cf_global_options[i].value != NULL) ? cf_global_options[i].value
+ : cf_global_options[i].def;
} /* char *global_option_get */
long global_option_get_long(const char *option, long default_value) {
} /* char *global_option_get */
long global_option_get_long(const char *option, long default_value) {
} /* char *global_option_get_long */
cdtime_t global_option_get_time(const char *name, cdtime_t def) /* {{{ */
} /* char *global_option_get_long */
cdtime_t global_option_get_time(const char *name, cdtime_t def) /* {{{ */
errno = 0;
v = strtod(optstr, &endptr);
if ((endptr == NULL) || (*endptr != 0) || (errno != 0))
errno = 0;
v = strtod(optstr, &endptr);
if ((endptr == NULL) || (*endptr != 0) || (errno != 0))
- return (global_option_get_time(
- "Interval", DOUBLE_TO_CDTIME_T(COLLECTD_DEFAULT_INTERVAL)));
+ return global_option_get_time("Interval",
+ DOUBLE_TO_CDTIME_T(COLLECTD_DEFAULT_INTERVAL));
conf = cf_read_generic(filename, /* pattern = */ NULL, /* depth = */ 0);
if (conf == NULL) {
ERROR("Unable to read config file %s.", filename);
conf = cf_read_generic(filename, /* pattern = */ NULL, /* depth = */ 0);
if (conf == NULL) {
ERROR("Unable to read config file %s.", filename);
} else if (conf->children_num == 0) {
ERROR("Configuration file %s is empty.", filename);
oconfig_free(conf);
} else if (conf->children_num == 0) {
ERROR("Configuration file %s is empty.", filename);
oconfig_free(conf);
ERROR("cf_util_get_string: The %s option requires "
"exactly one string argument.",
ci->key);
ERROR("cf_util_get_string: The %s option requires "
"exactly one string argument.",
ci->key);
} /* }}} int cf_util_get_string */
/* Assures the config option is a string and copies it to the provided buffer.
} /* }}} int cf_util_get_string */
/* Assures the config option is a string and copies it to the provided buffer.
int cf_util_get_string_buffer(const oconfig_item_t *ci, char *buffer, /* {{{ */
size_t buffer_size) {
if ((ci == NULL) || (buffer == NULL) || (buffer_size < 1))
int cf_util_get_string_buffer(const oconfig_item_t *ci, char *buffer, /* {{{ */
size_t buffer_size) {
if ((ci == NULL) || (buffer == NULL) || (buffer_size < 1))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("cf_util_get_string_buffer: The %s option requires "
"exactly one string argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("cf_util_get_string_buffer: The %s option requires "
"exactly one string argument.",
ci->key);
}
strncpy(buffer, ci->values[0].value.string, buffer_size);
buffer[buffer_size - 1] = 0;
}
strncpy(buffer, ci->values[0].value.string, buffer_size);
buffer[buffer_size - 1] = 0;
} /* }}} int cf_util_get_string_buffer */
/* Assures the config option is a number and returns it as an int. */
int cf_util_get_int(const oconfig_item_t *ci, int *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
} /* }}} int cf_util_get_string_buffer */
/* Assures the config option is a number and returns it as an int. */
int cf_util_get_int(const oconfig_item_t *ci, int *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_int: The %s option requires "
"exactly one numeric argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_int: The %s option requires "
"exactly one numeric argument.",
ci->key);
} /* }}} int cf_util_get_int */
int cf_util_get_double(const oconfig_item_t *ci, double *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
} /* }}} int cf_util_get_int */
int cf_util_get_double(const oconfig_item_t *ci, double *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_double: The %s option requires "
"exactly one numeric argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_double: The %s option requires "
"exactly one numeric argument.",
ci->key);
if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) &&
(ci->values[0].type != OCONFIG_TYPE_STRING))) {
ERROR("cf_util_get_boolean: The %s option requires "
"exactly one boolean argument.",
ci->key);
if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) &&
(ci->values[0].type != OCONFIG_TYPE_STRING))) {
ERROR("cf_util_get_boolean: The %s option requires "
"exactly one boolean argument.",
ci->key);
ci->values[0].value.string, ci->key);
if (IS_TRUE(ci->values[0].value.string))
ci->values[0].value.string, ci->key);
if (IS_TRUE(ci->values[0].value.string))
else {
ERROR("cf_util_get_boolean: Cannot parse string value `%s' of the `%s' "
"option as a boolean value.",
ci->values[0].value.string, ci->key);
else {
ERROR("cf_util_get_boolean: Cannot parse string value `%s' of the `%s' "
"option as a boolean value.",
ci->values[0].value.string, ci->key);
} /* }}} int cf_util_get_boolean */
int cf_util_get_flag(const oconfig_item_t *ci, /* {{{ */
unsigned int *ret_value, unsigned int flag) {
int status;
} /* }}} int cf_util_get_boolean */
int cf_util_get_flag(const oconfig_item_t *ci, /* {{{ */
unsigned int *ret_value, unsigned int flag) {
int status;
} /* }}} int cf_util_get_flag */
/* Assures that the config option is a string or a number if the correct range
} /* }}} int cf_util_get_flag */
/* Assures that the config option is a string or a number if the correct range
ERROR("cf_util_get_port_number: The \"%s\" option requires "
"exactly one string argument.",
ci->key);
ERROR("cf_util_get_port_number: The \"%s\" option requires "
"exactly one string argument.",
ci->key);
} /* }}} int cf_util_get_port_number */
int cf_util_get_service(const oconfig_item_t *ci, char **ret_string) /* {{{ */
} /* }}} int cf_util_get_port_number */
int cf_util_get_service(const oconfig_item_t *ci, char **ret_string) /* {{{ */
if (ci->values[0].type != OCONFIG_TYPE_NUMBER) {
ERROR("cf_util_get_service: The %s option requires "
"exactly one string or numeric argument.",
if (ci->values[0].type != OCONFIG_TYPE_NUMBER) {
ERROR("cf_util_get_service: The %s option requires "
"exactly one string or numeric argument.",
else if ((port < 1) || (port > 65535)) {
ERROR("cf_util_get_service: The port number given "
"for the %s option is out of "
"range (%i).",
ci->key, port);
else if ((port < 1) || (port > 65535)) {
ERROR("cf_util_get_service: The port number given "
"for the %s option is out of "
"range (%i).",
ci->key, port);
- ssnprintf(service, 6, "%i", port);
+ snprintf(service, 6, "%i", port);
} /* }}} int cf_util_get_service */
int cf_util_get_cdtime(const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
} /* }}} int cf_util_get_service */
int cf_util_get_cdtime(const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_cdtime: The %s option requires "
"exactly one numeric argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_cdtime: The %s option requires "
"exactly one numeric argument.",
ci->key);
}
if (ci->values[0].value.number < 0.0) {
ERROR("cf_util_get_cdtime: The numeric argument of the %s "
"option must not be negative.",
ci->key);
}
if (ci->values[0].value.number < 0.0) {
ERROR("cf_util_get_cdtime: The numeric argument of the %s "
"option must not be negative.",
ci->key);