[projects/pld-builder.new] chroot: let popen() callers see the exit code

arekm arekm at pld-linux.org
Mon Oct 26 17:15:50 CET 2026


commit bbc18644c3fa4375b1b6c14cc7b784288a884d68
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sat Oct 24 11:31:07 2026 +0200

    chroot: let popen() callers see the exit code
    
    Nobody waited for the command: its status was lost and it stayed a
    zombie.  close() now waits and returns the exit code.

 PLD_Builder/chroot.py | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
---
diff --git a/PLD_Builder/chroot.py b/PLD_Builder/chroot.py
index 2efa731..7b98c88 100644
--- a/PLD_Builder/chroot.py
+++ b/PLD_Builder/chroot.py
@@ -21,14 +21,34 @@ def command(cmd, user = None, nostdin="", nonet=True):
     return "%s sudo chroot %s su - %s -c \"export LC_ALL=C; %s %s\"" \
             % (config.sudo_chroot_wrapper, config.chroot, user, nostdin, quote(cmd))
 
+class Pipe:
+    """One end of a pipe to a command; close() waits and returns its exit code."""
+
+    def __init__(self, p, f):
+        self.p = p
+        self.f = f
+
+    def __iter__(self):
+        return iter(self.f)
+
+    def write(self, s):
+        return self.f.write(s)
+
+    def close(self):
+        try:
+            self.f.close()
+        except BaseException:
+            # a broken pipe on flush; still reap the command
+            self.p.wait()
+            raise
+        return self.p.wait()
+
 def popen(cmd, user = "builder", mode = "r", encoding = None, nonet=True):
     if mode == "r":
         p = subprocess.Popen(command(cmd, user, nonet=nonet), shell=True, stdout=subprocess.PIPE, close_fds=True, encoding=encoding)
-        f = p.stdout
-    else:
-        p = subprocess.Popen(command(cmd, user, nonet=nonet), shell=True, stdin=subprocess.PIPE, close_fds=True, encoding=encoding)
-        f = p.stdin
-    return f
+        return Pipe(p, p.stdout)
+    p = subprocess.Popen(command(cmd, user, nonet=nonet), shell=True, stdin=subprocess.PIPE, close_fds=True, encoding=encoding)
+    return Pipe(p, p.stdin)
 
 def run(cmd, user = "builder", logfile = None, logstdout = None, nonet=True):
     c = command(cmd, user, nostdin=True, nonet=nonet)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/ce9feb3c796ed049b6dd260a50d94d80feb1656d



More information about the pld-cvs-commit mailing list