From c7eb22e62fac733a070dea6cf51c247dae19f7be Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 28 Apr 2022 19:07:01 -0700 Subject: linenoise: Ctrl-Z: send SIGTSTP to group, not self. I realized this issue while implementing Ctrl-Z for the pw (Pipe Watch) program. Sending the SIGTSTP signal just to the calling process is not enough. Only that process gets suspended, which results in a weird behavior. It can be tested like this, for instance: txr | tee file Ctrl-Z must be issued twice: once to sort of suspend txr, and then again to send it to the tee program. Then the job actually suspends and the shell prompt appears. With this fix, the above situation requires only one Ctrl-Z, as expected. * linenoise/linenoise.c (history_search, show_help, edit): Don't raise(SIGTSTP), but kill(0, SIGTSTP) to send the suspend signal to all processes in the process group. --- linenoise/linenoise.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index b3645a18..f09e9b26 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -828,7 +828,7 @@ static int history_search(lino_t *l) break; case CTL('Z'): disable_raw_mode(l); - raise(SIGTSTP); + kill(0, SIGTSTP); enable_raw_mode(l); } } @@ -930,7 +930,7 @@ static void show_help(lino_t *l) continue; case CTL('Z'): disable_raw_mode(l); - raise(SIGTSTP); + kill(0, SIGTSTP); enable_raw_mode(l); i -= 1; continue; @@ -2526,7 +2526,7 @@ static int edit(lino_t *l, const wchar_t *prompt) if (l->need_refresh) refresh_line(l); disable_raw_mode(l); - raise(SIGTSTP); + kill(0, SIGTSTP); enable_raw_mode(l); l->maxrows = 0; l->dpos = dpos; -- cgit v1.2.3