Mercurial > public > mercurial-scm > hg-stable
diff tests/test-commandserver.t @ 23324:69f86b937035
cmdserver: protect pipe server streams against corruption caused by direct io
Because pipe-mode server uses stdio as IPC channel, other modules should not
touch stdio directly and use ui instead. However, this strategy is brittle
because several Python functions read and write stdio implicitly.
print 'hello' # should use ui.write()
# => ch = 'h', size = 1701604463 'ello', data = '\n'
This patch adds protection for such mistakes. Both stdio files and low-level
file descriptors are redirected to /dev/null while command server uses them.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 15 Nov 2014 13:50:43 +0900 |
parents | 000cfc8b3913 |
children | 42ed0780ec4b |
line wrap: on
line diff
--- a/tests/test-commandserver.t Sat Nov 15 13:04:41 2014 +0900 +++ b/tests/test-commandserver.t Sat Nov 15 13:50:43 2014 +0900 @@ -492,6 +492,7 @@ foo $ cat <<EOF > dbgui.py + > import os, sys > from mercurial import cmdutil, commands > cmdtable = {} > command = cmdutil.command(cmdtable) @@ -501,6 +502,14 @@ > @command("debugprompt", norepo=True) > def debugprompt(ui): > ui.write("%s\\n" % ui.prompt("prompt:")) + > @command("debugreadstdin", norepo=True) + > def debugreadstdin(ui): + > ui.write("read: %r\n" % sys.stdin.read(1)) + > @command("debugwritestdout", norepo=True) + > def debugwritestdout(ui): + > os.write(1, "low-level stdout fd and\n") + > sys.stdout.write("stdout should be redirected to /dev/null\n") + > sys.stdout.flush() > EOF $ cat <<EOF >> .hg/hgrc > [extensions] @@ -518,10 +527,15 @@ ... runcommand(server, ['debugprompt', '--config', ... 'ui.interactive=True'], ... input=cStringIO.StringIO('5678\n')) + ... runcommand(server, ['debugreadstdin']) + ... runcommand(server, ['debugwritestdout']) *** runcommand debuggetpass --config ui.interactive=True password: 1234 *** runcommand debugprompt --config ui.interactive=True prompt: 5678 + *** runcommand debugreadstdin + read: '' + *** runcommand debugwritestdout run commandserver in commandserver, which is silly but should work: