Skip to content

Commit

Permalink
[busybox] Write history on SIGHUP. Fixes JB#53061
Browse files Browse the repository at this point in the history
Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Feb 16, 2021
1 parent 7968e37 commit 19036f9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
67 changes: 67 additions & 0 deletions rpm/0006-ash-Write-history-on-SIGHUP.patch
@@ -0,0 +1,67 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomi=20Lepp=C3=A4nen?= <tomi.leppanen@jolla.com>
Date: Thu, 11 Feb 2021 18:08:59 +0200
Subject: [PATCH] ash: Write history on SIGHUP
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If FEATURE_EDITING_SAVE_ON_EXIT is enabled, then write history on
SIGHUP. This should allow most terminals to save history when closing
window. Works also on SSH connection.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
---
shell/ash.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/shell/ash.c b/shell/ash.c
index fabecdfe0..917b93fec 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -3626,6 +3626,19 @@ signal_handler(int signo)
return;
}

+#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
+ if (signo == SIGHUP) {
+ /*
+ * Terminal was closed, call exitshell() to write history etc.
+ * unless there is a trap set, in which case just save the history
+ */
+ if (!trap[SIGHUP])
+ exitshell();
+ else if (iflag && line_input_state)
+ save_history(line_input_state);
+ }
+#endif
+
gotsig[signo - 1] = 1;
pending_sig = signo;

@@ -3698,6 +3711,14 @@ setsignal(int signo)
if (signo == SIGCHLD)
new_act = S_CATCH;

+#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
+ /*
+ * Catch SIGHUP to write history on terminal close
+ */
+ if (signo == SIGHUP && iflag)
+ new_act = S_CATCH;
+#endif
+
t = &sigmode[signo - 1];
cur_act = *t;
if (cur_act == 0) {
@@ -9545,6 +9566,7 @@ setinteractive(int on)
setsignal(SIGINT);
setsignal(SIGQUIT);
setsignal(SIGTERM);
+ setsignal(SIGHUP);
if (is_interactive > 1) {
#if !ENABLE_FEATURE_SH_EXTRA_QUIET
/* Looks like they want an interactive shell */
--
2.29.2

1 change: 1 addition & 0 deletions rpm/busybox.spec
Expand Up @@ -13,6 +13,7 @@ Patch1: 0002-applets-Busybox-in-usr-bin-instead-of-bin.patch
Patch2: 0003-Align-watch-with-what-is-in-procps-ng.patch
Patch3: 0004-ash-Load-ENV-file-also-if-SSH_CLIENT-SSH2_CLIENT-is-.patch
Patch4: 0005-ash-job-option-to-restore-term-io-after-job-is-stopp.patch
Patch5: 0006-ash-Write-history-on-SIGHUP.patch
URL: https://git.sailfishos.org/mer-core/busybox
BuildRequires: glibc-static
BuildRequires: libselinux-static libsepol-static
Expand Down

0 comments on commit 19036f9

Please sign in to comment.