From: Michael Tremer Date: Tue, 23 Oct 2012 19:01:58 +0000 (+0200) Subject: Fix output of shell commands in makefiles. X-Git-Tag: 0.9.24~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e78c784c145d03d6b90a4659acc3bfa50870d32;p=pakfire.git Fix output of shell commands in makefiles. Error output is now thrown away and the wanted output is not written to the logfiles anymore. --- diff --git a/python/pakfire/chroot.py b/python/pakfire/chroot.py index 9862dc74b..c08bbdb39 100644 --- a/python/pakfire/chroot.py +++ b/python/pakfire/chroot.py @@ -79,7 +79,7 @@ def logOutput(fds, logger, returnOutput=1, start=0, timeout=0): return output -def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True, returnOutput=0, personality=None, logger=None, env=None, cgroup=None, *args, **kargs): +def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True, returnOutput=0, logstderr=1, personality=None, logger=None, env=None, cgroup=None, *args, **kargs): # Save the output of command output = "" @@ -94,6 +94,11 @@ def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True child = None + if logstderr: + stderr = subprocess.PIPE + else: + stderr = open("/dev/null", "w") + try: # Create new child process child = subprocess.Popen( @@ -102,7 +107,7 @@ def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True bufsize=0, close_fds=True, stdin=open("/dev/null", "r"), stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stderr=stderr, preexec_fn = preexec, env=env ) @@ -112,7 +117,11 @@ def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True cgroup.attach_task(child.pid) # use select() to poll for output so we dont block - output = logOutput([child.stdout, child.stderr], logger, returnOutput, start, timeout) + fds = [child.stdout,] + if logstderr: + fds.append(child.stderr) + + output = logOutput(fds, logger, returnOutput, start, timeout) except: # kill children if they aren't done diff --git a/python/pakfire/packages/lexer.py b/python/pakfire/packages/lexer.py index 52eeb1978..38445d833 100644 --- a/python/pakfire/packages/lexer.py +++ b/python/pakfire/packages/lexer.py @@ -238,7 +238,7 @@ class Lexer(object): # Do we need to chroot and change personality? try: - output = pakfire.chroot.do(command, shell=True, returnOutput=1, logger=log) + output = pakfire.chroot.do(command, shell=True, returnOutput=1, logstderr=False) except Error: return