From: Florian Forster Date: Sun, 20 May 2007 07:55:54 +0000 (+0200) Subject: src/plugin.c: Remove slashed from host, {plugin,type}{,-instance} here. X-Git-Tag: collectd-4.0.0~11 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=aed9a008cc5d155fc08f69f3e1da1e3069deaf13;p=collectd.git src/plugin.c: Remove slashed from host, {plugin,type}{,-instance} here. A fix in the disk plugin has been removed again. --- diff --git a/src/common.c b/src/common.c index bcdf59aa..9a28cdbf 100644 --- a/src/common.c +++ b/src/common.c @@ -241,7 +241,7 @@ int strsubstitute (char *str, char c_from, char c_to) } return (ret); -} +} /* int strsubstitute */ int escape_slashes (char *buf, int buf_len) { @@ -256,8 +256,12 @@ int escape_slashes (char *buf, int buf_len) return (0); } + if (buf_len <= 1) + return (0); + /* Move one to the left */ - memmove (buf, buf + 1, buf_len - 1); + if (buf[0] == '/') + memmove (buf, buf + 1, buf_len - 1); for (i = 0; i < buf_len - 1; i++) { @@ -269,7 +273,7 @@ int escape_slashes (char *buf, int buf_len) buf[i] = '\0'; return (0); -} +} /* int escape_slashes */ int timeval_sub_timespec (struct timeval *tv0, struct timeval *tv1, struct timespec *ret) { diff --git a/src/common.h b/src/common.h index 6c097f6c..7808ac93 100644 --- a/src/common.h +++ b/src/common.h @@ -143,6 +143,8 @@ int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const */ int escape_slashes (char *buf, int buf_len); +int strsubstitute (char *str, char c_from, char c_to); + /* FIXME: `timeval_sub_timespec' needs a description */ int timeval_sub_timespec (struct timeval *tv0, struct timeval *tv1, struct timespec *ret); diff --git a/src/disk.c b/src/disk.c index 5739f369..38c161f5 100644 --- a/src/disk.c +++ b/src/disk.c @@ -421,13 +421,6 @@ static int disk_read (void) minor = atoll (fields[1]); disk_name = fields[2]; - { /* Strip slashes from disk_name */ - int i; - for (i = 0; disk_name[i] != '\0'; i++) - if (disk_name[i] == '/') - disk_name[i] = '_'; - } - for (ds = disklist, pre_ds = disklist; ds != NULL; pre_ds = ds, ds = ds->next) if (strcmp (disk_name, ds->name) == 0) diff --git a/src/plugin.c b/src/plugin.c index 64dbf780..36cd80af 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -613,7 +613,7 @@ void plugin_shutdown_all (void) } } /* void plugin_shutdown_all */ -int plugin_dispatch_values (const char *name, const value_list_t *vl) +int plugin_dispatch_values (const char *name, value_list_t *vl) { int (*callback) (const data_set_t *, const value_list_t *); data_set_t *ds; @@ -650,6 +650,11 @@ int plugin_dispatch_values (const char *name, const value_list_t *vl) } #endif + escape_slashes (vl->host, sizeof (vl->host)); + escape_slashes (vl->plugin, sizeof (vl->plugin)); + escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance)); + escape_slashes (vl->type_instance, sizeof (vl->type_instance)); + le = llist_head (list_write); while (le != NULL) { @@ -660,7 +665,7 @@ int plugin_dispatch_values (const char *name, const value_list_t *vl) } return (0); -} +} /* int plugin_dispatch_values */ void plugin_log (int level, const char *format, ...) { diff --git a/src/plugin.h b/src/plugin.h index db556fce..83c21094 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -178,7 +178,7 @@ int plugin_unregister_log (const char *name); * `vl' Value list of the values that have been read by a `read' * function. */ -int plugin_dispatch_values (const char *name, const value_list_t *vl); +int plugin_dispatch_values (const char *name, value_list_t *vl); void plugin_log (int level, const char *format, ...); #define ERROR(...) plugin_log (LOG_ERR, __VA_ARGS__)