From ebf4af7f1332105fd6f9b33f39b630bf72d50b02 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sat, 7 Oct 2006 20:48:20 +0200 Subject: [PATCH] misc fixes --- network.c | 41 ++++++++++++++++++++--------------------- network.h | 2 +- plugins.c | 7 ++++--- plugins.h | 2 +- rrdtool.c | 15 ++++++++------- rrdtool.h | 2 +- sammler.c | 2 +- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/network.c b/network.c index 8bab5af..61dd9ec 100644 --- a/network.c +++ b/network.c @@ -27,18 +27,19 @@ struct fwd_entry { // todo: never freed.. static char *tx_buf, *rx_buf; -void net_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data) +int net_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data) { int size = snprintf(tx_buf, BUFSIZE, "%s:%s:%s:%d %s", hostname, plugin, filename, ds_id, data); if (size < 0 || size >= BUFSIZE) { log_print(LOG_ERROR, "net_submit(): arguments too long"); - return; + return -1; } struct fwd_entry *entry; list_for_each_entry(entry, &fwd_list, list) sendto(entry->sock, tx_buf, size +1, 0, (struct sockaddr *)&entry->sa, sizeof(entry->sa)); + return 0; } int net_receive(int socket) @@ -124,25 +125,23 @@ static int net_add_cli(char *addr) int net_init_cli() { - struct conf_section *section; - struct conf_tupel *tupel; - - section = config_get_section("global"); - if (section == NULL) - return 0; - - int retval = 0; - list_for_each_entry(tupel, §ion->tupel, list) { - if (!strcmp(tupel->option, "forward")) - retval |= (net_add_cli(tupel->parameter) != -1); + tx_buf = malloc(BUFSIZE); + if (tx_buf == NULL) { + log_print(LOG_ERROR, "net_init_cli(): out of memory"); + return -1; } - if (retval) { - tx_buf = malloc(BUFSIZE); - if (tx_buf == NULL) { - log_print(LOG_ERROR, "net_init_cli(): out of memory"); - return 0; - } + struct conf_section *section; + section = config_get_section("global"); + if (section == NULL) + return -1; + + int retval = -1; + struct conf_tupel *tupel; + list_for_each_entry(tupel, §ion->tupel, list) { + if (!strcmp(tupel->option, "forward")) + if (net_add_cli(tupel->parameter) != -1) + retval = 0; } return retval; @@ -171,10 +170,10 @@ int net_init_srv() rx_buf = malloc(BUFSIZE); if (rx_buf == NULL) { log_print(LOG_ERROR, "net_init_srv(): out of memory"); - return 0; + close(srv_sock); + return -1; } log_print(LOG_INFO, "listen on %s:%d", inet_ntoa(sa_srv.sin_addr), ntohs(sa_srv.sin_port)); - return srv_sock; } diff --git a/network.h b/network.h index 7e0a40e..9b098cd 100644 --- a/network.h +++ b/network.h @@ -7,6 +7,6 @@ int net_init_srv(); int net_init_cli(); int net_receive(int sock); -void net_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data); +int net_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data); #endif /* _NETWORK_H_ */ diff --git a/plugins.c b/plugins.c index ceff11b..576ee30 100644 --- a/plugins.c +++ b/plugins.c @@ -135,7 +135,7 @@ struct sammler_plugin * plugin_lookup(char *name) return NULL; } -void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ) +int probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ) { static char *hostname = NULL; @@ -149,7 +149,7 @@ void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, cons buffer = malloc(BUFSIZE); if (buffer == NULL) { log_print(LOG_ERROR, "probe_submit: out of memory"); - return; + return -1; } va_start(az, fmt); @@ -159,7 +159,7 @@ void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, cons if (len < 0 || len >= BUFSIZE) { log_print(LOG_ERROR, "probe_submit: %s arguments too long", plugin->name); free(buffer); - return; + return -1; } if (plugin_flags & PLUGIN_RRD) @@ -169,6 +169,7 @@ void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, cons net_submit(hostname, plugin->name, filename, ds_id, buffer); free(buffer); + return 0; } diff --git a/plugins.h b/plugins.h index f340ce2..ead3c77 100644 --- a/plugins.h +++ b/plugins.h @@ -24,7 +24,7 @@ void plugins_probe(void); struct sammler_plugin * plugin_lookup(char *name); -void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ); +int probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ); int strsplit(char *string, char **fields, size_t size); diff --git a/rrdtool.c b/rrdtool.c index 63e8646..c378889 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -226,7 +226,7 @@ static int create_parent_dirs(char *filename) return 0; } -void rrd_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data) +int rrd_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data) { struct stat statbuf; static char *rrd_dir = NULL; @@ -240,14 +240,14 @@ void rrd_submit(char *hostname, char *plugin, char *filename, int ds_id, char *d fullfile = malloc(BUFSIZE); if (fullfile == NULL) { log_print(LOG_ERROR, "rrd_submit: out of memory"); - return; + return -1; } len = snprintf(fullfile, BUFSIZE, "%s/%s/%s", rrd_dir, hostname, filename); if (len < 0 || len >= BUFSIZE) { log_print(LOG_ERROR, "rrd_submit: arguments too long"); free(fullfile); - return; + return -1; } if (stat(fullfile, &statbuf) == -1) { @@ -256,26 +256,27 @@ void rrd_submit(char *hostname, char *plugin, char *filename, int ds_id, char *d if (create_parent_dirs(fullfile) == -1) { free(fullfile); - return; + return -1; } if (rrd_create_file(fullfile, plugin, ds_id) == -1) { free(fullfile); - return; + return -1; } } else { log_print(LOG_ERROR, "rrd_submit: stat(%s):", fullfile); free(fullfile); - return; + return -1; } } else if (!S_ISREG (statbuf.st_mode)) { log_print(LOG_ERROR, "rrd_submit: stat(%s): Not a regular file!", fullfile); free(fullfile); - return; + return -1; } rrd_update_file(fullfile, data); free(fullfile); + return 0; } diff --git a/rrdtool.h b/rrdtool.h index 527394a..77b256b 100644 --- a/rrdtool.h +++ b/rrdtool.h @@ -2,7 +2,7 @@ #define _RRDTOOL_H_ #ifdef WITH_RRD -void rrd_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data); +int rrd_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data); #else #define rrd_submit(hostname, plugin, filename, ds_id, data) #endif diff --git a/sammler.c b/sammler.c index 034f3cf..0a41e35 100644 --- a/sammler.c +++ b/sammler.c @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) FD_SET(srv_sock, &fdsel); int probe_flags = 0; - if (net_init_cli()) + if (net_init_cli() != -1) probe_flags |= PLUGIN_NET; char *fwd_only = config_get_string("global", "forward_only", NULL);