From cd7a78e0a4130674b814934a9d77c92d9cbbf9be Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 31 Jan 2007 07:48:49 +0000 Subject: [PATCH] [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. () Backport from trunk rev. 53146. --- Lib/pty.py | 2 ++ Lib/test/test_pty.py | 15 +++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 20 insertions(+) diff --git a/Lib/pty.py b/Lib/pty.py index 889113c3dd..9fd4709427 100644 --- a/Lib/pty.py +++ b/Lib/pty.py @@ -121,6 +121,8 @@ 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 59e51627dd..02290be71b 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 False and 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. diff --git a/Misc/NEWS b/Misc/NEWS index 6036a2daad..ff8a0825cd 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -154,6 +154,9 @@ Extension Modules Library ------- +- Patch #783050: the pty.fork() function now closes the slave fd + correctly. + - Patch #1638243: the compiler package is now able to correctly compile a with statement; previously, executing code containing a with statement compiled by the compiler package crashed the interpreter. -- 2.40.0