Package: nload Version: 0.6.0-2 Tags: patch Followup-For: Bug #300267
The attached patch should fix this bug. It makes nload use 64-bit counters for total traffic, even on 32-bit hosts. Per-interval measurememnts will probably still wrap at 2^32 but that's harmless, and a much more invasive fix. Tested on i386 userland/amd64 kernel. Paul -- System Information: Debian Release: testing/unstable APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.13.2-w64 Locale: LANG=en_GB, LC_CTYPE=en_GB (charmap=ISO-8859-1) Versions of packages nload depends on: ii libc6 2.3.5-6 GNU C Library: Shared libraries an ii libgcc1 1:4.0.1-8 GCC support library ii libncurses5 5.4-9 Shared libraries for terminal hand ii libstdc++5 1:3.3.6-10 The GNU Standard C++ Library v3 nload recommends no packages. -- no debconf information
diff -ur nload-0.6.0/src/proc.cpp nload-fixed/src/proc.cpp --- nload-0.6.0/src/proc.cpp 2005-09-22 23:30:00.000000000 +0100 +++ nload-fixed/src/proc.cpp 2005-09-22 23:08:09.000000000 +0100 @@ -126,7 +126,7 @@ void Proc::readLoad( unsigned long& in, unsigned long& out ) { - unsigned long total_new[2] = { 0, 0 }; + long long total_new[2] = { 0, 0 }; int curr_time = 0; struct timeval time; @@ -181,7 +181,7 @@ if( ! strcmp( m_dev, dev ) ) { - sscanf( tmp, "%lu %*u %*u %*u %*u %*u %*u %*u %lu", &total_new[0], &total_new[1] ); + sscanf( tmp, "%llu %*u %*u %*u %*u %*u %*u %*u %llu", &total_new[0], &total_new[1] ); if( total_new[0] > m_total[0] ) in = total_new[0] - m_total[0]; @@ -513,12 +513,12 @@ return m_elapsed_time; } -unsigned long Proc::totalIn() +long long Proc::totalIn() { return m_total[0]; } -unsigned long Proc::totalOut() +long long Proc::totalOut() { return m_total[1]; } diff -ur nload-0.6.0/src/proc.h nload-fixed/src/proc.h --- nload-0.6.0/src/proc.h 2003-12-04 17:31:34.000000000 +0000 +++ nload-fixed/src/proc.h 2005-09-22 23:08:23.000000000 +0100 @@ -36,8 +36,8 @@ void readLoad( unsigned long& in, unsigned long& out ); - unsigned long totalIn(); - unsigned long totalOut(); + long long totalIn(); + long long totalOut(); int getElapsedTime(); @@ -51,7 +51,7 @@ char m_ip[16]; - unsigned long m_total[2]; + long long m_total[2]; }; diff -ur nload-0.6.0/src/status.cpp nload-fixed/src/status.cpp --- nload-0.6.0/src/status.cpp 2003-12-04 21:48:41.000000000 +0000 +++ nload-fixed/src/status.cpp 2005-09-22 23:09:03.000000000 +0100 @@ -30,7 +30,7 @@ } //new traffic measurement has been made => update statistics -void Status::update( unsigned long new_value, unsigned long new_total ) +void Status::update( unsigned long new_value, long long new_total ) { m_cur = new_value; @@ -44,7 +44,9 @@ *the /proc/net/dev file *(the total bytes value reaches 4GB and then switches to 0) */ - if( new_total < ( m_total % UINT_MAX ) ) + if (new_total >= UINT_MAX ) + m_total = new_total; + else if( new_total < ( m_total % UINT_MAX ) ) m_total = ( ( m_total / UINT_MAX ) + 1 ) * UINT_MAX + new_total; else m_total = ( m_total / UINT_MAX ) * UINT_MAX + new_total; diff -ur nload-0.6.0/src/status.h nload-fixed/src/status.h --- nload-0.6.0/src/status.h 2003-12-03 19:30:44.000000000 +0000 +++ nload-fixed/src/status.h 2005-09-22 23:09:12.000000000 +0100 @@ -52,7 +52,7 @@ gigabyte = 7 }; - void update( unsigned long, unsigned long ); + void update( unsigned long, long long); void print( Window&, int, int, status_format traff_format, status_format data_format ); void resetTrafficData();