mercurial/utils/procutil.py
changeset 46174 a1601ff3877c
parent 46102 7ce24d3761e8
child 46175 a04c03b0678e
--- a/mercurial/utils/procutil.py	Fri Dec 18 20:14:54 2020 +0900
+++ b/mercurial/utils/procutil.py	Sat Dec 19 11:10:18 2020 +0900
@@ -50,6 +50,16 @@
         return False
 
 
+class BadFile(io.RawIOBase):
+    """Dummy file object to simulate closed stdio behavior"""
+
+    def readinto(self, b):
+        raise IOError(errno.EBADF, 'Bad file descriptor')
+
+    def write(self, b):
+        raise IOError(errno.EBADF, 'Bad file descriptor')
+
+
 class LineBufferedWrapper(object):
     def __init__(self, orig):
         self.orig = orig
@@ -129,8 +139,7 @@
     if sys.stdin:
         stdin = sys.stdin.buffer
     else:
-        stdin = open(os.devnull, 'rb')
-        os.close(stdin.fileno())
+        stdin = BadFile()
     stdout = _make_write_all(sys.stdout.buffer)
     stderr = _make_write_all(sys.stderr.buffer)
     if pycompat.iswindows: