mitogen/parent: Bail out if STDIN or STDOUT is closed

Bail out if STDIN or STDOUT is closed or unavailable, as these streams are
required for the communication with the parent process. Without this check, the
later `os.pipe()` calls in the first_stage may return file descriptors 0 and 1,
leading to a confusing and hard-to-diagnose situation.

-SSH command size: 838
+SSH command size: 850

-mitogen.parent        99240  96.9KiB  51244 50.0KiB 51.6%  12956 12.7KiB 13.1%
+mitogen.parent        99496  97.2KiB  51275 50.1KiB 51.5%  12964 12.7KiB 13.0%

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
pull/1395/head
Marc Hartmayer 1 month ago
parent e0cc3e8cbd
commit b68dfbe602

@ -1420,6 +1420,11 @@ class Connection(object):
# "[1234 refs]" during exit.
@staticmethod
def _first_stage():
# Bail out in case STDIN or STDOUT is not accessible (e.g. closed).
# Otherwise, os.pipe() could reuse file descriptors 0 or 1, leading to
# unexpected behavior that is difficult to diagnose.
os.fstat(0)
os.fstat(1)
R,W=os.pipe()
r,w=os.pipe()
if os.fork():

Loading…
Cancel
Save