diff --git a/network.c b/network.c index ab23d1d..4cff9f4 100644 --- a/network.c +++ b/network.c @@ -24,7 +24,7 @@ static int fwd_sock; static char *tx_buf, *rx_buf; static int tx_pos; -int net_submit(const char *hostname, char *plugin, char *filename, int ds_id, char *data) +int net_submit(const char *hostname, const char *plugin, const char *filename, int ds_id, const char *data) { int size = snprintf(tx_buf + tx_pos, BUFSIZE - tx_pos, "%s:%s:%s:%d %s\n", hostname, plugin, filename, ds_id, data); @@ -39,7 +39,7 @@ int net_submit(const char *hostname, char *plugin, char *filename, int ds_id, ch return 0; } -int net_submit_flush() +int net_submit_flush(void) { if (tx_pos != 0) sendto(fwd_sock, tx_buf, tx_pos, 0, (struct sockaddr *)&fwd_sa, sizeof(fwd_sa)); @@ -76,7 +76,7 @@ int net_receive(int socket) return 0; } -static int net_config_get_saddr(char *section, char *option, struct sockaddr_in *sa) +static int net_config_get_saddr(const char *section, const char *option, struct sockaddr_in *sa) { char *part[2]; @@ -94,7 +94,7 @@ static int net_config_get_saddr(char *section, char *option, struct sockaddr_in return 0; } -int net_init_cli() +int net_init_cli(void) { int ret = net_config_get_saddr("global", "forward", &fwd_sa); if (ret < 0) @@ -118,7 +118,7 @@ int net_init_cli() return 0; } -int net_init_srv() +int net_init_srv(void) { struct sockaddr_in sa_srv; diff --git a/network.h b/network.h index 8ca49fb..45d0a08 100644 --- a/network.h +++ b/network.h @@ -3,11 +3,11 @@ #include "plugins.h" -int net_init_srv(); -int net_init_cli(); +int net_init_srv(void); +int net_init_cli(void); int net_receive(int sock); -int net_submit(const char *hostname, char *plugin, char *filename, int ds_id, char *data); +int net_submit(const char *hostname, const char *plugin, const char *filename, int ds_id, const char *data); int net_submit_flush(); #endif /* _NETWORK_H_ */ diff --git a/p_apache.c b/p_apache.c index 25c0074..078cdfc 100644 --- a/p_apache.c +++ b/p_apache.c @@ -39,7 +39,7 @@ struct server_entry { static LIST_HEAD(server_list); -static char *ds_def = { +static const char *ds_def = { "DS:total_accesses:COUNTER:90:0:U " "DS:total_kbytes:COUNTER:90:0:U " "DS:busy_workers:GAUGE:90:0:U " @@ -58,7 +58,7 @@ struct sammler_plugin plugin; static char *rx_buf; static int rx_pos; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/p_ctstat.c b/p_ctstat.c index 09a14e3..34767eb 100644 --- a/p_ctstat.c +++ b/p_ctstat.c @@ -28,7 +28,7 @@ struct sammler_plugin plugin; -static char *ds_def = { +static const char *ds_def = { "DS:entries:GAUGE:15:0:U " "DS:searched:DERIVE:15:0:U " "DS:found:DERIVE:15:0:U " @@ -47,7 +47,7 @@ static char *ds_def = { "DS:expect_delete:DERIVE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/p_load.c b/p_load.c index baac5ba..1b19ac7 100644 --- a/p_load.c +++ b/p_load.c @@ -25,13 +25,13 @@ struct sammler_plugin plugin; -static char *ds_def = { +static const char *ds_def = { "DS:1min:GAUGE:15:0:U " "DS:5min:GAUGE:15:0:U " "DS:15min:GAUGE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/p_memory.c b/p_memory.c index 767eee5..c0fd9e8 100644 --- a/p_memory.c +++ b/p_memory.c @@ -30,19 +30,19 @@ struct sammler_plugin plugin; -static char *mem_ds_def = { +static const char *mem_ds_def = { "DS:total:GAUGE:15:0:U " "DS:free:GAUGE:15:0:U " "DS:buffers:GAUGE:15:0:U " "DS:cached:GAUGE:15:0:U " }; -static char *swap_ds_def = { +static const char *swap_ds_def = { "DS:total:GAUGE:15:0:U " "DS:free:GAUGE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { switch (ds_id) { case DS_MEMORY: diff --git a/p_mount.c b/p_mount.c index a174cf5..b797e55 100644 --- a/p_mount.c +++ b/p_mount.c @@ -27,12 +27,12 @@ struct sammler_plugin plugin; -static char *ds_def = { +static const char *ds_def = { "DS:block_total:GAUGE:15:0:U " "DS:block_free:GAUGE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/p_mysql.c b/p_mysql.c index df0f7c5..1919cc8 100644 --- a/p_mysql.c +++ b/p_mysql.c @@ -41,12 +41,12 @@ struct server_entry { static LIST_HEAD(server_list); -static char *traffic_ds_def = { +static const char *traffic_ds_def = { "DS:bytes_received:COUNTER:90:0:U " "DS:bytes_sent:COUNTER:90:0:U " }; -static char *commands_ds_def = { +static const char *commands_ds_def = { "DS:com_delete:COUNTER:90:0:U " "DS:com_insert:COUNTER:90:0:U " "DS:com_select:COUNTER:90:0:U " @@ -55,7 +55,7 @@ static char *commands_ds_def = { "DS:questions:COUNTER:90:0:U " }; -static char *qcache_ds_def = { +static const char *qcache_ds_def = { "DS:qc_free_blocks:GAUGE:90:0:U " "DS:qc_free_memory:GAUGE:90:0:U " "DS:qc_hits:COUNTER:90:0:U " @@ -66,14 +66,14 @@ static char *qcache_ds_def = { "DS:qc_total_blocks:GAUGE:90:0:U " }; -static char *threads_ds_def = { +static const char *threads_ds_def = { "DS:threads_cached:GAUGE:90:0:U " "DS:threads_connected:GAUGE:90:0:U " "DS:threads_created:COUNTER:90:0:U " "DS:threads_running:GAUGE:90:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { switch (ds_id) { case DS_TRAFFIC: diff --git a/p_mysql_helper.c b/p_mysql_helper.c index e61f9e8..2c1faee 100644 --- a/p_mysql_helper.c +++ b/p_mysql_helper.c @@ -7,7 +7,7 @@ #include "logging.h" #include "p_mysql_helper.h" -void * init_connection(char *host, char *user, char *pass) +void * init_connection(const char *host, const char *user, const char *pass) { MYSQL *con = NULL; diff --git a/p_mysql_helper.h b/p_mysql_helper.h index 55168cf..248b971 100644 --- a/p_mysql_helper.h +++ b/p_mysql_helper.h @@ -26,7 +26,7 @@ struct mysql_stats { uint64_t threads_running; }; -void * init_connection(char *host, char *user, char *pass); +void * init_connection(const char *host, const char *user, const char *pass); int ping_connection(void *mysql); int close_connection(void *mysql); diff --git a/p_netdev.c b/p_netdev.c index 9a5c92e..b4a221f 100644 --- a/p_netdev.c +++ b/p_netdev.c @@ -28,14 +28,14 @@ struct sammler_plugin plugin; -static char *ds_def = { +static const char *ds_def = { "DS:byte_in:COUNTER:15:0:U " "DS:byte_out:COUNTER:15:0:U " "DS:pkt_in:COUNTER:15:0:U " "DS:pkt_out:COUNTER:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/p_random.c b/p_random.c index 0b37831..2ee1d14 100644 --- a/p_random.c +++ b/p_random.c @@ -25,11 +25,11 @@ struct sammler_plugin plugin; -static char *ds_def = { +static const char *ds_def = { "DS:entropy:GAUGE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/p_rtstat.c b/p_rtstat.c index eb0ad1e..c3a4d7a 100644 --- a/p_rtstat.c +++ b/p_rtstat.c @@ -31,7 +31,7 @@ struct sammler_plugin plugin; -static char *ds_def_stat = { +static const char *ds_def_stat = { "DS:in_hit:DERIVE:15:0:U " "DS:in_slow_tot:DERIVE:15:0:U " "DS:in_slow_mc:DERIVE:15:0:U " @@ -46,7 +46,7 @@ static char *ds_def_stat = { "DS:out_hlist_search:DERIVE:15:0:U " }; -static char *ds_def_gc = { +static const char *ds_def_gc = { "DS:entries:GAUGE:15:0:U " "DS:gc_total:DERIVE:15:0:U " "DS:gc_ignored:DERIVE:15:0:U " @@ -54,7 +54,7 @@ static char *ds_def_gc = { "DS:gc_dst_overflow:DERIVE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { switch (ds_id) { case DS_STAT: diff --git a/p_stat.c b/p_stat.c index 7beae4a..71cad77 100644 --- a/p_stat.c +++ b/p_stat.c @@ -31,7 +31,7 @@ struct sammler_plugin plugin; -static char *cpu_ds_def = { +static const char *cpu_ds_def = { "DS:user:COUNTER:15:0:U " "DS:nice:COUNTER:15:0:U " "DS:system:COUNTER:15:0:U " @@ -42,13 +42,13 @@ static char *cpu_ds_def = { "DS:steal:COUNTER:15:0:U " }; -static char *proc_ds_def = { +static const char *proc_ds_def = { "DS:intr:COUNTER:15:0:U " "DS:ctxt:COUNTER:15:0:U " "DS:fork:COUNTER:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { switch (ds_id) { case DS_CPU: @@ -104,10 +104,10 @@ static int probe(void) else if (numfields == 5) val[5] = val[6] = val[7] = val[8] = "0"; - + else if (numfields == 8) val[8] = "0"; - + probe_submit(&plugin, filename, DS_CPU, "%s:%s:%s:%s:%s:%s:%s:%s", val[1], val[2], val[3], val[4], diff --git a/p_uptime.c b/p_uptime.c index 86a13a7..11344c3 100644 --- a/p_uptime.c +++ b/p_uptime.c @@ -25,12 +25,12 @@ struct sammler_plugin plugin; -static char *ds_def = { +static const char *ds_def = { "DS:uptime:GAUGE:15:0:U " "DS:idletime:GAUGE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/p_vmstat.c b/p_vmstat.c index f9fc46e..33e81d0 100644 --- a/p_vmstat.c +++ b/p_vmstat.c @@ -27,7 +27,7 @@ struct sammler_plugin plugin; -static char *ds_def = { +static const char *ds_def = { "DS:pgalloc_high:DERIVE:15:0:U " "DS:pgalloc_normal:DERIVE:15:0:U " "DS:pgalloc_dma:DERIVE:15:0:U " @@ -35,7 +35,7 @@ static char *ds_def = { "DS:pgfault:DERIVE:15:0:U " }; -static char * get_ds(int ds_id) +static const char * get_ds(int ds_id) { return ds_def; } diff --git a/plugins.c b/plugins.c index 1f98ce3..76ec02d 100644 --- a/plugins.c +++ b/plugins.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "list.h" @@ -51,14 +52,14 @@ static int plugin_init_cb(const char *filename, void *privdata) if (plugin_dir == NULL) plugin_dir = config_get_string("global", "plugin_dir", "."); - buffer = malloc(BUFSIZE); + buffer = malloc(PATH_MAX); if (buffer == NULL) { log_print(LOG_ERROR, "plugin_load: out of memory"); return -1; } - len = snprintf(buffer, BUFSIZE, "%s/%s", plugin_dir, filename); - if (len < 0 || len >= BUFSIZE) { + len = snprintf(buffer, PATH_MAX, "%s/%s", plugin_dir, filename); + if (len < 0 || len >= PATH_MAX) { log_print(LOG_ERROR, "plugin_load: file name too long: %s/%s", plugin_dir, filename); free(buffer); return -1; @@ -117,7 +118,7 @@ void plugins_probe(void) net_submit_flush(); } -struct sammler_plugin * plugin_lookup(char *name) +struct sammler_plugin * plugin_lookup(const char *name) { struct sammler_plugin *plugin; list_for_each_entry(plugin, &plugin_list, list) { @@ -128,7 +129,7 @@ struct sammler_plugin * plugin_lookup(char *name) return NULL; } -int probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ) +int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... ) { static const char *hostname = NULL; diff --git a/plugins.h b/plugins.h index 0193fa7..900e2cd 100644 --- a/plugins.h +++ b/plugins.h @@ -9,21 +9,21 @@ struct sammler_plugin { struct list_head list; - char *name; + const char *name; unsigned int interval; unsigned long lastprobe; int (*init) (void); int (*fini) (void); int (*probe) (void); - char * (*get_ds) (int ds_id); + const char * (*get_ds) (int ds_id); }; void plugin_init(int flags); void plugins_probe(void); -struct sammler_plugin * plugin_lookup(char *name); +struct sammler_plugin * plugin_lookup(const char *name); -int probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ); +int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... ); #endif /* _PLUGINS_H_ */ diff --git a/rrdtool.c b/rrdtool.c index 5e0ca37..bd0d702 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -73,7 +73,7 @@ static int append_rra_config(char *buffer, int size, int *pos) return config_get_strings("global", "rra", append_rra_config_cb, &data); } -static int do_rrd(int mode, char *cmd) +static int do_rrd(int mode, const char *cmd) { int argc; char *argv[ARGCMAX]; @@ -103,11 +103,12 @@ static int do_rrd(int mode, char *cmd) return 0; } -static int rrd_create_file(char *filename, char *plugin_name, int ds_id) +static int rrd_create_file(const char *filename, const char *plugin_name, int ds_id) { struct sammler_plugin *plugin; int pos, step, retval; - char *ds_def, *buffer; + const char *ds_def; + char *buffer; plugin = plugin_lookup(plugin_name); if (plugin == NULL) { @@ -147,7 +148,7 @@ static int rrd_create_file(char *filename, char *plugin_name, int ds_id) return retval; } -static int rrd_update_file(char *filename, char *values) +static int rrd_update_file(const char *filename, const char *values) { int pos, retval; char *buffer; @@ -171,7 +172,7 @@ static int rrd_update_file(char *filename, char *values) return retval; } -static int check_create_dir(char *dir) +static int check_create_dir(const char *dir) { struct stat statbuf; if (stat(dir, &statbuf) == -1) { @@ -228,7 +229,7 @@ static int create_parent_dirs(char *filename) return 0; } -int rrd_submit(const char *hostname, char *plugin, char *filename, int ds_id, char *data) +int rrd_submit(const char *hostname, const char *plugin, const char *filename, int ds_id, const char *data) { struct stat statbuf; static const char *rrd_dir = NULL; diff --git a/rrdtool.h b/rrdtool.h index 6af78e6..ce15c5a 100644 --- a/rrdtool.h +++ b/rrdtool.h @@ -2,7 +2,7 @@ #define _RRDTOOL_H_ #ifdef WITH_RRD -int rrd_submit(const char *hostname, char *plugin, char *filename, int ds_id, char *data); +int rrd_submit(const char *hostname, const char *plugin, const char *filename, int ds_id, const char *data); #else #define rrd_submit(hostname, plugin, filename, ds_id, data) #endif