Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Add _POSIX_VDISABLE from unistd.h to termios module.
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
  • Loading branch information
8vasu committed Feb 4, 2024
commit 67bd4810aeecbcf362fa5c2e63a59eed9e1365bb
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
Copy Markdown
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