From 46e716ee8d4208924d10f57f9ed97c99674a6ef4 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 17 Sep 2014 11:31:13 +0200 Subject: [PATCH 20/22] openvpn: Make read functions robust like in 8516f9abb625fa7b9321e62307305aa6499be4e8 --- src/openvpn.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/openvpn.c b/src/openvpn.c index 6a0ffbd..f686721 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -332,7 +332,7 @@ static int multi2_read (char *name, FILE *fh) char buffer[1024]; char *fields[10]; const int max_fields = STATIC_ARRAY_SIZE (fields); - int fields_num, read = 0; + int fields_num; long long sum_users = 0; while (fgets (buffer, sizeof (buffer), fh) != NULL) @@ -379,17 +379,14 @@ static int multi2_read (char *name, FILE *fh) atoll (fields[5])); /* "Bytes Sent" */ } } - - read = 1; } if (collect_user_count) { numusers_submit(name, name, sum_users); - read = 1; } - return (read); + return (1); } /* int multi2_read */ /* for reading status version 3 */ @@ -398,7 +395,7 @@ static int multi3_read (char *name, FILE *fh) char buffer[1024]; char *fields[15]; const int max_fields = STATIC_ARRAY_SIZE (fields); - int fields_num, read = 0; + int fields_num; long long sum_users = 0; while (fgets (buffer, sizeof (buffer), fh) != NULL) @@ -447,18 +444,15 @@ static int multi3_read (char *name, FILE *fh) atoll (fields[5])); /* "Bytes Sent" */ } } - - read = 1; } } if (collect_user_count) { numusers_submit(name, name, sum_users); - read = 1; } - return (read); + return (1); } /* int multi3_read */ /* for reading status version 4 */ @@ -467,7 +461,7 @@ static int multi4_read (char *name, FILE *fh) char buffer[1024]; char *fields[11]; const int max_fields = STATIC_ARRAY_SIZE (fields); - int fields_num, read = 0; + int fields_num; long long sum_users = 0; while (fgets (buffer, sizeof (buffer), fh) != NULL) @@ -515,17 +509,14 @@ static int multi4_read (char *name, FILE *fh) atoll (fields[5])); /* "Bytes Sent" */ } } - - read = 1; } if (collect_user_count) { numusers_submit(name, name, sum_users); - read = 1; } - return (read); + return (1); } /* int multi4_read */ /* read callback */ -- 1.9.3