From: iap10@labyrinth.cl.cam.ac.uk Date: Mon, 14 Jun 2004 15:40:23 +0000 (+0000) Subject: bitkeeper revision 1.963 (40cdc6e7KtOV36mP1pWf4c8GN636Pw) X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~18158 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d23f77a5a5bc12d3bb8770a857efe25e175028a8;p=xen.git bitkeeper revision 1.963 (40cdc6e7KtOV36mP1pWf4c8GN636Pw) readline re-fix --- diff --git a/tools/xenctl/lib/ip.py b/tools/xenctl/lib/ip.py index bf5a6a2dff..301e3654b2 100644 --- a/tools/xenctl/lib/ip.py +++ b/tools/xenctl/lib/ip.py @@ -5,12 +5,42 @@ import struct ##### Networking-related functions +def readlines(fd): + """Version of readlines safe against EINTR. + """ + import errno + + lines = [] + while 1: + try: + line = fd.readline() + except IOError, ex: + if ex.errno == errno.EINTR: + continue + else: + raise + if line == '': break + lines.append(line) + return lines + +def readline(fd): + """Version of readline safe against EINTR. + """ + while 1: + try: + return fd.readline() + except IOError, ex: + if ex.errno == errno.EINTR: + continue + else: + raise + def get_current_ipaddr(dev='eth0'): """Return a string containing the primary IP address for the given network interface (default 'eth0'). """ fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) - lines = fd.readlines() + lines = readlines(fd) for line in lines: m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', line ) @@ -23,7 +53,7 @@ def get_current_ipmask(dev='eth0'): network interface (default 'eth0'). """ fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) - lines = fd.readlines() + lines = readlines(fd) for line in lines: m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', line ) @@ -36,7 +66,7 @@ def get_current_ipgw(dev='eth0'): network interface (default 'eth0'). """ fd = os.popen( '/sbin/route -n' ) - lines = fd.readlines() + lines = readlines(fd) for line in lines: m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' + '\s+\S+\s+\S*G.*' + dev + '.*', line )