put the terminal into raw mode

For whatever reason, urwid puts the terminal into cbreak mode during
initialization. If we put the terminal into raw mode instead, then we
don't have to ignore SIGINT and SIGQUIT, which is good, because when we
support dropping to a subshell we don't want to run that subshell with
those signals ignored, because that is extremely confusing.

This also lets me dump the code that puts the terminal into raw mode
during keyboard detection.
This commit is contained in:
Michael Hudson-Doyle 2019-08-15 13:50:23 +12:00
parent 8b2a59bf2e
commit 90d376fbbd
3 changed files with 6 additions and 26 deletions

View File

@ -17,7 +17,6 @@
import argparse
import sys
import logging
import signal
from subiquitycore.log import setup_logger
from subiquitycore import __version__ as VERSION
from console_conf.core import ConsoleConf
@ -83,9 +82,6 @@ def main():
logger.info("Starting console-conf v{}".format(VERSION))
logger.info("Arguments passed: {}".format(sys.argv))
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
env_ok = environment_check(ENVIRONMENT)
if env_ok is False and not opts.dry_run:
print('Failed environment check. '

View File

@ -18,7 +18,6 @@ import argparse
import logging
import os
import fcntl
import signal
import sys
from subiquitycore.log import setup_logger
@ -126,9 +125,6 @@ def main():
logging.getLogger('curtin').addHandler(handler)
logging.getLogger('block-discover').addHandler(handler)
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
env_ok = environment_check(ENVIRONMENT)
if env_ok is False and not opts.dry_run:
print('Failed environment check. '

View File

@ -20,7 +20,6 @@ import logging
import os
import struct
import sys
import termios
import tty
import urwid
@ -156,25 +155,13 @@ class KeyCodesFilter:
def enter_keycodes_mode(self):
log.debug("enter_keycodes_mode")
self.filtering = True
# Read the old keyboard mode (it will proably always be
# K_UNICODE but well).
# Read the old keyboard mode (it will proably always be K_UNICODE but
# well).
o = bytearray(4)
fcntl.ioctl(self._fd, KDGKBMODE, o)
self._old_mode = struct.unpack('i', o)[0]
# Make some changes to the terminal settings.
# If you don't do this, sometimes writes to the terminal hang (and no,
# I don't know exactly why).
self._old_settings = termios.tcgetattr(self._fd)
new_settings = termios.tcgetattr(self._fd)
new_settings[tty.IFLAG] = 0
new_settings[tty.LFLAG] = new_settings[tty.LFLAG] & ~(termios.ECHO |
termios.ICANON |
termios.ISIG)
new_settings[tty.CC][termios.VMIN] = 0
new_settings[tty.CC][termios.VTIME] = 0
termios.tcsetattr(self._fd, termios.TCSAFLUSH, new_settings)
# Finally, set the keyboard mode to K_MEDIUMRAW, which causes
# the keyboard driver in the kernel to pass us keycodes.
# Set the keyboard mode to K_MEDIUMRAW, which causes the keyboard
# driver in the kernel to pass us keycodes.
log.debug("old mode was %s, setting mode to %s",
self._old_mode, K_MEDIUMRAW)
fcntl.ioctl(self._fd, KDSKBMODE, K_MEDIUMRAW)
@ -184,7 +171,6 @@ class KeyCodesFilter:
self.filtering = False
log.debug("setting mode back to %s", self._old_mode)
fcntl.ioctl(self._fd, KDSKBMODE, self._old_mode)
termios.tcsetattr(self._fd, termios.TCSANOW, self._old_settings)
def filter(self, keys, codes):
# Luckily urwid passes us the raw results from read() we can
@ -526,6 +512,8 @@ class Application:
except Skip:
self.next_screen()
self.common['loop'].set_alarm_in(
0.00, lambda loop, ud: tty.setraw(0))
self.common['loop'].set_alarm_in(
0.05, select_initial_screen, initial_controller_index)
self._connect_base_signals()