[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] src/pk-repl.c (pk_repl): Add signal handler for SIGINT
From: |
John Darrington |
Subject: |
[PATCH 2/2] src/pk-repl.c (pk_repl): Add signal handler for SIGINT |
Date: |
Sun, 10 Nov 2019 13:02:14 +0100 |
---
src/pk-repl.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/pk-repl.c b/src/pk-repl.c
index 11c7664..22d2e30 100644
--- a/src/pk-repl.c
+++ b/src/pk-repl.c
@@ -32,6 +32,8 @@
# include "pk-hserver.h"
#endif
+#include <signal.h>
+
static void
banner (void)
{
@@ -66,10 +68,28 @@ 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 ();
+}
+
void
pk_repl (void)
{
banner ();
+
+ /* Arrange for the current line to be cancelled on SIGINT. */
+ struct sigaction sa;
+ sa.sa_handler = poke_sigint_handler;
+ sa.sa_flags = 0;
+ sigemptyset (&sa.sa_mask);
+ sigaction (SIGINT, &sa, 0);
+
while (!poke_exit_p)
{
int ret;
--
2.11.0