Index: branches/releng-9.0/nanobsd/files/usr/local/bin/pen_wrapper
===================================================================
--- branches/releng-9.0/nanobsd/files/usr/local/bin/pen_wrapper	(revision 10931)
+++ branches/releng-9.0/nanobsd/files/usr/local/bin/pen_wrapper	(revision 10950)
@@ -23,5 +23,5 @@
 }
 
-update_proxy_list() {
+get_proxy_list() {
   # Get (updated) proxy listing from configuration files.
   . /etc/rc.subr
@@ -34,18 +34,20 @@
 test_proxy() {
   PROXY=$1
-  retstr=`HTTP_PROXY=http://$PROXY fetch -T 3 -o /dev/null ${TEST_URL} 2>&1` || return 0
-  BPS=`echo "${retstr}" | awk '/Bps/ {printf $4}'`
-  return $BPS
+  retstr=`HTTP_PROXY=http://$PROXY fetch -T 3 -o /dev/null ${TEST_URL} 2>&1`
+  bps=`echo "${retstr}" | awk '/Bps/ {printf $4}'`
+  echo ${bps:-"0"}
 }
 
 # Sort proxy list on highest bandwidth
-sort_proxies() {
+test_proxies() {
   result=''
   for host in $*; do
     bps=`test_proxy $host:3128`
-    result="$bps $host:3128"
+    if [ "$bps" != "0" ]; then
+      result="$result $bps:$host:3128"
+    fi
   done
 
-  echo $result | xargs -n2 | sort -r | awk '{print $2}' | xargs
+  echo $result | xargs -n1 | sort -t':' -k1 -n -r | cut -d: -f 2,3 | xargs
 }
 
@@ -55,9 +57,9 @@
 LIVE_PROXY_LIST=''
 while true; do
-  PROXY_LIST=`update_proxy_list`
+  PROXY_LIST=`get_proxy_list`
   if [ -z "$PROXY_LIST" ]; then
     logit "Not starting: list_normal_proxies variable not configured"
   else
-    NEW_PROXY_LIST=`sort_proxies $PROXY_LIST`
+    NEW_PROXY_LIST=`test_proxies $PROXY_LIST`
     if [ "${LIVE_PROXY_LIST}" != "${NEW_PROXY_LIST}" ]; then
       logit "INFO: New listing to be configured '${NEW_PROXY_LIST}'"
