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

gh-85984: Add _POSIX_VDISABLE from unistd.h to termios module. #114985

Merged
merged 5 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``_POSIX_VDISABLE`` from C's ``<unistd.h>`` to :mod:`termios`.
7 changes: 4 additions & 3 deletions Modules/termios.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@

#include <termios.h>
#include <sys/ioctl.h>
#if defined(__sun) && defined(__SVR4)
# include <unistd.h> // ioctl()
#endif
#include <unistd.h> // _POSIX_VDISABLE

/* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
* MDTR, MRI, and MRTS (apparently used internally by some things
Expand Down Expand Up @@ -1315,6 +1313,9 @@ static struct constant {
#ifdef TIOCTTYGSTRUCT
{"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
#endif
#ifdef _POSIX_VDISABLE
{"_POSIX_VDISABLE", _POSIX_VDISABLE},
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following script uses termios._POSIX_VDISABLE to disable INTR. Then it calls stty(1) to check if INTR has successfully been disabled.

#!/usr/bin/python3

# Written and tested on Debian GNU/Linux 12 (bookworm) using stty (GNU coreutils) 9.1.

import subprocess
import termios

def stty_intr_value():
    out = subprocess.run(['stty', '-a'], stdout=subprocess.PIPE, text=True).stdout
    s = out.replace(";", " ")
    sub = "intr = "
    i = s.find(sub) + len(sub)
    return s[i:].split()[0]

t = termios.tcgetattr(0)
t[6][termios.VINTR] = bytes([termios._POSIX_VDISABLE])
termios.tcsetattr(0, termios.TCSANOW, t)

assert stty_intr_value() == "<undef>"
print("PASSED")

Hit Control-C after running running above script to see SIGINT not being sent.

Please run stty intr ^c to restore Control-C functionality.

/* sentinel */
{NULL, 0}
Expand Down
Loading