Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal settings are not correctly restored on repl exit #128330

Open
citrus-it opened this issue Dec 29, 2024 · 0 comments
Open

Terminal settings are not correctly restored on repl exit #128330

citrus-it opened this issue Dec 29, 2024 · 0 comments
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@citrus-it
Copy link

citrus-it commented Dec 29, 2024

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

@citrus-it citrus-it added the type-bug An unexpected behavior, bug, or error label Dec 29, 2024
citrus-it added a commit to omniosorg/cpython that referenced this issue Dec 29, 2024
@picnixz picnixz added stdlib Python modules in the Lib dir topic-repl Related to the interactive shell labels Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants