misc fixes
This commit is contained in:
parent
a44fad8ecc
commit
ebf4af7f13
41
network.c
41
network.c
@ -27,18 +27,19 @@ struct fwd_entry {
|
|||||||
// todo: never freed..
|
// todo: never freed..
|
||||||
static char *tx_buf, *rx_buf;
|
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);
|
int size = snprintf(tx_buf, BUFSIZE, "%s:%s:%s:%d %s", hostname, plugin, filename, ds_id, data);
|
||||||
if (size < 0 || size >= BUFSIZE) {
|
if (size < 0 || size >= BUFSIZE) {
|
||||||
log_print(LOG_ERROR, "net_submit(): arguments too long");
|
log_print(LOG_ERROR, "net_submit(): arguments too long");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fwd_entry *entry;
|
struct fwd_entry *entry;
|
||||||
list_for_each_entry(entry, &fwd_list, list)
|
list_for_each_entry(entry, &fwd_list, list)
|
||||||
sendto(entry->sock, tx_buf, size +1, 0, (struct sockaddr *)&entry->sa, sizeof(entry->sa));
|
sendto(entry->sock, tx_buf, size +1, 0, (struct sockaddr *)&entry->sa, sizeof(entry->sa));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_receive(int socket)
|
int net_receive(int socket)
|
||||||
@ -124,25 +125,23 @@ static int net_add_cli(char *addr)
|
|||||||
|
|
||||||
int net_init_cli()
|
int net_init_cli()
|
||||||
{
|
{
|
||||||
struct conf_section *section;
|
tx_buf = malloc(BUFSIZE);
|
||||||
struct conf_tupel *tupel;
|
if (tx_buf == NULL) {
|
||||||
|
log_print(LOG_ERROR, "net_init_cli(): out of memory");
|
||||||
section = config_get_section("global");
|
return -1;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval) {
|
struct conf_section *section;
|
||||||
tx_buf = malloc(BUFSIZE);
|
section = config_get_section("global");
|
||||||
if (tx_buf == NULL) {
|
if (section == NULL)
|
||||||
log_print(LOG_ERROR, "net_init_cli(): out of memory");
|
return -1;
|
||||||
return 0;
|
|
||||||
}
|
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;
|
return retval;
|
||||||
@ -171,10 +170,10 @@ int net_init_srv()
|
|||||||
rx_buf = malloc(BUFSIZE);
|
rx_buf = malloc(BUFSIZE);
|
||||||
if (rx_buf == NULL) {
|
if (rx_buf == NULL) {
|
||||||
log_print(LOG_ERROR, "net_init_srv(): out of memory");
|
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));
|
log_print(LOG_INFO, "listen on %s:%d", inet_ntoa(sa_srv.sin_addr), ntohs(sa_srv.sin_port));
|
||||||
|
|
||||||
return srv_sock;
|
return srv_sock;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ int net_init_srv();
|
|||||||
int net_init_cli();
|
int net_init_cli();
|
||||||
int net_receive(int sock);
|
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_ */
|
#endif /* _NETWORK_H_ */
|
||||||
|
@ -135,7 +135,7 @@ struct sammler_plugin * plugin_lookup(char *name)
|
|||||||
return NULL;
|
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;
|
static char *hostname = NULL;
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, cons
|
|||||||
buffer = malloc(BUFSIZE);
|
buffer = malloc(BUFSIZE);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
log_print(LOG_ERROR, "probe_submit: out of memory");
|
log_print(LOG_ERROR, "probe_submit: out of memory");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_start(az, fmt);
|
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) {
|
if (len < 0 || len >= BUFSIZE) {
|
||||||
log_print(LOG_ERROR, "probe_submit: %s arguments too long", plugin->name);
|
log_print(LOG_ERROR, "probe_submit: %s arguments too long", plugin->name);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin_flags & PLUGIN_RRD)
|
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);
|
net_submit(hostname, plugin->name, filename, ds_id, buffer);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ void plugins_probe(void);
|
|||||||
|
|
||||||
struct sammler_plugin * plugin_lookup(char *name);
|
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);
|
int strsplit(char *string, char **fields, size_t size);
|
||||||
|
|
||||||
|
15
rrdtool.c
15
rrdtool.c
@ -226,7 +226,7 @@ static int create_parent_dirs(char *filename)
|
|||||||
return 0;
|
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;
|
struct stat statbuf;
|
||||||
static char *rrd_dir = NULL;
|
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);
|
fullfile = malloc(BUFSIZE);
|
||||||
if (fullfile == NULL) {
|
if (fullfile == NULL) {
|
||||||
log_print(LOG_ERROR, "rrd_submit: out of memory");
|
log_print(LOG_ERROR, "rrd_submit: out of memory");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = snprintf(fullfile, BUFSIZE, "%s/%s/%s", rrd_dir, hostname, filename);
|
len = snprintf(fullfile, BUFSIZE, "%s/%s/%s", rrd_dir, hostname, filename);
|
||||||
if (len < 0 || len >= BUFSIZE) {
|
if (len < 0 || len >= BUFSIZE) {
|
||||||
log_print(LOG_ERROR, "rrd_submit: arguments too long");
|
log_print(LOG_ERROR, "rrd_submit: arguments too long");
|
||||||
free(fullfile);
|
free(fullfile);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(fullfile, &statbuf) == -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) {
|
if (create_parent_dirs(fullfile) == -1) {
|
||||||
free(fullfile);
|
free(fullfile);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rrd_create_file(fullfile, plugin, ds_id) == -1) {
|
if (rrd_create_file(fullfile, plugin, ds_id) == -1) {
|
||||||
free(fullfile);
|
free(fullfile);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log_print(LOG_ERROR, "rrd_submit: stat(%s):", fullfile);
|
log_print(LOG_ERROR, "rrd_submit: stat(%s):", fullfile);
|
||||||
free(fullfile);
|
free(fullfile);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!S_ISREG (statbuf.st_mode)) {
|
} else if (!S_ISREG (statbuf.st_mode)) {
|
||||||
log_print(LOG_ERROR, "rrd_submit: stat(%s): Not a regular file!", fullfile);
|
log_print(LOG_ERROR, "rrd_submit: stat(%s): Not a regular file!", fullfile);
|
||||||
free(fullfile);
|
free(fullfile);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rrd_update_file(fullfile, data);
|
rrd_update_file(fullfile, data);
|
||||||
free(fullfile);
|
free(fullfile);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define _RRDTOOL_H_
|
#define _RRDTOOL_H_
|
||||||
|
|
||||||
#ifdef WITH_RRD
|
#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
|
#else
|
||||||
#define rrd_submit(hostname, plugin, filename, ds_id, data)
|
#define rrd_submit(hostname, plugin, filename, ds_id, data)
|
||||||
#endif
|
#endif
|
||||||
|
@ -104,7 +104,7 @@ int main(int argc, char *argv[])
|
|||||||
FD_SET(srv_sock, &fdsel);
|
FD_SET(srv_sock, &fdsel);
|
||||||
|
|
||||||
int probe_flags = 0;
|
int probe_flags = 0;
|
||||||
if (net_init_cli())
|
if (net_init_cli() != -1)
|
||||||
probe_flags |= PLUGIN_NET;
|
probe_flags |= PLUGIN_NET;
|
||||||
|
|
||||||
char *fwd_only = config_get_string("global", "forward_only", NULL);
|
char *fwd_only = config_get_string("global", "forward_only", NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user