summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-12-22 18:41:42 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-12-22 18:41:42 (GMT)
commitee0e6d16b371a66e1d9ab8103fb51117db37cdbc (patch)
tree566bc24fe583c883252b956a9f6fe10b1602e0eb
parent3fa5e6ee4527219a9351413ac6ba425be8ea5dd8 (diff)
downloadcpython-ee0e6d16b371a66e1d9ab8103fb51117db37cdbc.zip
cpython-ee0e6d16b371a66e1d9ab8103fb51117db37cdbc.tar.gz
cpython-ee0e6d16b371a66e1d9ab8103fb51117db37cdbc.tar.bz2
[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.
-rw-r--r--Lib/pty.py4
-rw-r--r--Lib/test/test_pty.py15
2 files changed, 18 insertions, 1 deletions
diff --git a/Lib/pty.py b/Lib/pty.py
index 889113c..d3eb64f 100644
--- a/Lib/pty.py
+++ b/Lib/pty.py
@@ -121,7 +121,9 @@ def fork():
# Explicitly open the tty to make it become a controlling tty.
tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
os.close(tmp_fd)
-
+ else:
+ os.close(slave_fd)
+
# Parent and child process.
return pid, master_fd
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index 59e5162..fd346c0 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -115,6 +115,12 @@ if pid == pty.CHILD:
os._exit(4)
else:
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)
res = status >> 8
debug("Child (%d) exited with status %d (%d)."%(pid, res, status))
@@ -127,6 +133,15 @@ else:
elif res != 4:
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)
# pty.fork() passed.