poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] repl: Fix SIGINT behavior with reverse-i-search


From: Carlo Caione
Subject: [PATCH] repl: Fix SIGINT behavior with reverse-i-search
Date: Tue, 18 Feb 2020 11:36:49 +0100

The current SIGINT handling is failing to reset readline when doing a
reverse-search.

  (failed reverse-i-search)`XXXXXX': ^CQuit
  (failed reverse-i-search)`XXXXXX': ^CQuit

Use the standard implementation for the SIGINT handler to address this
(and other) problems.

        * src/pk-repl.c: Rework poke_sigint_handler()

Signed-off-by: Carlo Caione <address@hidden>
---
 src/pk-repl.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/pk-repl.c b/src/pk-repl.c
index ea9881d0..8439aac9 100644
--- a/src/pk-repl.c
+++ b/src/pk-repl.c
@@ -34,6 +34,9 @@
 
 #include <signal.h>
 #include <unistd.h>
+#include <setjmp.h>
+
+sigjmp_buf ctrlc_buf;
 
 static char *
 pkl_complete_struct (int *idx, const char *x, size_t len, int state)
@@ -203,11 +206,11 @@ banner (void)
 static void
 poke_sigint_handler (int status)
 {
-  fputs (_("Quit"), rl_outstream);
-  fputs ("\n", rl_outstream);
-  rl_on_new_line ();
-  rl_replace_line ("", 0);
-  rl_redisplay ();
+  rl_free_line_state ();
+  rl_cleanup_after_signal ();
+  rl_line_buffer[rl_point = rl_end = rl_mark = 0] = 0;
+  printf("\n");
+  siglongjmp(ctrlc_buf, 1);
 }
 
 void
@@ -246,6 +249,8 @@ pk_repl (void)
       int ret;
       char *line;
 
+      while ( sigsetjmp( ctrlc_buf, 1 ) != 0 );
+
       pk_term_flush ();
       rl_completion_entry_function = poke_completion_function;
       line = readline ("(poke) ");
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]