From cb644eb1749f3d484329b31dbae7189e07f7535a Mon Sep 17 00:00:00 2001 From: qubesuser Date: Tue, 7 Nov 2017 17:56:56 +0100 Subject: [PATCH] make qvm-run work for non-blocking stdin The main process sometimes sets fd 1 to O_NONBLOCK, and since in the terminal case fd 0 and 1 are the same fd, this also results in fd 0 being non-blocking, causing qvm-run to crash with EAGAIN. So just make the code work for both blocking and non-blocking stdin. --- qubesadmin/tools/qvm_run.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qubesadmin/tools/qvm_run.py b/qubesadmin/tools/qvm_run.py index 8de455c..270289d 100644 --- a/qubesadmin/tools/qvm_run.py +++ b/qubesadmin/tools/qvm_run.py @@ -26,7 +26,7 @@ import sys import multiprocessing -import fcntl +import select import qubesadmin.tools import qubesadmin.exc @@ -114,11 +114,11 @@ def copy_stdin(stream): '''Copy stdin to *stream*''' # multiprocessing.Process have sys.stdin connected to /dev/null, use fd 0 # directly - flags = fcntl.fcntl(0, fcntl.F_GETFL) - flags &= ~os.O_NONBLOCK - fcntl.fcntl(0, fcntl.F_SETFL, flags) - for data in iter(lambda: os.read(0, 65536), b''): - if data is None: + while True: + # select so this code works even if fd 0 is non-blocking + select.select([0], [], []) + data = os.read(0, 65536) + if data is None or data == b'': break stream.write(data) stream.flush()