mirror of
https://github.com/python/cpython.git
synced 2025-11-07 00:51:49 +00:00
gh-135329: prevent infinite traceback loop on Ctrl-C for strace (GH-138133)
Signed-off-by: yihong0618 <zouzou0208@gmail.com> Co-authored-by: dura0ok <slpmcf@gmail.com> Co-authored-by: graymon <greyschwinger@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
55e29a6100
commit
b9dbf6acb3
4 changed files with 171 additions and 3 deletions
|
|
@ -340,7 +340,14 @@ def prepare(self):
|
|||
raw.lflag |= termios.ISIG
|
||||
raw.cc[termios.VMIN] = 1
|
||||
raw.cc[termios.VTIME] = 0
|
||||
tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
|
||||
try:
|
||||
tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
|
||||
except termios.error as e:
|
||||
if e.args[0] != errno.EIO:
|
||||
# gh-135329: when running under external programs (like strace),
|
||||
# tcsetattr may fail with EIO. We can safely ignore this
|
||||
# and continue with default terminal settings.
|
||||
raise
|
||||
|
||||
# In macOS terminal we need to deactivate line wrap via ANSI escape code
|
||||
if self.is_apple_terminal:
|
||||
|
|
@ -372,7 +379,11 @@ def restore(self):
|
|||
self.__disable_bracketed_paste()
|
||||
self.__maybe_write_code(self._rmkx)
|
||||
self.flushoutput()
|
||||
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
|
||||
try:
|
||||
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
|
||||
except termios.error as e:
|
||||
if e.args[0] != errno.EIO:
|
||||
raise
|
||||
|
||||
if self.is_apple_terminal:
|
||||
os.write(self.output_fd, b"\033[?7h")
|
||||
|
|
@ -411,6 +422,8 @@ def get_event(self, block: bool = True) -> Event | None:
|
|||
return self.event_queue.get()
|
||||
else:
|
||||
continue
|
||||
elif err.errno == errno.EIO:
|
||||
raise SystemExit(errno.EIO)
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue