-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Conversation
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
In a previous PR in this series (#101832), I mentioned the idea of writing a Python library that mimics This is not a dependency of the main set of changes of this series in #101833, but since this idea was conceived while working on this issue and since this PR is so small, I did not create a separate issue for this. I have added a test script as a comment. |
@@ -1315,6 +1313,9 @@ static struct constant { | |||
#ifdef TIOCTTYGSTRUCT | |||
{"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT}, | |||
#endif | |||
#ifdef _POSIX_VDISABLE | |||
{"_POSIX_VDISABLE", _POSIX_VDISABLE}, | |||
#endif | |||
|
There was a problem hiding this comment.
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.
@gpshead Thank you so much! I will make my stty-like library available soon and send you a link. |
…ython#114985) Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
This follows #102413.
POSIX General Terminal Interface defines Special Control Characters. An example of this is the
INTR
character, which is usually set toControl-C
, which sends theSIGINT
signal to interrupt a process running in the terminal.POSIX General Terminal Interface allows the programmer to disable these characters by setting them to
_POSIX_VDISABLE
, which is defined in POSIX<unistd.h>
. This is how POSIXstty(1)
disables special control characters internally; for example, running the following command will disable theINTR
character:stty intr undef
Now hitting
Control-C
will not sendSIGINT
to the running process until it is reset using the following command:stty intr ^c
.At any given point of time, check all terminal settings by running
stty -a
.This PR adds
_POSIX_VDISABLE
to thetermios
module.