aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>2004-11-04 10:33:25 +0000
committeriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>2004-11-04 10:33:25 +0000
commit64815fdde73031d56d381806074d6d8929aca2ed (patch)
tree6463837fa45f0fbd5e86c5dad21e07456375a634
parentd7688ba92e638451eb0c8125f288ed4455bdc3bc (diff)
downloadxen-64815fdde73031d56d381806074d6d8929aca2ed.tar.gz
xen-64815fdde73031d56d381806074d6d8929aca2ed.tar.bz2
xen-64815fdde73031d56d381806074d6d8929aca2ed.zip
bitkeeper revision 1.1159.1.363 (418a0575yNZLM5woi8ymt4nfB0T_xA)
Cset exclude: mwilli2@equilibrium.research|ChangeSet|20041104003258|47721
-rw-r--r--tools/python/xen/sv/Daemon.py4
-rw-r--r--tools/python/xen/util/ip.py4
-rw-r--r--tools/python/xen/xend/server/SrvDaemon.py4
-rwxr-xr-xtools/python/xen/xend/server/blkif.py2
-rw-r--r--tools/python/xen/xend/util.py41
5 files changed, 22 insertions, 33 deletions
diff --git a/tools/python/xen/sv/Daemon.py b/tools/python/xen/sv/Daemon.py
index 164a0b1656..8aeb58720e 100644
--- a/tools/python/xen/sv/Daemon.py
+++ b/tools/python/xen/sv/Daemon.py
@@ -30,7 +30,7 @@ class Daemon:
cmdex = '(?P<cmd>.*)'
procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
- procs = util.popen('ps -e -o pid,args')
+ procs = util.popen('ps -e -o pid,args 2>/dev/null')
for proc in procs:
pm = procre.match(proc)
if not pm: continue
@@ -58,7 +58,7 @@ class Daemon:
return 0
# Read the pid of the previous invocation and search active process list.
pid = open(PID_FILE, 'r').read()
- lines = util.popen('ps ' + pid).readlines()
+ lines = util.popen('ps ' + pid + ' 2>/dev/null').readlines()
for line in lines:
if re.search('^ *' + pid + '.+xensv', line):
if not kill:
diff --git a/tools/python/xen/util/ip.py b/tools/python/xen/util/ip.py
index 855a517f50..d130f19421 100644
--- a/tools/python/xen/util/ip.py
+++ b/tools/python/xen/util/ip.py
@@ -51,7 +51,7 @@ def get_current_ipaddr(dev='eth0'):
returns interface address as a string
"""
- fd = util.popen( '/sbin/ifconfig ' + dev )
+ fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
lines = _readlines(fd)
for line in lines:
m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
@@ -69,7 +69,7 @@ def get_current_ipmask(dev='eth0'):
returns interface netmask as a string
"""
- fd = util.popen( '/sbin/ifconfig ' + dev )
+ fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
lines = _readlines(fd)
for line in lines:
m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py
index 010249fc83..a95e1124d7 100644
--- a/tools/python/xen/xend/server/SrvDaemon.py
+++ b/tools/python/xen/xend/server/SrvDaemon.py
@@ -337,7 +337,7 @@ class Daemon:
cmdex = '(?P<cmd>.*)'
procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
- procs = util.popen('ps -e -o pid,args')
+ procs = util.popen('ps -e -o pid,args 2>/dev/null')
for proc in procs:
pm = procre.match(proc)
if not pm: continue
@@ -383,7 +383,7 @@ class Daemon:
"""
running = 0
if pid:
- lines = util.popen('ps %d' % pid).readlines()
+ lines = util.popen('ps %d 2>/dev/null' % pid).readlines()
exp = '^ *%d.+%s' % (pid, name)
for line in lines:
if re.search(exp, line):
diff --git a/tools/python/xen/xend/server/blkif.py b/tools/python/xen/xend/server/blkif.py
index c8d7032fce..df32613470 100755
--- a/tools/python/xen/xend/server/blkif.py
+++ b/tools/python/xen/xend/server/blkif.py
@@ -26,7 +26,7 @@ def expand_dev_name(name):
def check_mounted(self, name):
mode = None
name = expand_dev_name(name)
- lines = util.popen('mount').readlines()
+ lines = util.popen('mount 2>/dev/null').readlines()
exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
for line in lines:
pm = exp.match(line)
diff --git a/tools/python/xen/xend/util.py b/tools/python/xen/xend/util.py
index fcce7bc1fa..111d8cd011 100644
--- a/tools/python/xen/xend/util.py
+++ b/tools/python/xen/xend/util.py
@@ -3,12 +3,9 @@
from twisted.internet import utils
from twisted.internet import reactor
-from twisted.internet import protocol
from XendLogging import log
from StringIO import StringIO
-import os
-
# This is rather distasteful. Twisted doesn't play nicely with Python's
# standard os.popen, so here's an implementation of a synchronous popen that
# should work reliably. - MAW
@@ -17,30 +14,22 @@ def popen(cmd):
done_flag = False
result = ''
+
+ def done(output):
+ global done_flag, result
+ done_flag = True
+ result = output
+
+ def err(output):
+ global done_flag
+# For normal use, suppress debug output here. It grumbles about stderr if the
+# program exits with $? != 0, even if stderr is redirected. Grrr!
+# log.debug("util.popen(\'%s\'): %s" % (cmd, output))
+ done_flag = True
+
+ d = utils.getProcessOutput(cmd)
+ d.addCallbacks(done, err)
- class PopenProtocol(protocol.ProcessProtocol):
- def connectionMade(self):
- self.transport.closeStdin() # we don't want stdin
- def outReceived(self, data):
- global result
- result = result + data
-# def errReceived(self, errdata):
-# log.debug("popen: %s" % errdata)
- def processEnded(self,status_obj):
- code = status_obj.value.exitCode
- if code:
- # todo: Should consider throwing an exception here.
- log.debug("popen: process exit with code %d" % code)
- global done_flag
- done_flag = True
-
- # using cmd.split is quick and dirty. OK as long as people don't try anything
- # tricky with quotes, etc.
- args = cmd.split(' ')
- reactor.spawnProcess(PopenProtocol(), args[0], args, os.environ)
-
- # Ick! Sit and ask the reactor to do IO, until the process finishes.
- # Can't just do "pass" here because then the reactor won't run at all :-(
while not done_flag:
reactor.iterate()