Patchwork [2,of,4,STABLE] procutil: compare fd number to see if stdio protection is needed (issue5992)

mail settings
Submitter Yuya Nishihara
Date Sept. 26, 2018, 1:59 p.m.
Message ID <2a1d09ba204e9e772728.1537970354@mimosa>
Download mbox | patch
Permalink /patch/35053/
State Accepted
Headers show


Yuya Nishihara - Sept. 26, 2018, 1:59 p.m.
# HG changeset patch
# User Yuya Nishihara <>
# Date 1537962839 -32400
#      Wed Sep 26 20:53:59 2018 +0900
# Branch stable
# Node ID 2a1d09ba204e9e7727286fdc0e8d7cfdeb22bb1d
# Parent  96ba53b29353d32ce6e23ba3ccf4a2c72b84e116
procutil: compare fd number to see if stdio protection is needed (issue5992)

When I wrote this function for commandserver at 69f86b937035, testing object
identity was suffice, and I was sloppy enough not to compare fileno() values.
However, it doesn't work in chg session because chgserver reopens stdio to
apply new buffering mode.

This patch partially fixes the issue 5992. Still we have another problem in


diff --git a/mercurial/utils/ b/mercurial/utils/
--- a/mercurial/utils/
+++ b/mercurial/utils/
@@ -273,13 +273,13 @@  def protectstdio(uin, uout):
     fin, fout = uin, uout
-    if uin is stdin:
+    if _testfileno(uin, stdin):
         newfd = os.dup(uin.fileno())
         nullfd =, os.O_RDONLY)
         os.dup2(nullfd, uin.fileno())
         fin = os.fdopen(newfd, r'rb')
-    if uout is stdout:
+    if _testfileno(uout, stdout):
         newfd = os.dup(uout.fileno())
         os.dup2(stderr.fileno(), uout.fileno())
         fout = os.fdopen(newfd, r'wb')
diff --git a/tests/test-ssh.t b/tests/test-ssh.t
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -328,6 +328,10 @@  try again with remote chg, which should 
   pushing to ssh://user@dummy/remote
   searching for changes
   remote has heads on branch 'default' that are not known locally: 6c0482d977a3
+  remote: adding changesets
+  remote: adding manifests
+  remote: adding file changes
+  remote: added 1 changesets with 1 changes to 1 files
   abort: not a Mercurial bundle