From c3193104049186bd28203801e8fd7d9d4ff2b547 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 1 Apr 2019 12:29:27 +0200 Subject: vi: fix ^Z not always working as intended function old new delta tstp_handler 64 71 +7 text_yank 54 56 +2 vi_main 280 272 -8 do_cmd 4705 4696 -9 colon 2861 2852 -9 cont_handler 66 - -66 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/3 up/down: 9/-92) Total: -83 bytes Signed-off-by: Denys Vlasenko --- editors/vi.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'editors/vi.c') diff --git a/editors/vi.c b/editors/vi.c index a11e06040..9bdee5928 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -330,9 +330,6 @@ struct globals { int lmc_len; // length of last_modifying_cmd char *ioq, *ioq_start; // pointer to string for get_one_char to "read" #endif -#if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME - int my_pid; -#endif #if ENABLE_FEATURE_VI_SEARCH char *last_search_pattern; // last pattern from a '/' or '?' search #endif @@ -449,7 +446,6 @@ struct globals { #define lmc_len (G.lmc_len ) #define ioq (G.ioq ) #define ioq_start (G.ioq_start ) -#define my_pid (G.my_pid ) #define last_search_pattern (G.last_search_pattern) #define edit_file__cur_line (G.edit_file__cur_line) @@ -634,11 +630,8 @@ int vi_main(int argc, char **argv) #endif #endif -#if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME - my_pid = getpid(); -#endif #if ENABLE_FEATURE_VI_CRASHME - srand((long) my_pid); + srand((long) getpid()); #endif #ifdef NO_SUCH_APPLET_YET // if we aren't "vi", we are "view" @@ -2770,31 +2763,30 @@ static void winch_handler(int sig UNUSED_PARAM) redraw(TRUE); // re-draw the screen errno = save_errno; } -static void cont_handler(int sig UNUSED_PARAM) -{ - int save_errno = errno; - rawmode(); // terminal to "raw" - last_status_cksum = 0; // force status update - redraw(TRUE); // re-draw the screen - - signal(SIGTSTP, tstp_handler); - signal(SIGCONT, SIG_DFL); - //kill(my_pid, SIGCONT); // huh? why? we are already "continued"... - errno = save_errno; -} static void tstp_handler(int sig UNUSED_PARAM) { int save_errno = errno; + + // ioctl inside cookmode() was seen to generate SIGTTOU, + // stopping us too early. Prevent that: + signal(SIGTTOU, SIG_IGN); + go_bottom_and_clear_to_eol(); cookmode(); // terminal to "cooked" - signal(SIGCONT, cont_handler); - signal(SIGTSTP, SIG_DFL); - kill(my_pid, SIGTSTP); + // stop now + //signal(SIGTSTP, SIG_DFL); + //raise(SIGTSTP); + raise(SIGSTOP); // avoid "dance" with TSTP handler - use SIGSTOP instead + //signal(SIGTSTP, tstp_handler); + + // we have been "continued" with SIGCONT, restore screen and termios + rawmode(); // terminal to "raw" + last_status_cksum = 0; // force status update + redraw(TRUE); // re-draw the screen + errno = save_errno; } - -//----- Come here when we get a signal --------------------------- static void int_handler(int sig) { signal(SIGINT, int_handler); -- cgit v1.2.3