[Piuparts-commits] [SCM] piuparts git repository branch, piatti, updated. 0.42-14-g5c2eadd

Andreas Beckmann debian at abeckmann.de
Mon Jan 9 17:10:53 UTC 2012


The following commit has been merged in the piatti branch:
commit b32b40ac06361b12a7e19946b1c96d27b115fffd
Author: Andreas Beckmann <debian at abeckmann.de>
Date:   Sun Jan 8 18:58:18 2012 +0100

    read output remaining after command terminated
    
    There may be output generated between reading a chunk (or at the
    very beginning) and the time Popen.poll() returns not None for
    the first time - this output was previously missed. So read again
    from the Popen.stdout file after the process has terminated.
    Limit the amount that is read, it is possible that a buggy program
    forks into the background, keeps the stdout/stderr file descriptors
    and produces infinite output but is not killed by Popen.terminate()
    and friends ... (These remaining programs will be terminated by
    the check for running processes.)
    
    Hopefully fixes the spurious missing output from dpkg-divert --list
    and other commands.
    
    Signed-off-by: Andreas Beckmann <debian at abeckmann.de>

diff --git a/piuparts.1.txt b/piuparts.1.txt
index 36f57af..353b424 100644
--- a/piuparts.1.txt
+++ b/piuparts.1.txt
@@ -219,7 +219,8 @@ ENVIRONMENT
 
 NOTES
 -----
-Outputs of commands run by piuparts are limited to the last two megabytes. To change this limit, the source code needs to be edited.
+Output of commands run by piuparts is limited to two megabytes. To change this limit, the source code needs to be edited.
+Commands exceeding this limit will be aborted.
 
 SEE ALSO
 --------
diff --git a/piuparts.py b/piuparts.py
index ba859df..77e58ca 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -388,6 +388,7 @@ def run(command, ignore_errors=False):
     devnull = open('/dev/null', 'r')
     p = subprocess.Popen(command, env=env, stdin=devnull, 
                          stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    max_output = 1 << 21  # 2 MB
     output = ""
     excessive_output = False
     while p.poll() is None:
@@ -395,7 +396,7 @@ def run(command, ignore_errors=False):
         of the command we may get less even if more output is coming later.
         Abort after reading 2 MB."""
         output += p.stdout.read(1 << 16)
-        if (len(output) > (1 << 21)):
+        if (len(output) > max_output):
             excessive_output = True
             logging.error("Terminating command due to excessive output")
             p.terminate()
@@ -408,6 +409,8 @@ def run(command, ignore_errors=False):
                 p.kill()
             p.wait()
             break
+    if not excessive_output:
+        output += p.stdout.read(max_output)
     devnull.close()
 
     if output:

-- 
piuparts git repository



More information about the Piuparts-commits mailing list