misc fixes

This commit is contained in:
Olaf Rempel 2006-10-07 20:48:20 +02:00
parent a44fad8ecc
commit ebf4af7f13
7 changed files with 36 additions and 35 deletions

View File

@ -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, &section->tupel, list) {
if (!strcmp(tupel->option, "forward"))
retval |= (net_add_cli(tupel->parameter) != -1);
}
if (retval) {
tx_buf = malloc(BUFSIZE);
if (tx_buf == NULL) {
log_print(LOG_ERROR, "net_init_cli(): out of memory");
return 0;
return -1;
}
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, &section->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;
}

View File

@ -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_ */

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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);