Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-02-22 21:53:33 +0300
committerJunio C Hamano <gitster@pobox.com>2022-02-24 00:30:06 +0300
commitf7da756566e8abf18abdf9e30a8ed6d2088770de (patch)
treef92ab4f386d1bc5d1fb64314edc0c50f2f77c5d7 /compat/terminal.h
parent24d7ce383a3d92feae6a641499448fde43206fd8 (diff)
terminal: pop signal handler when terminal is restored
When disable_bits() changes the terminal attributes it uses sigchain_push_common() to restore the terminal if a signal is received before restore_term() is called. However there is no corresponding call to sigchain_pop_common() when the settings are restored so the signal handler is left on the sigchain stack. This leaves the stack unbalanced so code such as sigchain_push_common(my_handler); ... read_key_without_echo(...); ... sigchain_pop_common(); pops the handler pushed by disable_bits() rather than the one it intended to. Additionally "git add -p" changes the terminal settings every time it reads a key press so the stack can grow significantly. In order to fix this save_term() now sets up the signal handler so restore_term() can unconditionally call sigchain_pop_common(). There are no callers of save_term() outside of terminal.c as the only external caller was removed by e3f7e01b50 ("Revert "editor: save and reset terminal after calling EDITOR"", 2021-11-22). Any future callers of save_term() should benefit from having the signal handler set up for them. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/terminal.h')
-rw-r--r--compat/terminal.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/compat/terminal.h b/compat/terminal.h
index e1770c575b..0fb9fa147c 100644
--- a/compat/terminal.h
+++ b/compat/terminal.h
@@ -1,7 +1,15 @@
#ifndef COMPAT_TERMINAL_H
#define COMPAT_TERMINAL_H
+/*
+ * Save the terminal attributes so they can be restored later by a
+ * call to restore_term(). Note that every successful call to
+ * save_term() must be matched by a call to restore_term() even if the
+ * attributes have not been changed. Returns 0 on success, -1 on
+ * failure.
+ */
int save_term(int full_duplex);
+/* Restore the terminal attributes that were saved with save_term() */
void restore_term(void);
char *git_terminal_prompt(const char *prompt, int echo);