Skip to content

Commit e265465

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.15] gh-154345: Fix test_posix_pty_functions() killing the worker on Solaris (GH-154346) (GH-154354)
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 b8c7ff9 commit e265465

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
@@ -4716,12 +4716,27 @@ def test_posix_pty_functions(self):
47164716
son_fd = os.open(son_path, os.O_RDWR|os.O_NOCTTY)
47174717
self.addCleanup(os.close, son_fd)
47184718
if sys.platform.startswith('sunos'):
4719-
# The slave is not a terminal until these STREAMS modules
4720-
# are pushed onto it.
47214719
import fcntl
47224720
I_PUSH = 0x5302
4721+
TIOCNOTTY = 0x7471
4722+
# Pushing "ptem" makes the slave a terminal, which a session
4723+
# leader without a controlling terminal then acquires as one
4724+
# despite O_NOCTTY. Note whether we already had one.
4725+
try:
4726+
os.close(os.open('/dev/tty', os.O_RDONLY|os.O_NOCTTY))
4727+
had_ctty = True
4728+
except OSError:
4729+
had_ctty = False
47234730
fcntl.ioctl(son_fd, I_PUSH, b'ptem\0')
47244731
fcntl.ioctl(son_fd, I_PUSH, b'ldterm\0')
4732+
if not had_ctty and os.getsid(0) == os.getpid():
4733+
# Disown it, otherwise closing the file descriptors sends
4734+
# SIGHUP to the session. TIOCNOTTY sends it too.
4735+
old_handler = signal.signal(signal.SIGHUP, signal.SIG_IGN)
4736+
try:
4737+
fcntl.ioctl(son_fd, TIOCNOTTY)
4738+
finally:
4739+
signal.signal(signal.SIGHUP, old_handler)
47254740
self.assertEqual(os.ptsname(mother_fd), os.ttyname(son_fd))
47264741

47274742
@warnings_helper.ignore_fork_in_thread_deprecation_warnings()

0 commit comments

Comments
 (0)