Skip to content

Terminal settings are not correctly restored on repl exit #128330

Closed
@citrus-it

Description

@citrus-it

Bug report

Bug description:

I am working on updating the version of Python that ships in OmniOS -- an illumos distribution -- from 3.12 to 3.13 and have encountered a problem with terminal settings not being properly restored when exiting from the interactive interpreter prompt.

In particular, I see the EOF character changing from 0x4 (^D) to 0x1 (^A) after a trip through repl:

bloody% stty -a | grep eof
eof = ^d; eol = <undef>; eol2 = <undef>; swtch = <undef>;

bloody% python3
Python 3.13.1 (main, Dec 29 2024, 11:58:33) [GCC 14.2.0] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> exit

bloody% stty -a | grep eof
eof = ^a; eol = <undef>; eol2 = <undef>; swtch = <undef>;

Using DTrace (we patch dtrace support back into python locally), I can see that all of the other settings are being restored, just not this particular control character. Here's an excerpt:

Here is the sequence that switches the terminal to raw mode. The trace shows
that c_cc[4] is being changed from 0x4 to 0x1. This is VMIN so as expected.

 15   1364 dtrace function-entry: fancy_termios.py:tcsetattr:54
 15   1364 dtrace function-entry:   fancy_termios.py:as_list:35
 15   1366 dtrace function-return:  fancy_termios.py:as_list:36

 15  78613                 tcgetattr:return struct termios {
    tcflag_t c_iflag = 0x2526
    tcflag_t c_oflag = 0x5
    tcflag_t c_cflag = 0xf01af
    tcflag_t c_lflag = 0x8a3b
    cc_t [19] c_cc = [ 0x3, 0x1c, 0x7f, 0x15, 0x4, 0, 0, 0, 0x11, 0x13, 0x1a, 0x19, 0x12, 0xf, 0x17, 0x16, 0x14, 0x8, 0 ]
}

 15  78611                  tcsetattr:entry struct termios {
    tcflag_t c_iflag = 0x2106
    tcflag_t c_oflag = 0x4
    tcflag_t c_cflag = 0xf00bf
    tcflag_t c_lflag = 0xa31
    cc_t [19] c_cc = [ 0x3, 0x1c, 0x7f, 0x15, 0x1, 0, 0, 0, 0x11, 0x13, 0x1a, 0x19, 0x12, 0xf, 0x17, 0x16, 0x14, 0x8, 0 ]
}

and here is where the terminal is restored:

  0   1366 dtrace function-return:  unix_console.py:flushoutput:489
  0   1364 dtrace function-entry:   fancy_termios.py:tcsetattr:54
  0   1364 dtrace function-entry:     fancy_termios.py:as_list:35
  0   1366 dtrace function-return:    fancy_termios.py:as_list:36

  0  78613                 tcgetattr:return struct termios {
    tcflag_t c_iflag = 0x2106
    tcflag_t c_oflag = 0x4
    tcflag_t c_cflag = 0xf00bf
    tcflag_t c_lflag = 0xa31
    cc_t [19] c_cc = [ 0x3, 0x1c, 0x7f, 0x15, 0x1, 0, 0, 0, 0x11, 0x13, 0x1a, 0x19, 0x12, 0xf, 0x17, 0x16, 0x14, 0x8, 0 ]
}

  0  78611                  tcsetattr:entry struct termios {
    tcflag_t c_iflag = 0x2526
    tcflag_t c_oflag = 0x5
    tcflag_t c_cflag = 0xf01af
    tcflag_t c_lflag = 0x8a3b
    cc_t [19] c_cc = [ 0x3, 0x1c, 0x7f, 0x15, 0x1, 0, 0, 0, 0x11, 0x13, 0x1a, 0x19, 0x12, 0xf, 0x17, 0x16, 0x14, 0x8, 0 ]
}

Everything is being restored apart from that c_cc[4]. On illumos, VMIN and
VEOF are both defined as 4, which is legitimate but different to some other
UNIX-like environments.

The bug here is that the list of control characters is not deep copied in
fancy_termios.py.

CPython versions tested on:

3.13

Operating systems tested on:

Other

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions