From eede0df81427169660804b1b6fa10389d7a4ed47 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 22 Jun 2024 10:59:52 +0000 Subject: [PATCH] Handle SIGHUP in sh(1) and save shell history. --- sh/sh.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sh/sh.c b/sh/sh.c index 203b06c7..47de2fe3 100644 --- a/sh/sh.c +++ b/sh/sh.c @@ -1183,6 +1183,8 @@ struct execute_result execute(char** tokens, return result; } + signal(SIGHUP, SIG_DFL); + setpgid(0, pgid != -1 ? pgid : 0); if ( interactive && pgid == -1 ) { @@ -2137,6 +2139,9 @@ static int top(FILE* fp, if ( *script_exited || (status != 0 && exit_on_error) ) return status; + // Receive read EOF instead so we save the shell history. + signal(SIGHUP, SIG_IGN); + edit_line_history_load(&edit_state, getenv("HISTFILE")); } @@ -2144,7 +2149,10 @@ static int top(FILE* fp, status); if ( interactive ) + { edit_line_history_save(&edit_state, getenv("HISTFILE")); + signal(SIGHUP, SIG_DFL); + } return status; }