Merge remote-tracking branch 'qubesos/pr/35'
* qubesos/pr/35: make qvm-run work for non-blocking stdin
This commit is contained in:
commit
dc5afa56bf
@ -26,7 +26,7 @@ import sys
|
|||||||
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
import fcntl
|
import select
|
||||||
|
|
||||||
import qubesadmin.tools
|
import qubesadmin.tools
|
||||||
import qubesadmin.exc
|
import qubesadmin.exc
|
||||||
@ -114,11 +114,11 @@ def copy_stdin(stream):
|
|||||||
'''Copy stdin to *stream*'''
|
'''Copy stdin to *stream*'''
|
||||||
# multiprocessing.Process have sys.stdin connected to /dev/null, use fd 0
|
# multiprocessing.Process have sys.stdin connected to /dev/null, use fd 0
|
||||||
# directly
|
# directly
|
||||||
flags = fcntl.fcntl(0, fcntl.F_GETFL)
|
while True:
|
||||||
flags &= ~os.O_NONBLOCK
|
# select so this code works even if fd 0 is non-blocking
|
||||||
fcntl.fcntl(0, fcntl.F_SETFL, flags)
|
select.select([0], [], [])
|
||||||
for data in iter(lambda: os.read(0, 65536), b''):
|
data = os.read(0, 65536)
|
||||||
if data is None:
|
if data is None or data == b'':
|
||||||
break
|
break
|
||||||
stream.write(data)
|
stream.write(data)
|
||||||
stream.flush()
|
stream.flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user