Skip to content

Commit 5f05d2f

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.14] gh-154345: Fix test_posix_pty_functions() killing the worker on Solaris (GH-154346) (GH-154355)
Pushing the "ptem" STREAMS module makes a session leader without a controlling terminal acquire the slave as one, so closing the file descriptors sent SIGHUP to the session and killed the regrtest worker. Disown it after the pushes, as os.openpty() does. (cherry picked from commit f69f7fd) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9ee705f commit 5f05d2f

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/test/test_os.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4955,12 +4955,27 @@ def test_posix_pty_functions(self):
49554955
son_fd = os.open(son_path, os.O_RDWR|os.O_NOCTTY)
49564956
self.addCleanup(os.close, son_fd)
49574957
if sys.platform.startswith('sunos'):
4958-
# The slave is not a terminal until these STREAMS modules
4959-
# are pushed onto it.
49604958
import fcntl
49614959
I_PUSH = 0x5302
4960+
TIOCNOTTY = 0x7471
4961+
# Pushing "ptem" makes the slave a terminal, which a session
4962+
# leader without a controlling terminal then acquires as one
4963+
# despite O_NOCTTY. Note whether we already had one.
4964+
try:
4965+
os.close(os.open('/dev/tty', os.O_RDONLY|os.O_NOCTTY))
4966+
had_ctty = True
4967+
except OSError:
4968+
had_ctty = False
49624969
fcntl.ioctl(son_fd, I_PUSH, b'ptem\0')
49634970
fcntl.ioctl(son_fd, I_PUSH, b'ldterm\0')
4971+
if not had_ctty and os.getsid(0) == os.getpid():
4972+
# Disown it, otherwise closing the file descriptors sends
4973+
# SIGHUP to the session. TIOCNOTTY sends it too.
4974+
old_handler = signal.signal(signal.SIGHUP, signal.SIG_IGN)
4975+
try:
4976+
fcntl.ioctl(son_fd, TIOCNOTTY)
4977+
finally:
4978+
signal.signal(signal.SIGHUP, old_handler)
49644979
self.assertEqual(os.ptsname(mother_fd), os.ttyname(son_fd))
49654980

49664981
@unittest.skipUnless(hasattr(os, 'spawnl'), "need os.spawnl()")

0 commit comments

Comments
 (0)