Skip to content

3.12.2: termios: fetching window size may not work until you set it.Β #115189

@Bill-Sommerfeld

Description

@Bill-Sommerfeld

Bug report

Bug description:

While working on packaging Python 3.12 for OpenIndiana I noticed failures in Lib/test/test_termios.py, which boil down to a comical "you go first" / "no, I insist, you go first" standoff between Modules/termios.c and the illumos kernel's pty code.

illumos will not return success from TIOCGWINSZ unless a prior TIOCSWINSZ has set at least one of the four dimensions to a non-zero value, while a freshly created pty has all four set to zero. See https://github.com/illumos/illumos-gate/blame/0c4d3ec56b3e8f2f8bcc4dbe1eb32871e2663b39/usr/src/uts/common/io/ptem.c#L936-L943

Meanwhile, Python refuses to call TIOCSWINSZ to set the window size unless a prior call to TIOCGWINSZ succeeds, lest it clobber the rarely-used ws_xpixel and ws_ypixel fields.

As a result, all of the termios window size tests fail even though the interface is fully functional on a pty that someone else initialized with a window size.

In my draft patch for this at Bill-Sommerfeld/oi-userland@fd47054
I have Python break the impasse - if TIOCGWINSZ fails in termios_tcgetwinsize_impl, just zero out our struct winsize w and drive on to try to set the size with the caller-provided rows and columns values.

The patch also fixes the test to set a non-zero window size on the pty allocated by the test if termios.tcgetwinsize fails in the setup code.

I'll be happy to convert this patch to a pull request on some branch of the python repo if that would be appropriate.

CPython versions tested on:

3.12

Operating systems tested on:

Other

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirpendingThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions