From 4fd1e7eba5e4f23f0857ecc296f243916da7caf4 Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 21 Dec 2010 16:50:16 +0000 Subject: [PATCH] The buffer length for command buffers should be controlled by a single #define. Renamed CMD_MAX to RRD_CMD_MAX and put into rrd_client.h so that it is available to clients as well. -- kevin brintnall git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@2156 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_client.c | 20 ++++++++++---------- program/src/rrd_client.h | 2 ++ program/src/rrd_daemon.c | 14 ++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/program/src/rrd_client.c b/program/src/rrd_client.c index 870a27b7..29d1d299 100644 --- a/program/src/rrd_client.c +++ b/program/src/rrd_client.c @@ -304,7 +304,7 @@ static int buffer_add_string (const char *str, /* {{{ */ static int buffer_add_value (const char *value, /* {{{ */ char **buffer_ret, size_t *buffer_size_ret) { - char temp[4096]; + char temp[RRD_CMD_MAX]; if (strncmp (value, "N:", 2) == 0) snprintf (temp, sizeof (temp), "%lu:%s", @@ -319,7 +319,7 @@ static int buffer_add_value (const char *value, /* {{{ */ static int buffer_add_ulong (const unsigned long value, /* {{{ */ char **buffer_ret, size_t *buffer_size_ret) { - char temp[4096]; + char temp[RRD_CMD_MAX]; snprintf (temp, sizeof (temp), "%lu", value); temp[sizeof (temp) - 1] = 0; @@ -372,7 +372,7 @@ static int response_read (rrdc_response_t **ret_response) /* {{{ */ rrdc_response_t *ret = NULL; int status = 0; - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t i; @@ -713,7 +713,7 @@ int rrdc_disconnect (void) /* {{{ */ int rrdc_update (const char *filename, int values_num, /* {{{ */ const char * const *values) { - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t buffer_free; size_t buffer_size; @@ -775,7 +775,7 @@ int rrdc_update (const char *filename, int values_num, /* {{{ */ int rrdc_flush (const char *filename) /* {{{ */ { - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t buffer_free; size_t buffer_size; @@ -829,7 +829,7 @@ int rrdc_flush (const char *filename) /* {{{ */ rrd_info_t * rrdc_info (const char *filename) /* {{{ */ { - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t buffer_free; size_t buffer_size; @@ -930,7 +930,7 @@ rrd_info_t * rrdc_info (const char *filename) /* {{{ */ time_t rrdc_last (const char *filename) /* {{{ */ { - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t buffer_free; size_t buffer_size; @@ -991,7 +991,7 @@ time_t rrdc_last (const char *filename) /* {{{ */ time_t rrdc_first (const char *filename, int rraindex) /* {{{ */ { - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t buffer_free; size_t buffer_size; @@ -1064,7 +1064,7 @@ int rrdc_create (const char *filename, /* {{{ */ int argc, const char **argv) { - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t buffer_free; size_t buffer_size; @@ -1149,7 +1149,7 @@ int rrdc_fetch (const char *filename, /* {{{ */ char ***ret_ds_names, rrd_value_t **ret_data) { - char buffer[4096]; + char buffer[RRD_CMD_MAX]; char *buffer_ptr; size_t buffer_free; size_t buffer_size; diff --git a/program/src/rrd_client.h b/program/src/rrd_client.h index e203d7ca..681397dd 100644 --- a/program/src/rrd_client.h +++ b/program/src/rrd_client.h @@ -49,6 +49,8 @@ typedef unsigned long long int uint64_t; #endif +/* max length of socket command or response */ +#define RRD_CMD_MAX 4096 #ifndef RRDCACHED_DEFAULT_ADDRESS # define RRDCACHED_DEFAULT_ADDRESS "unix:/tmp/rrdcached.sock" diff --git a/program/src/rrd_daemon.c b/program/src/rrd_daemon.c index a2001359..79fbc310 100644 --- a/program/src/rrd_daemon.c +++ b/program/src/rrd_daemon.c @@ -219,9 +219,7 @@ typedef struct { size_t files_num; } journal_set; -/* max length of socket command or response */ -#define CMD_MAX 4096 -#define RBUF_SIZE (CMD_MAX*2) +#define RBUF_SIZE (RRD_CMD_MAX*2) /* * Variables @@ -543,7 +541,7 @@ static int add_to_wbuf(listen_socket_t *sock, char *str, size_t len) /* {{{ */ static int add_response_info(listen_socket_t *sock, char *fmt, ...) /* {{{ */ { va_list argp; - char buffer[CMD_MAX]; + char buffer[RRD_CMD_MAX]; int len; if (JOURNAL_REPLAY(sock)) return 0; @@ -588,7 +586,7 @@ static int send_response (listen_socket_t *sock, response_code rc, char *fmt, ...) /* {{{ */ { va_list argp; - char buffer[CMD_MAX]; + char buffer[RRD_CMD_MAX]; int lines; ssize_t wrote; int rclen, len; @@ -1327,7 +1325,7 @@ static int handle_request_update (HANDLER_PROTO) /* {{{ */ char *file, file_tmp[PATH_MAX]; int values_num = 0; int status; - char orig_buf[CMD_MAX]; + char orig_buf[RRD_CMD_MAX]; cache_item_t *ci; @@ -2204,7 +2202,7 @@ static int handle_request_help (HANDLER_PROTO) /* {{{ */ if (help && (help->syntax || help->help)) { - char tmp[CMD_MAX]; + char tmp[RRD_CMD_MAX]; snprintf(tmp, sizeof(tmp)-1, "Help for %s\n", help->cmd); resp_txt = tmp; @@ -2439,7 +2437,7 @@ static int journal_replay (const char *file) /* {{{ */ int entry_cnt = 0; int fail_cnt = 0; uint64_t line = 0; - char entry[CMD_MAX]; + char entry[RRD_CMD_MAX]; time_t now; if (file == NULL) return 0; -- 2.30.2