From 3d0063c4197f7e8896e9505deaeaefe825f81fed Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sun, 1 Apr 2007 13:21:51 +0200 Subject: [PATCH] do plugin_lookup() only when needed --- network.c | 12 +++--------- network.h | 2 +- plugins.c | 4 ++-- rrdtool.c | 14 ++++++++++---- rrdtool.h | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/network.c b/network.c index 36a4637..512ab16 100644 --- a/network.c +++ b/network.c @@ -30,13 +30,13 @@ static LIST_HEAD(fwd_list); static char *tx_buf, *rx_buf; static int tx_pos; -int net_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data) +int net_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data) { if (list_empty(&fwd_list)) return 0; int size = snprintf(tx_buf + tx_pos, BUFSIZE - tx_pos, "%s:%s:%s:%d %s\n", - hostname, plugin->name, filename, ds_id, data); + hostname, pluginname, filename, ds_id, data); if (size < 0 || size >= BUFSIZE - tx_pos) { log_print(LOG_ERROR, "net_submit(): arguments too long"); @@ -83,13 +83,7 @@ static int net_receive(int socket, void *privdata) continue; } - struct sammler_plugin *plugin = plugin_lookup(part[1]); - if (plugin == NULL) { - log_print(LOG_ERROR, "net_receive(): plugin not found (%s)", part[1]); - continue; - } - - rrd_submit(part[0], plugin, part[2], atoi(part[3]), data[1]); + rrd_submit(part[0], part[1], part[2], atoi(part[3]), data[1]); rx_pos = (delim - rx_buf) +1; } diff --git a/network.h b/network.h index c14309e..f373d19 100644 --- a/network.h +++ b/network.h @@ -5,7 +5,7 @@ int net_init(void); -int net_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data); +int net_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data); void net_submit_flush(void); #endif /* _NETWORK_H_ */ diff --git a/plugins.c b/plugins.c index 6739258..8c9bc9f 100644 --- a/plugins.c +++ b/plugins.c @@ -175,10 +175,10 @@ int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, return -1; } - net_submit(hostname, plugin, filename, ds_id, buffer); + net_submit(hostname, plugin->name, filename, ds_id, buffer); if (!(submit_flags & SUBMIT_NET_ONLY)) - rrd_submit(hostname, plugin, filename, ds_id, buffer); + rrd_submit(hostname, plugin->name, filename, ds_id, buffer); free(buffer); return 0; diff --git a/rrdtool.c b/rrdtool.c index 8541e2f..39caca4 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -81,8 +81,14 @@ static int do_rrd(int (*rrd_func)(int, char **), char *cmd) return retval; } -static int rrd_create_file(const char *filename, struct sammler_plugin *plugin, int ds_id) +static int rrd_create_file(const char *filename, const char *pluginname, int ds_id) { + struct sammler_plugin *plugin = plugin_lookup(pluginname); + if (plugin == NULL) { + log_print(LOG_ERROR, "rrd_create_file: plugin not found (%s)", pluginname); + return -1; + } + const char *ds_def = plugin->get_ds(ds_id); if (ds_def == NULL) { log_print(LOG_ERROR, "No vaild DS found (%s:%d)", plugin->name, ds_id); @@ -91,7 +97,7 @@ static int rrd_create_file(const char *filename, struct sammler_plugin *plugin, char *buffer = malloc(ARGVSIZE); if (buffer == NULL) { - log_print(LOG_ERROR, "append_ds_config: out of memory"); + log_print(LOG_ERROR, "rrd_create_file: out of memory"); return -1; } @@ -193,7 +199,7 @@ static int create_parent_dirs(char *filename) return 0; } -int rrd_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data) +int rrd_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data) { static const char *rrd_dir = NULL; if (rrd_dir == NULL) @@ -222,7 +228,7 @@ int rrd_submit(const char *hostname, struct sammler_plugin *plugin, const char * return -1; } - if (rrd_create_file(fullfile, plugin, ds_id) == -1) { + if (rrd_create_file(fullfile, pluginname, ds_id) == -1) { free(fullfile); return -1; } diff --git a/rrdtool.h b/rrdtool.h index 7ca7855..3eb22aa 100644 --- a/rrdtool.h +++ b/rrdtool.h @@ -2,7 +2,7 @@ #define _RRDTOOL_H_ #ifdef WITH_RRD -int rrd_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data); +int rrd_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data); #else #define rrd_submit(hostname, plugin, filename, ds_id, data) #endif