From ab37251175c785a30a7bab5db4bbf3bee3018351 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Wed, 18 Jan 2012 17:46:26 -0600 Subject: [PATCH] * usr/lib/byobu/ec2_cost, usr/lib/byobu/network: - fix input-field-separator problems with /proc/net/dev parsing --- debian/changelog | 3 ++- usr/lib/byobu/ec2_cost | 16 +++++++++++++--- usr/lib/byobu/network | 18 +++++++++++------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/debian/changelog b/debian/changelog index f1e0a352..96ca7edc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ byobu (5.5) unreleased; urgency=low - * UNRELEASED + * usr/lib/byobu/ec2_cost, usr/lib/byobu/network: + - fix input-field-separator problems with /proc/net/dev parsing -- Dustin Kirkland Tue, 17 Jan 2012 12:56:23 -0600 diff --git a/usr/lib/byobu/ec2_cost b/usr/lib/byobu/ec2_cost index 0ea18d1d..4318336b 100755 --- a/usr/lib/byobu/ec2_cost +++ b/usr/lib/byobu/ec2_cost @@ -33,7 +33,6 @@ __ec2_cost_detail() { __ec2_cost() { local zone type file_to_stat cpu mem rate hours tx_gb rx_gb network_cost uptime_cost total_cost interface cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ec2_cost" - OIFS="$IFS" # Try to use metadata service if metadata_available; then [ -s "$cache.zone" ] || wget -q -O "$cache.zone" http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null & @@ -76,15 +75,26 @@ __ec2_cost() { # Auto detect network interface interface=`tail -n1 /proc/net/route | awk '{print $1}'` local iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed - IFS="$OIFS:" while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do + case "$iface" in + ${interface}:) + tx_gb=${tbytes} + rx_gb=${rbytes} + break; + ;; + ${interface}:*) + # Interface and rbytes got munged together + tx_gb=${rmulticast##*:} + rx_gb=${iface##*:} + break; + ;; + esac if [ "$iface" = "${interface}:" ]; then tx_gb=${tbytes} rx_gb=${rbytes} break fi done < /proc/net/dev - IFS="$OIFS" tx_gb=$(echo ${tx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') rx_gb=$(echo ${rx_gb} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'` diff --git a/usr/lib/byobu/network b/usr/lib/byobu/network index 1910d5a4..ebc90fa7 100755 --- a/usr/lib/byobu/network +++ b/usr/lib/byobu/network @@ -32,7 +32,6 @@ __network() { # By default, we won't bug the user with the display of network traffic # below NETWORK_THRESHOLD in kbps; override in $BYOBU_CONFIG_DIR/status [ -n "$NETWORK_THRESHOLD" ] || NETWORK_THRESHOLD=20 - OIFS=$IFS for i in up down; do unit="kb" case $i in @@ -42,14 +41,19 @@ __network() { cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/network.$i" [ -r "$cache" ] && read x1 < "$cache" || tx1=0 local iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed - IFS="$OIFS:" while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do - if [ "$iface" = "${interface}:" ]; then - [ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes} - break; - fi + case "$iface" in + ${interface}:) + [ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes} + break; + ;; + ${interface}:*) + # Interface and tbytes got munged together + [ "$i" = "up" ] && x2=${iface##*:} || x2=${rmulticast##*:} + break; + ;; + esac done < /proc/net/dev - IFS="$OIFS" echo "$x2" > "$cache" rate=$((8*($x2 - $x1) / $t / 1024)) # in kbps [ "$rate" -lt 0 ] && rate=0