mirror of https://github.com/python/cpython.git
[Patch #783050 from Patrick Lynch] The emulation of forkpty() is incorrect;
the master should close the slave fd. Added a test to test_pty.py that reads from the master_fd after doing a pty.fork(); without the fix it hangs forever instead of raising an exception. (<crossing fingers for the buildbots>) 2.5 backport candidate.
This commit is contained in:
parent
3fa5e6ee45
commit
ee0e6d16b3
|
@ -121,7 +121,9 @@ def fork():
|
||||||
# Explicitly open the tty to make it become a controlling tty.
|
# Explicitly open the tty to make it become a controlling tty.
|
||||||
tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
|
tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
|
||||||
os.close(tmp_fd)
|
os.close(tmp_fd)
|
||||||
|
else:
|
||||||
|
os.close(slave_fd)
|
||||||
|
|
||||||
# Parent and child process.
|
# Parent and child process.
|
||||||
return pid, master_fd
|
return pid, master_fd
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,12 @@ def handle_sig(sig, frame):
|
||||||
os._exit(4)
|
os._exit(4)
|
||||||
else:
|
else:
|
||||||
debug("Waiting for child (%d) to finish."%pid)
|
debug("Waiting for child (%d) to finish."%pid)
|
||||||
|
line = os.read(master_fd, 80)
|
||||||
|
lines = line.replace('\r\n', '\n').split('\n')
|
||||||
|
if lines != ['In child, calling os.setsid()',
|
||||||
|
'Good: OSError was raised.', '']:
|
||||||
|
raise TestFailed("Unexpected output from child: %r" % line)
|
||||||
|
|
||||||
(pid, status) = os.waitpid(pid, 0)
|
(pid, status) = os.waitpid(pid, 0)
|
||||||
res = status >> 8
|
res = status >> 8
|
||||||
debug("Child (%d) exited with status %d (%d)."%(pid, res, status))
|
debug("Child (%d) exited with status %d (%d)."%(pid, res, status))
|
||||||
|
@ -127,6 +133,15 @@ def handle_sig(sig, frame):
|
||||||
elif res != 4:
|
elif res != 4:
|
||||||
raise TestFailed, "pty.fork() failed for unknown reasons."
|
raise TestFailed, "pty.fork() failed for unknown reasons."
|
||||||
|
|
||||||
|
debug("Reading from master_fd now that the child has exited")
|
||||||
|
try:
|
||||||
|
s1 = os.read(master_fd, 1024)
|
||||||
|
except os.error:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise TestFailed("Read from master_fd did not raise exception")
|
||||||
|
|
||||||
|
|
||||||
os.close(master_fd)
|
os.close(master_fd)
|
||||||
|
|
||||||
# pty.fork() passed.
|
# pty.fork() passed.
|
||||||
|
|
Loading…
Reference in New Issue