From 93e0898c663a533082b5f3c2e7dcce93ec47076d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 26 Jan 2023 12:56:33 +0100 Subject: shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256 function old new delta record_pending_signo 32 63 +31 lineedit_read_key 231 224 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 31/-7) Total: 24 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 3 ++- shell/hush.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 18ccc1329..5f8c8ea19 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10821,7 +10821,8 @@ preadfd(void) again: /* For shell, LI_INTERRUPTIBLE is set: * read_line_input will abort on either - * getting EINTR in poll(), or if it sees bb_got_signal != 0 + * getting EINTR in poll() and bb_got_signal became != 0, + * or if it sees bb_got_signal != 0 * (IOW: if signal arrives before poll() is reached). * Interactive testcases: * (while kill -INT $$; do sleep 1; done) & diff --git a/shell/hush.c b/shell/hush.c index d111f0cc5..f064b8fd2 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1946,7 +1946,12 @@ static void record_pending_signo(int sig) { sigaddset(&G.pending_set, sig); #if ENABLE_FEATURE_EDITING - bb_got_signal = sig; /* for read_line_input: "we got a signal" */ + if (sig != SIGCHLD + || (G_traps && G_traps[SIGCHLD] && G_traps[SIGCHLD][0]) + /* ^^^ if SIGCHLD, interrupt line reading only if it has a trap */ + ) { + bb_got_signal = sig; /* for read_line_input: "we got a signal" */ + } #endif #if ENABLE_HUSH_FAST if (sig == SIGCHLD) { @@ -2669,7 +2674,8 @@ static int get_user_input(struct in_str *i) } else { /* For shell, LI_INTERRUPTIBLE is set: * read_line_input will abort on either - * getting EINTR in poll(), or if it sees bb_got_signal != 0 + * getting EINTR in poll() and bb_got_signal became != 0, + * or if it sees bb_got_signal != 0 * (IOW: if signal arrives before poll() is reached). * Interactive testcases: * (while kill -INT $$; do sleep 1; done) & -- cgit v1.2.3-55-g6feb