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 --- libbb/lineedit.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'libbb/lineedit.c') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index d6b2e76..b942f54 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2180,7 +2180,8 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) * "\xff\n",pause,"ls\n" invalid and thus won't lose "ls". * * If LI_INTERRUPTIBLE, return -1 if got EINTR in poll() - * inside read_key, or if bb_got_signal != 0 (IOW: if signal + * inside read_key and bb_got_signal became != 0, + * or if bb_got_signal != 0 (IOW: if signal * arrived before poll() is reached). * * Note: read_key sets errno to 0 on success. @@ -2197,14 +2198,16 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) if (errno != EINTR) break; + /* It was EINTR. Repeat read_key() unless... */ if (state->flags & LI_INTERRUPTIBLE) { - /* LI_INTERRUPTIBLE bails out on EINTR, - * but nothing really guarantees that bb_got_signal - * is nonzero. Follow the least surprise principle: + /* LI_INTERRUPTIBLE bails out on EINTR + * if bb_got_signal became nonzero. + * (It may stay zero: for example, our SIGWINCH + * handler does not set it. This is used for signals + * which should not interrupt line editing). */ - if (bb_got_signal == 0) - bb_got_signal = 255; - goto ret; + if (bb_got_signal != 0) + goto ret; /* will return -1 */ } } -- cgit v1.1