summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxebd <xeb@mail.ru>2021-12-20 12:24:49 +0300
committerGitHub <noreply@github.com>2021-12-20 12:24:49 +0300
commitc6f264ad09305f646a15bfea2985c277a8d3bbe2 (patch)
treeb33900a3d6e6b28e6c1f88b36f6a9769ee7112ae
parent385c4038c451f5c181136070846cab0664dae43a (diff)
parentb8ab27c2254e1668a175a3ae9ad038e5db7d6851 (diff)
downloadaccel-ppp-c6f264ad09305f646a15bfea2985c277a8d3bbe2.tar.gz
accel-ppp-c6f264ad09305f646a15bfea2985c277a8d3bbe2.zip
Merge pull request #30 from DmitriyEshenko/m-17122021
T54: Use get_stats function to prevent garbage in counters
-rw-r--r--accel-pppd/cli/show_sessions.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index 73c6a41c..fb3ff527 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -565,10 +565,19 @@ static void format_bytes(char *buf, unsigned long long bytes)
sprintf(buf, "%.1f %s", d, suffix);
}
+static void get_stats(struct ap_session *ses) {
+ if(ap_session_read_stats(ses, &stats) == -1) {
+ stats.rx_bytes = 0;
+ stats.tx_bytes = 0;
+ stats.rx_packets = 0;
+ stats.tx_packets = 0;
+ }
+}
+
static void print_rx_bytes(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
format_bytes(buf, 4294967296ll*ses->acct_input_gigawords + stats.rx_bytes);
@@ -577,7 +586,7 @@ static void print_rx_bytes(struct ap_session *ses, char *buf)
static void print_tx_bytes(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
format_bytes(buf, 4294967296ll*ses->acct_output_gigawords + stats.tx_bytes);
@@ -586,7 +595,7 @@ static void print_tx_bytes(struct ap_session *ses, char *buf)
static void print_rx_bytes_raw(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%llu", 4294967296ll*ses->acct_input_gigawords + stats.rx_bytes);
@@ -595,7 +604,7 @@ static void print_rx_bytes_raw(struct ap_session *ses, char *buf)
static void print_tx_bytes_raw(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%llu", 4294967296ll*ses->acct_output_gigawords + stats.tx_bytes);
@@ -604,7 +613,7 @@ static void print_tx_bytes_raw(struct ap_session *ses, char *buf)
static void print_rx_pkts(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%u", stats.rx_packets);
@@ -613,7 +622,7 @@ static void print_rx_pkts(struct ap_session *ses, char *buf)
static void print_tx_pkts(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%u", stats.tx_packets);