Skip to content

Commit

Permalink
Merge remote-tracking branch 'qubesos/pr/35'
Browse files Browse the repository at this point in the history
* qubesos/pr/35:
  make qvm-run work for non-blocking stdin
  • Loading branch information
marmarek committed Nov 7, 2017
2 parents 7f728e2 + cb644eb commit dc5afa5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions qubesadmin/tools/qvm_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import multiprocessing

import fcntl
import select

import qubesadmin.tools
import qubesadmin.exc
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit dc5afa5

Please sign in to comment.