From a68a5a8825edd669e61816b00a3000f5b8f745cd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 6 Apr 2024 20:57:54 +0200 Subject: [PATCH] if using readline , the CTRL-C should now handle it a bit more nicer. Especially the pm3 history file should be flushed with the upside you dont loose all your commands you issued and mistakingly pressed CTRL-C. for the linenoice and Win32, you still have this issue. --- CHANGELOG.md | 1 + client/src/pm3line.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2219d20ae..06b754349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Changed client now handles CTRL-C and saves history if using READLINE (@iceman1001) - Changed `hf mf *` - printing of keys if MFC EV1 added extra explaination (@iceman1001) - Changed `hf mf ginfo - now supports decoding of user supplied configuration block (@iceman1001) - Changed `data load` - now shows loaded number as comma printed. (@iceman1001) diff --git a/client/src/pm3line.c b/client/src/pm3line.c index 5c09c6135..30f3e7349 100644 --- a/client/src/pm3line.c +++ b/client/src/pm3line.c @@ -123,10 +123,20 @@ static bool WINAPI terminate_handler(DWORD t) { # else static struct sigaction gs_old_sigint_action; static void sigint_handler(int signum) { - sigaction(SIGINT, &gs_old_sigint_action, NULL); - pm3line_flush_history(); - kill(0, SIGINT); + + switch(signum) { + case SIGINT: { + sigaction(SIGINT, &gs_old_sigint_action, NULL); + pm3line_flush_history(); + kill(0, SIGINT); + break; + } + default: { + break; + } + } } + #endif void pm3line_install_signals(void) { @@ -138,6 +148,7 @@ void pm3line_install_signals(void) { action.sa_handler = &sigint_handler; sigaction(SIGINT, &action, &gs_old_sigint_action); # endif + #if defined(HAVE_READLINE) rl_catch_signals = 1; rl_set_signals(); @@ -150,6 +161,8 @@ void pm3line_init(void) { using_history(); rl_readline_name = "PM3"; rl_attempted_completion_function = rl_command_completion; + rl_getc_function = getc; + pm3line_install_signals(); #ifdef RL_STATE_READCMD rl_extend_line_buffer(1024);