ia64/xen-unstable

changeset 2873:f52231be6806

bitkeeper revision 1.1159.1.363 (418a0575yNZLM5woi8ymt4nfB0T_xA)

Cset exclude: mwilli2@equilibrium.research|ChangeSet|20041104003258|47721
author iap10@labyrinth.cl.cam.ac.uk
date Thu Nov 04 10:33:25 2004 +0000 (2004-11-04)
parents 88412d1771bd
children 2364cd863c91
files tools/python/xen/sv/Daemon.py tools/python/xen/util/ip.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/util.py
line diff
     1.1 --- a/tools/python/xen/sv/Daemon.py	Thu Nov 04 08:52:34 2004 +0000
     1.2 +++ b/tools/python/xen/sv/Daemon.py	Thu Nov 04 10:33:25 2004 +0000
     1.3 @@ -30,7 +30,7 @@ class Daemon:
     1.4          cmdex = '(?P<cmd>.*)'
     1.5          procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
     1.6          xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
     1.7 -        procs = util.popen('ps -e -o pid,args')
     1.8 +        procs = util.popen('ps -e -o pid,args 2>/dev/null')
     1.9          for proc in procs:
    1.10              pm = procre.match(proc)
    1.11              if not pm: continue
    1.12 @@ -58,7 +58,7 @@ class Daemon:
    1.13              return 0
    1.14          # Read the pid of the previous invocation and search active process list.
    1.15          pid = open(PID_FILE, 'r').read()
    1.16 -        lines = util.popen('ps ' + pid).readlines()
    1.17 +        lines = util.popen('ps ' + pid + ' 2>/dev/null').readlines()
    1.18          for line in lines:
    1.19              if re.search('^ *' + pid + '.+xensv', line):
    1.20                  if not kill:
     2.1 --- a/tools/python/xen/util/ip.py	Thu Nov 04 08:52:34 2004 +0000
     2.2 +++ b/tools/python/xen/util/ip.py	Thu Nov 04 10:33:25 2004 +0000
     2.3 @@ -51,7 +51,7 @@ def get_current_ipaddr(dev='eth0'):
     2.4  
     2.5      returns interface address as a string
     2.6      """
     2.7 -    fd = util.popen( '/sbin/ifconfig ' + dev )
     2.8 +    fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
     2.9      lines = _readlines(fd)
    2.10      for line in lines:
    2.11          m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
    2.12 @@ -69,7 +69,7 @@ def get_current_ipmask(dev='eth0'):
    2.13  
    2.14      returns interface netmask as a string
    2.15      """
    2.16 -    fd = util.popen( '/sbin/ifconfig ' + dev )
    2.17 +    fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    2.18      lines = _readlines(fd)
    2.19      for line in lines:
    2.20          m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
     3.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Nov 04 08:52:34 2004 +0000
     3.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Thu Nov 04 10:33:25 2004 +0000
     3.3 @@ -337,7 +337,7 @@ class Daemon:
     3.4          cmdex = '(?P<cmd>.*)'
     3.5          procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
     3.6          xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
     3.7 -        procs = util.popen('ps -e -o pid,args')
     3.8 +        procs = util.popen('ps -e -o pid,args 2>/dev/null')
     3.9          for proc in procs:
    3.10              pm = procre.match(proc)
    3.11              if not pm: continue
    3.12 @@ -383,7 +383,7 @@ class Daemon:
    3.13          """
    3.14          running = 0
    3.15          if pid:
    3.16 -            lines = util.popen('ps %d' % pid).readlines()
    3.17 +            lines = util.popen('ps %d 2>/dev/null' % pid).readlines()
    3.18              exp = '^ *%d.+%s' % (pid, name)
    3.19              for line in lines:
    3.20                  if re.search(exp, line):
     4.1 --- a/tools/python/xen/xend/server/blkif.py	Thu Nov 04 08:52:34 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/blkif.py	Thu Nov 04 10:33:25 2004 +0000
     4.3 @@ -26,7 +26,7 @@ def expand_dev_name(name):
     4.4  def check_mounted(self, name):
     4.5      mode = None
     4.6      name = expand_dev_name(name)
     4.7 -    lines = util.popen('mount').readlines()
     4.8 +    lines = util.popen('mount 2>/dev/null').readlines()
     4.9      exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
    4.10      for line in lines:
    4.11          pm = exp.match(line)
     5.1 --- a/tools/python/xen/xend/util.py	Thu Nov 04 08:52:34 2004 +0000
     5.2 +++ b/tools/python/xen/xend/util.py	Thu Nov 04 10:33:25 2004 +0000
     5.3 @@ -3,12 +3,9 @@
     5.4  
     5.5  from twisted.internet import utils
     5.6  from twisted.internet import reactor
     5.7 -from twisted.internet import protocol
     5.8  from XendLogging import log
     5.9  from StringIO import StringIO
    5.10  
    5.11 -import os
    5.12 -
    5.13  # This is rather distasteful.  Twisted doesn't play nicely with Python's
    5.14  # standard os.popen, so here's an implementation of a synchronous popen that
    5.15  # should work reliably. - MAW
    5.16 @@ -17,30 +14,22 @@ def popen(cmd):
    5.17  
    5.18      done_flag = False
    5.19      result = ''
    5.20 +    
    5.21 +    def done(output):
    5.22 +        global done_flag, result
    5.23 +        done_flag = True
    5.24 +        result = output
    5.25  
    5.26 -    class PopenProtocol(protocol.ProcessProtocol):
    5.27 -        def connectionMade(self):
    5.28 -            self.transport.closeStdin() # we don't want stdin
    5.29 -        def outReceived(self, data):
    5.30 -            global result
    5.31 -            result = result + data
    5.32 -#        def errReceived(self, errdata):
    5.33 -#            log.debug("popen: %s" % errdata)
    5.34 -        def processEnded(self,status_obj):
    5.35 -            code = status_obj.value.exitCode
    5.36 -            if code:
    5.37 -                # todo: Should consider throwing an exception here.
    5.38 -                log.debug("popen: process exit with code %d" % code)
    5.39 -            global done_flag
    5.40 -            done_flag = True
    5.41 +    def err(output):
    5.42 +        global done_flag
    5.43 +# For normal use, suppress debug output here.  It grumbles about stderr if the
    5.44 +# program exits with $? != 0, even if stderr is redirected.  Grrr!
    5.45 +#        log.debug("util.popen(\'%s\'): %s" % (cmd, output))
    5.46 +        done_flag = True
    5.47  
    5.48 -    # using cmd.split is quick and dirty.  OK as long as people don't try anything
    5.49 -    # tricky with quotes, etc.
    5.50 -    args = cmd.split(' ')
    5.51 -    reactor.spawnProcess(PopenProtocol(), args[0], args, os.environ)
    5.52 +    d = utils.getProcessOutput(cmd)
    5.53 +    d.addCallbacks(done, err)
    5.54  
    5.55 -    # Ick!  Sit and ask the reactor to do IO, until the process finishes.
    5.56 -    # Can't just do "pass" here because then the reactor won't run at all :-(
    5.57      while not done_flag:
    5.58          reactor.iterate()
    5.59