mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
Merge branch 'monitor/new_kernel-4.4' into 'release/v4.4'
bug(monitor/console_reader): replace TIOCSTI with busy wait to suppport kernel > 6.2 (4.4) See merge request espressif/esp-idf!23352
This commit is contained in:
@ -41,6 +41,15 @@ class ConsoleReader(StoppableThread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.console.setup()
|
self.console.setup()
|
||||||
|
if os.name == 'posix':
|
||||||
|
# Use non-blocking busy read to avoid using unsecure TIOCSTI from console.cancel().
|
||||||
|
# TIOCSTI is not supported on kernels newer than 6.2.
|
||||||
|
import termios
|
||||||
|
new = termios.tcgetattr(self.console.fd)
|
||||||
|
# new[6] - 'cc': a list of the tty special characters
|
||||||
|
new[6][termios.VMIN] = 0 # minimum bytes to read
|
||||||
|
new[6][termios.VTIME] = 2 # timer of 0.1 second granularity
|
||||||
|
termios.tcsetattr(self.console.fd, termios.TCSANOW, new)
|
||||||
try:
|
try:
|
||||||
while self.alive:
|
while self.alive:
|
||||||
try:
|
try:
|
||||||
@ -64,7 +73,7 @@ class ConsoleReader(StoppableThread):
|
|||||||
c = self.console.getkey()
|
c = self.console.getkey()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
c = '\x03'
|
c = '\x03'
|
||||||
if c is not None:
|
if c:
|
||||||
ret = self.parser.parse(c)
|
ret = self.parser.parse(c)
|
||||||
if ret is not None:
|
if ret is not None:
|
||||||
(tag, cmd) = ret
|
(tag, cmd) = ret
|
||||||
@ -76,22 +85,3 @@ class ConsoleReader(StoppableThread):
|
|||||||
|
|
||||||
finally:
|
finally:
|
||||||
self.console.cleanup()
|
self.console.cleanup()
|
||||||
|
|
||||||
def _cancel(self):
|
|
||||||
# type: () -> None
|
|
||||||
if os.name == 'posix' and not self.test_mode:
|
|
||||||
# this is the way cancel() is implemented in pyserial 3.3 or newer,
|
|
||||||
# older pyserial (3.1+) has cancellation implemented via 'select',
|
|
||||||
# which does not work when console sends an escape sequence response
|
|
||||||
#
|
|
||||||
# even older pyserial (<3.1) does not have this method
|
|
||||||
#
|
|
||||||
# on Windows there is a different (also hacky) fix, applied above.
|
|
||||||
#
|
|
||||||
# note that TIOCSTI is not implemented in WSL / bash-on-Windows.
|
|
||||||
# TODO: introduce some workaround to make it work there.
|
|
||||||
#
|
|
||||||
# Note: This would throw exception in testing mode when the stdin is connected to PTY.
|
|
||||||
import fcntl
|
|
||||||
import termios
|
|
||||||
fcntl.ioctl(self.console.fd, termios.TIOCSTI, b'\0')
|
|
||||||
|
Reference in New Issue
Block a user