Show More
@@ -306,13 +306,19 b' class server(object):' | |||||
306 |
|
306 | |||
307 | return 0 |
|
307 | return 0 | |
308 |
|
308 | |||
309 | def _protectio(ui): |
|
309 | def _protectio(uin, uout): | |
310 |
""" |
|
310 | """Duplicate streams and redirect original to null if (uin, uout) are | |
311 | ui.flush() |
|
311 | stdio | |
|
312 | ||||
|
313 | Returns (fin, fout) which point to the original (uin, uout) fds, but | |||
|
314 | may be copy of (uin, uout). The returned streams can be considered | |||
|
315 | "owned" in that print(), exec(), etc. never reach to them. | |||
|
316 | """ | |||
|
317 | uout.flush() | |||
312 | newfiles = [] |
|
318 | newfiles = [] | |
313 | nullfd = os.open(os.devnull, os.O_RDWR) |
|
319 | nullfd = os.open(os.devnull, os.O_RDWR) | |
314 |
for f, sysf, mode in [(ui |
|
320 | for f, sysf, mode in [(uin, procutil.stdin, r'rb'), | |
315 |
(u |
|
321 | (uout, procutil.stdout, r'wb')]: | |
316 | if f is sysf: |
|
322 | if f is sysf: | |
317 | newfd = os.dup(f.fileno()) |
|
323 | newfd = os.dup(f.fileno()) | |
318 | os.dup2(nullfd, f.fileno()) |
|
324 | os.dup2(nullfd, f.fileno()) | |
@@ -321,10 +327,10 b' def _protectio(ui):' | |||||
321 | os.close(nullfd) |
|
327 | os.close(nullfd) | |
322 | return tuple(newfiles) |
|
328 | return tuple(newfiles) | |
323 |
|
329 | |||
324 | def _restoreio(ui, fin, fout): |
|
330 | def _restoreio(uin, uout, fin, fout): | |
325 |
""" |
|
331 | """Restore (uin, uout) streams from possibly duplicated (fin, fout)""" | |
326 |
u |
|
332 | uout.flush() | |
327 |
for f, uif in [(fin, ui |
|
333 | for f, uif in [(fin, uin), (fout, uout)]: | |
328 | if f is not uif: |
|
334 | if f is not uif: | |
329 | os.dup2(f.fileno(), uif.fileno()) |
|
335 | os.dup2(f.fileno(), uif.fileno()) | |
330 | f.close() |
|
336 | f.close() | |
@@ -341,13 +347,13 b' class pipeservice(object):' | |||||
341 | ui = self.ui |
|
347 | ui = self.ui | |
342 | # redirect stdio to null device so that broken extensions or in-process |
|
348 | # redirect stdio to null device so that broken extensions or in-process | |
343 | # hooks will never cause corruption of channel protocol. |
|
349 | # hooks will never cause corruption of channel protocol. | |
344 | fin, fout = _protectio(ui) |
|
350 | fin, fout = _protectio(ui.fin, ui.fout) | |
345 | try: |
|
351 | try: | |
346 | sv = server(ui, self.repo, fin, fout) |
|
352 | sv = server(ui, self.repo, fin, fout) | |
347 | return sv.serve() |
|
353 | return sv.serve() | |
348 | finally: |
|
354 | finally: | |
349 | sv.cleanup() |
|
355 | sv.cleanup() | |
350 | _restoreio(ui, fin, fout) |
|
356 | _restoreio(ui.fin, ui.fout, fin, fout) | |
351 |
|
357 | |||
352 | def _initworkerprocess(): |
|
358 | def _initworkerprocess(): | |
353 | # use a different process group from the master process, in order to: |
|
359 | # use a different process group from the master process, in order to: |
General Comments 0
You need to be logged in to leave comments.
Login now