You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2019/03/12 21:05:38 UTC

[trafficcontrol] branch master updated: astats appendSystemState: increase file buffer size to account for possible virtualized network devices

This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c085bb  astats appendSystemState: increase file buffer size to account for possible virtualized network devices
8c085bb is described below

commit 8c085bb8b980736792b6336266529ca1d3c2a40e
Author: Brian Olsen <br...@comcast.com>
AuthorDate: Wed Feb 27 20:58:49 2019 +0000

    astats appendSystemState: increase file buffer size to account for possible virtualized network devices
---
 traffic_server/plugins/astats_over_http/astats_over_http.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/traffic_server/plugins/astats_over_http/astats_over_http.c b/traffic_server/plugins/astats_over_http/astats_over_http.c
index a1c5690..58b8121 100644
--- a/traffic_server/plugins/astats_over_http/astats_over_http.c
+++ b/traffic_server/plugins/astats_over_http/astats_over_http.c
@@ -220,8 +220,9 @@ stats_process_read(TSCont contp, TSEvent event, stats_state *my_state) {
 #define APPEND(a) my_state->output_bytes += stats_add_data_to_resp_buffer(a, my_state)
 #define APPEND_STAT(a, fmt, v) do { \
 		char b[3048]; \
-		if (snprintf(b, sizeof(b), "   \"%s\": " fmt ",\n", a, v) < sizeof(b)) \
-		APPEND(b); \
+		int nbytes = snprintf(b, sizeof(b), "   \"%s\": " fmt ",\n", a, v); \
+		if (0 < nbytes && nbytes < (int)sizeof(b)) \
+			APPEND(b); \
 } while(0)
 
 static void
@@ -298,19 +299,18 @@ static int getSpeed(char *inf, char *buffer, int bufferSize) {
 
 static void appendSystemState(stats_state *my_state) {
 	char *interface = my_state->interfaceName;
-	char buffer[2024];
-	int bsize = 2024;
+	char buffer[16384];
 	char *str;
 	char *end;
 	int speed = 0;
 
 	APPEND_STAT("inf.name", "\"%s\"", interface);
 
-	speed = getSpeed(interface, buffer, bsize);
+	speed = getSpeed(interface, buffer, sizeof(buffer));
 
 	APPEND_STAT("inf.speed", "%d", speed);
 
-	str = getFile("/proc/net/dev", buffer, bsize);
+	str = getFile("/proc/net/dev", buffer, sizeof(buffer));
 	if (str && interface) {
 		str = strstr(str, interface);
 		if (str) {
@@ -321,7 +321,7 @@ static void appendSystemState(stats_state *my_state) {
 		}
 	}
 
-	str = getFile("/proc/loadavg", buffer, bsize);
+	str = getFile("/proc/loadavg", buffer, sizeof(buffer));
 	if (str) {
 		end = strstr(str, "\n");
 		if (end)