X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftable.c;h=20f02756c44bf77de78f01d9676b96b2054eee3e;hb=849f5394cce97a76da080f6cd9e5194b7f4ee0f0;hp=eb18660cb82a7732a8c52af58d9a6b40f63b3a39;hpb=35a6c9c5fcd87cb78451a974c4d5b5707926845c;p=collectd.git diff --git a/src/table.c b/src/table.c index eb18660c..20f02756 100644 --- a/src/table.c +++ b/src/table.c @@ -55,6 +55,7 @@ typedef struct { typedef struct { char *file; char *sep; + char *plugin_name; char *instance; tbl_result_t *results; @@ -96,6 +97,7 @@ static void tbl_result_clear(tbl_result_t *res) { static void tbl_setup(tbl_t *tbl, char *file) { tbl->file = sstrdup(file); tbl->sep = NULL; + tbl->plugin_name = NULL; tbl->instance = NULL; tbl->results = NULL; @@ -111,6 +113,7 @@ static void tbl_clear(tbl_t *tbl) { sfree(tbl->file); sfree(tbl->sep); + sfree(tbl->plugin_name); sfree(tbl->instance); /* (tbl->results == NULL) -> (tbl->results_num == 0) */ @@ -161,8 +164,7 @@ static int tbl_config_append_array_i(char *name, size_t **var, size_t *len, tmp = realloc(*var, ((*len) + num) * sizeof(**var)); if (NULL == tmp) { - char errbuf[1024]; - log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf))); + log_err("realloc failed: %s.", STRERRNO); return -1; } *var = tmp; @@ -184,8 +186,7 @@ static int tbl_config_result(tbl_t *tbl, oconfig_item_t *ci) { tbl_result_t *res = realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results)); if (res == NULL) { - char errbuf[1024]; - log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf))); + log_err("realloc failed: %s.", STRERRNO); return -1; } @@ -242,8 +243,7 @@ static int tbl_config_table(oconfig_item_t *ci) { tbl_t *tbl = realloc(tables, (tables_num + 1) * sizeof(*tables)); if (NULL == tbl) { - char errbuf[1024]; - log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf))); + log_err("realloc failed: %s.", STRERRNO); return -1; } @@ -257,6 +257,8 @@ static int tbl_config_table(oconfig_item_t *ci) { if (0 == strcasecmp(c->key, "Separator")) tbl_config_set_s(c->key, &tbl->sep, c); + else if (0 == strcasecmp(c->key, "Plugin")) + tbl_config_set_s(c->key, &tbl->plugin_name, c); else if (0 == strcasecmp(c->key, "Instance")) tbl_config_set_s(c->key, &tbl->instance, c); else if (0 == strcasecmp(c->key, "Result")) @@ -334,8 +336,8 @@ static int tbl_prepare(tbl_t *tbl) { } if (res->values_num != res->ds->ds_num) { - log_err("Invalid type \"%s\". Expected %zu data source%s, " - "got %zu.", + log_err("Invalid type \"%s\". Expected %" PRIsz " data source%s, " + "got %" PRIsz ".", res->type, res->values_num, (1 == res->values_num) ? "" : "s", res->ds->ds_num); return -1; @@ -371,7 +373,8 @@ static int tbl_result_dispatch(tbl_t *tbl, tbl_result_t *res, char **fields, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE(values); - sstrncpy(vl.plugin, "table", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (tbl->plugin_name != NULL) ? tbl->plugin_name : "table", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, tbl->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, res->type, sizeof(vl.type)); @@ -427,7 +430,7 @@ static int tbl_parse_line(tbl_t *tbl, char *line, size_t len) { if (i <= tbl->max_colnum) { log_warn("Not enough columns in line " - "(expected at least %zu, got %zu).", + "(expected at least %" PRIsz ", got %" PRIsz ").", tbl->max_colnum + 1, i); return -1; } @@ -447,9 +450,7 @@ static int tbl_read_table(tbl_t *tbl) { fh = fopen(tbl->file, "r"); if (NULL == fh) { - char errbuf[1024]; - log_err("Failed to open file \"%s\": %s.", tbl->file, - sstrerror(errno, errbuf, sizeof(errbuf))); + log_err("Failed to open file \"%s\": %s.", tbl->file, STRERRNO); return -1; } @@ -467,9 +468,7 @@ static int tbl_read_table(tbl_t *tbl) { } if (0 != ferror(fh)) { - char errbuf[1024]; - log_err("Failed to read from file \"%s\": %s.", tbl->file, - sstrerror(errno, errbuf, sizeof(errbuf))); + log_err("Failed to read from file \"%s\": %s.", tbl->file, STRERRNO); fclose(fh); return -1; } @@ -524,5 +523,3 @@ void module_register(void) { plugin_register_complex_config("table", tbl_config); plugin_register_init("table", tbl_init); } /* module_register */ - -/* vim: set sw=4 ts=4 tw=78 noexpandtab : */