ia64/xen-unstable

changeset 1472:38d3dc57c133

bitkeeper revision 1.963 (40cdc6e7KtOV36mP1pWf4c8GN636Pw)

readline re-fix
author iap10@labyrinth.cl.cam.ac.uk
date Mon Jun 14 15:40:23 2004 +0000 (2004-06-14)
parents f6495a180c4d
children cda612df4651
files tools/xenctl/lib/ip.py
line diff
     1.1 --- a/tools/xenctl/lib/ip.py	Mon Jun 14 12:50:39 2004 +0000
     1.2 +++ b/tools/xenctl/lib/ip.py	Mon Jun 14 15:40:23 2004 +0000
     1.3 @@ -5,12 +5,42 @@ import struct
     1.4  
     1.5  ##### Networking-related functions
     1.6  
     1.7 +def readlines(fd):
     1.8 +    """Version of readlines safe against EINTR.
     1.9 +    """
    1.10 +    import errno
    1.11 +    
    1.12 +    lines = []
    1.13 +    while 1:
    1.14 +        try:
    1.15 +            line = fd.readline()
    1.16 +        except IOError, ex:
    1.17 +            if ex.errno == errno.EINTR:
    1.18 +                continue
    1.19 +            else:
    1.20 +                raise
    1.21 +        if line == '': break
    1.22 +        lines.append(line)
    1.23 +    return lines
    1.24 +
    1.25 +def readline(fd):
    1.26 +    """Version of readline safe against EINTR.
    1.27 +    """
    1.28 +    while 1:
    1.29 +        try:
    1.30 +            return fd.readline()
    1.31 +        except IOError, ex:
    1.32 +            if ex.errno == errno.EINTR:
    1.33 +                continue
    1.34 +            else:
    1.35 +                raise
    1.36 +        
    1.37  def get_current_ipaddr(dev='eth0'):
    1.38      """Return a string containing the primary IP address for the given
    1.39      network interface (default 'eth0').
    1.40      """
    1.41      fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    1.42 -    lines = fd.readlines()
    1.43 +    lines = readlines(fd)
    1.44      for line in lines:
    1.45          m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
    1.46                         line )
    1.47 @@ -23,7 +53,7 @@ def get_current_ipmask(dev='eth0'):
    1.48      network interface (default 'eth0').
    1.49      """
    1.50      fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    1.51 -    lines = fd.readlines()
    1.52 +    lines = readlines(fd)
    1.53      for line in lines:
    1.54          m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
    1.55                         line )
    1.56 @@ -36,7 +66,7 @@ def get_current_ipgw(dev='eth0'):
    1.57      network interface (default 'eth0').
    1.58      """
    1.59      fd = os.popen( '/sbin/route -n' )
    1.60 -    lines = fd.readlines()
    1.61 +    lines = readlines(fd)
    1.62      for line in lines:
    1.63          m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' +
    1.64                         '\s+\S+\s+\S*G.*' + dev + '.*', line )