autobuild: use close_fds=True to avoid *.stderr and *.stdout inheriting into every...
authorAndrew Bartlett <abartlet@samba.org>
Mon, 27 Aug 2018 09:00:58 +0000 (21:00 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 29 Aug 2018 03:28:17 +0000 (05:28 +0200)
commit47c14ef64e0037ad3e5ac9d8ddf9801501dcdcab
treedeb5feb07a47997969f9cf8e8da104a9068aae76
parentacb8cf1eaf7232a994aafc83fc12d723b71d981b
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 <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
script/autobuild.py