summaryrefslogtreecommitdiffstats
path: root/bin/net_monitor
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.org>2009-02-11 18:43:15 +0000
committerEugeni Dodonov <eugeni@mandriva.org>2009-02-11 18:43:15 +0000
commit5722162b1b524ebbf10f8c3f86eeffa07385d3a6 (patch)
tree6c238d8d015c6797149af9e7ede8811fc8f08526 /bin/net_monitor
parentf529611ff81fb95512b25df6c5c413ce6c9936ef (diff)
downloaddrakx-net-5722162b1b524ebbf10f8c3f86eeffa07385d3a6.tar
drakx-net-5722162b1b524ebbf10f8c3f86eeffa07385d3a6.tar.gz
drakx-net-5722162b1b524ebbf10f8c3f86eeffa07385d3a6.tar.bz2
drakx-net-5722162b1b524ebbf10f8c3f86eeffa07385d3a6.tar.xz
drakx-net-5722162b1b524ebbf10f8c3f86eeffa07385d3a6.zip
Handle /proc/net/dev 32 and 64-bits overflows (#46398).
Diffstat (limited to 'bin/net_monitor')
-rwxr-xr-xbin/net_monitor40
1 files changed, 31 insertions, 9 deletions
diff --git a/bin/net_monitor b/bin/net_monitor
index f41c977..ac16c24 100755
--- a/bin/net_monitor
+++ b/bin/net_monitor
@@ -273,10 +273,30 @@ sub rescan() {
my $transmit = $monitor->{$intf}{val}[8];
my $refr = $monitor->{$intf}{referencer};
my $reft = $monitor->{$intf}{referencet};
- $monitor->{sr} += $recv - $refr;
- $monitor->{st} += $transmit - $reft;
-
- $monitor->{$intf}{recva} += $recv - $refr;
+ my $diffr = $recv - $refr;
+ my $difft = $transmit - $reft;
+
+ # prevent for case 32 bits or 64 bits unsigned value of /proc (if rotate to zero)
+ if ($diffr < 0) {
+ if ($refr < 2**32) { # transition (2^32 - 1) to 0
+ $diffr += 2**32
+ } else { $diffr += 2**64 } # transition (2^64 - 1) to 0
+ # { $diffr = 0; $monitor->{$intf}{totalr} = 0 } # Alternatively, if bug for very big number in perl
+ };
+ # prevent for case 32 bits or 64 bits unsigned value of /proc (if rotate to zero)
+ if ($difft < 0) {
+ if ($reft < 2**32) { # transition (2^32 - 1) to 0
+ $difft += 2**32
+ } else { $difft += 2**64 } # transition (2^64 - 1) to 0
+ # { $difft = 0; $monitor->{$intf}{totalt} = 0 } # Alternatively, if bug for very big number in perl
+ };
+
+ $monitor->{$intf}{totalr} += $diffr;
+ $monitor->{$intf}{totalt} += $difft;
+ $monitor->{sr} += $diffr;
+ $monitor->{st} += $difft;
+
+ $monitor->{$intf}{recva} += $diffr;
$monitor->{$intf}{recvan}++;
if ($monitor->{$intf}{recvan} > 9) {
push(@{$monitor->{$intf}{stack_ra}}, $monitor->{$intf}{recva}/10);
@@ -284,12 +304,12 @@ sub rescan() {
} else { push(@{$monitor->{$intf}{stack_ra}}, -1) }
shift @{$monitor->{$intf}{stack_ra}} if @{$monitor->{$intf}{stack_ra}} > graph_window_width();
- push(@{$monitor->{$intf}{stack_r}}, $recv - $refr);
+ push(@{$monitor->{$intf}{stack_r}}, $diffr);
shift @{$monitor->{$intf}{stack_r}} if @{$monitor->{$intf}{stack_r}} > graph_window_width();
- $monitor->{$intf}{labelr}->set_label(formatXiB($recv - $monitor->{$intf}{initialr}));
+ $monitor->{$intf}{labelr}->set_label(formatXiB($monitor->{$intf}{totalr}));
$monitor->{$intf}{referencer} = $recv;
- $monitor->{$intf}{transmita} += $transmit - $reft;
+ $monitor->{$intf}{transmita} += $difft;
$monitor->{$intf}{transmitan}++;
if ($monitor->{$intf}{transmitan} > 9) {
push(@{$monitor->{$intf}{stack_ta}}, $monitor->{$intf}{transmita}/10);
@@ -297,9 +317,9 @@ sub rescan() {
} else { push(@{$monitor->{$intf}{stack_ta}}, -1) }
shift @{$monitor->{$intf}{stack_ta}} if @{$monitor->{$intf}{stack_ta}} > graph_window_width();
- push(@{$monitor->{$intf}{stack_t}}, $transmit - $reft);
+ push(@{$monitor->{$intf}{stack_t}}, $difft);
shift @{$monitor->{$intf}{stack_t}} if @{$monitor->{$intf}{stack_t}} > graph_window_width();
- $monitor->{$intf}{labelt}->set_label(formatXiB($transmit - $monitor->{$intf}{initialt}));
+ $monitor->{$intf}{labelt}->set_label(formatXiB($monitor->{$intf}{totalt}));
$monitor->{$intf}{referencet} = $transmit;
draw_monitor($monitor->{$intf}, $intf);
@@ -389,6 +409,8 @@ sub update() {
$default_intf ||= $intf;
$monitor->{$intf}{initialr} = $monitor->{$intf}{val}[0];
$monitor->{$intf}{initialt} = $monitor->{$intf}{val}[8];
+ $monitor->{$intf}{totalr} = 0;
+ $monitor->{$intf}{totalt} = 0;
$darea->{$intf} = Gtk2::DrawingArea->new;
$darea->{$intf}->set_events(["pointer_motion_mask"]);
$notebook->append_page(gtkshow(my $page = gtknew('VBox', children => [