From: Andrew Bartlett Date: Mon, 27 Aug 2018 09:00:58 +0000 (+1200) Subject: autobuild: use close_fds=True to avoid *.stderr and *.stdout inheriting into every... X-Git-Tag: tdb-1.3.17~1994 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=47c14ef64e0037ad3e5ac9d8ddf9801501dcdcab;p=thirdparty%2Fsamba.git autobuild: use close_fds=True to avoid *.stderr and *.stdout inheriting into every process This closes fds other than 0, 1, 2. This ensures only the correct *.stderr and *.stdout is attached, via the stdout/stderr parameter to Popen(), but not every other FD currently open in python at the time Popen is called. For the tail invocation and other calls to Popen(), because fds 0, 1, 2 are still attached, these function as before. Per https://docs.python.org/2.6/library/subprocess.html: "If close_fds is true, all file descriptors except 0, 1 and 2 will be closed before the child process is executed. (Unix only)." And regarding the passed in parameters: "stdin, stdout and stderr specify the executed programs’ standard input, standard output and standard error file handles, respectively. " ... "With None (the default), no redirection will occur; the child’s file handles will be inherited from the parent. " (The unwanted inherited files would be on a random high FD, where the program wouldn't know what to do with them, but counting towards the process FD limit). BUG: https://bugzilla.samba.org/show_bug.cgi?id=13591 Signed-off-by: Andrew Bartlett Reviewed-by: Gary Lockyer --- diff --git a/script/autobuild.py b/script/autobuild.py index 9f20b65f692..6ad1941890b 100755 --- a/script/autobuild.py +++ b/script/autobuild.py @@ -407,7 +407,7 @@ def run_cmd(cmd, dir=".", show=None, output=False, checkfail=True): if show: do_print("Running: '%s' in '%s'" % (cmd, dir)) if output: - return Popen([cmd], shell=True, stdout=PIPE, cwd=dir).communicate()[0] + return Popen([cmd], shell=True, stdout=PIPE, cwd=dir, close_fds=True).communicate()[0] elif checkfail: return check_call(cmd, shell=True, cwd=dir) else: @@ -473,6 +473,7 @@ class builder(object): cwd = os.getcwd() os.chdir("%s/%s" % (self.sdir, self.dir)) self.proc = Popen(self.cmd, shell=True, + close_fds=True, stdout=self.stdout, stderr=self.stderr, stdin=self.stdin) os.chdir(cwd) self.next += 1 @@ -615,7 +616,7 @@ class buildlist(object): cwd = os.getcwd() cmd = "tail -f *.stdout *.stderr" os.chdir(gitroot) - self.tail_proc = Popen(cmd, shell=True) + self.tail_proc = Popen(cmd, shell=True, close_fds=True) os.chdir(cwd)