comparison mercurial/utils/procutil.py @ 39807:e5724be689b3 stable

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 chgui._runsystem().
author Yuya Nishihara <yuya@tcha.org>
date Wed, 26 Sep 2018 20:53:59 +0900
parents 313a940d49a3
children a9f56e4501c1
comparison
equal deleted inserted replaced
39806:0ad5f064d829 39807:e5724be689b3
271 may be copy of (uin, uout). The returned streams can be considered 271 may be copy of (uin, uout). The returned streams can be considered
272 "owned" in that print(), exec(), etc. never reach to them. 272 "owned" in that print(), exec(), etc. never reach to them.
273 """ 273 """
274 uout.flush() 274 uout.flush()
275 fin, fout = uin, uout 275 fin, fout = uin, uout
276 if uin is stdin: 276 if _testfileno(uin, stdin):
277 newfd = os.dup(uin.fileno()) 277 newfd = os.dup(uin.fileno())
278 nullfd = os.open(os.devnull, os.O_RDONLY) 278 nullfd = os.open(os.devnull, os.O_RDONLY)
279 os.dup2(nullfd, uin.fileno()) 279 os.dup2(nullfd, uin.fileno())
280 os.close(nullfd) 280 os.close(nullfd)
281 fin = os.fdopen(newfd, r'rb') 281 fin = os.fdopen(newfd, r'rb')
282 if uout is stdout: 282 if _testfileno(uout, stdout):
283 newfd = os.dup(uout.fileno()) 283 newfd = os.dup(uout.fileno())
284 os.dup2(stderr.fileno(), uout.fileno()) 284 os.dup2(stderr.fileno(), uout.fileno())
285 fout = os.fdopen(newfd, r'wb') 285 fout = os.fdopen(newfd, r'wb')
286 return fin, fout 286 return fin, fout
287 287