From a5faae14cd81c019b8757c2f263799d19a2218e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Sat, 28 Nov 2015 15:48:46 +0100 Subject: Restore signal handlers when catching signals in edit_alloc() edit_catcher() performs a longjmp via rc_raise() to the matching setjmp in doit(). The latter does the same as before, so that edit_alloc() gets called again, but this time the installation of the signal handlers trashes the old handlers saved in the last call. Once readline() returns normally to edit_alloc() the wrong signal handlers get restored. The simplified call hierarchy looks like this: doit(); sigsetjmp(); edit_alloc(); oldint = sys_signal(SIGINT, edit_catcher); readline(); SIGINT -> edit_catcher(); siglongjmp(); sys_signal(SIGINT, oldint); Restoring the old signal handlers in edit_catcher() solves this. --- edit-readline.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'edit-readline.c') diff --git a/edit-readline.c b/edit-readline.c index 6a997c5..6d99d94 100644 --- a/edit-readline.c +++ b/edit-readline.c @@ -32,7 +32,11 @@ void *edit_begin(int fd) { return c; } +static void (*oldint)(int), (*oldquit)(int); + static void edit_catcher(int sig) { + sys_signal(SIGINT, oldint); + sys_signal(SIGQUIT, oldquit); write(2, "\n", 1); rc_raise(eError); } @@ -41,7 +45,6 @@ static char *prompt; char *edit_alloc(void *cookie, size_t *count) { struct cookie *c = cookie; - void (*oldint)(int), (*oldquit)(int); oldint = sys_signal(SIGINT, edit_catcher); oldquit = sys_signal(SIGQUIT, edit_catcher); -- cgit v1.2.3