tools/qvm-run: fix handling small data blocks

When data block is smaller than 4096 (and no EOF is reached), python's
io.read() will call read(2) again to get more data. This may deadlock if
the other end of connection will write anything only after receiveing
data (which is the case for qubes.Filecopy).
Disable this buffering by using syscall wrappers directly. To not affect
performance that much, increase buffer size to 64k.

Fixes QubesOS/qubes-issues#2948
This commit is contained in:
Marek Marczykowski-Górecki 2017-08-02 02:43:03 +02:00
parent 1d29929ae1
commit 50bd9f5fab
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -94,11 +94,12 @@ parser.add_argument('cmd', metavar='COMMAND',
def copy_stdin(stream):
'''Copy stdin to *stream*'''
# multiprocessing.Process have sys.stdin connected to /dev/null
stdin = open(0)
for data in iter(lambda: stdin.buffer.read(4096), b''):
os.set_blocking(0, True)
for data in iter(lambda: os.read(0, 65536), b''):
if data is None:
break
stream.write(data)
stream.flush()
stream.close()
def main(args=None, app=None):