Skip to content

Commit f69f7fd

Browse files
gh-154345: Fix test_posix_pty_functions() killing the worker on Solaris (GH-154346)
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. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent dc72be1 commit f69f7fd

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/test/test_os/test_os.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,12 +4728,27 @@ def test_posix_pty_functions(self):
47284728
son_fd = os.open(son_path, os.O_RDWR|os.O_NOCTTY)
47294729
self.addCleanup(os.close, son_fd)
47304730
if sys.platform.startswith('sunos'):
4731-
# The slave is not a terminal until these STREAMS modules
4732-
# are pushed onto it.
47334731
import fcntl
47344732
I_PUSH = 0x5302
4733+
TIOCNOTTY = 0x7471
4734+
# Pushing "ptem" makes the slave a terminal, which a session
4735+
# leader without a controlling terminal then acquires as one
4736+
# despite O_NOCTTY. Note whether we already had one.
4737+
try:
4738+
os.close(os.open('/dev/tty', os.O_RDONLY|os.O_NOCTTY))
4739+
had_ctty = True
4740+
except OSError:
4741+
had_ctty = False
47354742
fcntl.ioctl(son_fd, I_PUSH, b'ptem\0')
47364743
fcntl.ioctl(son_fd, I_PUSH, b'ldterm\0')
4744+
if not had_ctty and os.getsid(0) == os.getpid():
4745+
# Disown it, otherwise closing the file descriptors sends
4746+
# SIGHUP to the session. TIOCNOTTY sends it too.
4747+
old_handler = signal.signal(signal.SIGHUP, signal.SIG_IGN)
4748+
try:
4749+
fcntl.ioctl(son_fd, TIOCNOTTY)
4750+
finally:
4751+
signal.signal(signal.SIGHUP, old_handler)
47374752
self.assertEqual(os.ptsname(mother_fd), os.ttyname(son_fd))
47384753

47394754
@warnings_helper.ignore_fork_in_thread_deprecation_warnings()

0 commit comments

Comments
 (0)